V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
code4life
V2EX  ›  iDev

Apple watch 真机测试,发现收到的通知没有显示自定义的 action 按钮,请大牛过来诊断一下

  •  
  •   code4life · 2015-08-28 16:10:11 +08:00 · 1882 次点击
    这是一个创建于 3175 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题!
    模拟器没有问题,因为用的是本地的 apns 的。
    但是真机实测就不太明白为什么不显示了。
    代码和网上的都一样。

    • (void )registerSettingsAndCategories {
      // Create a mutable set to store the category definitions.
      NSMutableSet* categories = [NSMutableSet set];

      // Define the actions for a meeting invite notification.
      UIMutableUserNotificationAction* acceptAction = [[UIMutableUserNotificationAction alloc] init];
      acceptAction.title = NSLocalizedString (@"Accept", @"Accept invitation");
      acceptAction.identifier = @"accept";
      acceptAction.activationMode = UIUserNotificationActivationModeBackground;
      acceptAction.authenticationRequired = NO;

      UIMutableUserNotificationAction* declineAction = [[UIMutableUserNotificationAction alloc] init];
      declineAction.title = NSLocalizedString (@"Decline", @"Decline invitation");
      declineAction.identifier = @"decline";
      declineAction.activationMode = UIUserNotificationActivationModeBackground;
      declineAction.authenticationRequired = NO;

      // Create the category object and add it to the set.
      UIMutableUserNotificationCategory* inviteCategory = [[UIMutableUserNotificationCategory alloc] init];
      [inviteCategory setActions:@[acceptAction, declineAction]
      forContext:UIUserNotificationActionContextDefault];
      inviteCategory.identifier = @"invitation";

      [categories addObject:inviteCategory];

      // Configure other actions and categories and add them to the set...

      UIUserNotificationSettings* settings = [UIUserNotificationSettings settingsForTypes:
      (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound )
      categories:categories];

      [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
      }

    上述代码是在 appdelegate 中的
    - (BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 调用的。

    但 watch 中收到的消息死活不显示这两个按钮,就只有一个默认的关闭。

    说明: ios 开发新手。服务器推送过来的消息格式没有变过(不知道这里有没有要求),只是现在加了 watch 应用,多了一个展示的途径。
    关于这个问题也是找了很多资料,但是一直无法解决,不是伸手党。看了网易新闻的通知,是带有自定义按钮的。说明是我某个地方处理不当引起的。但是因为经验不足,无法准确定位以及解决。所以请大家指点一下。

    类似问题: http://stackoverflow.com/questions/30255063/watchkit-simulator-actions-not-working-on-actual-apple-watch-device

    3 条回复    2015-08-31 11:02:16 +08:00
    superdong
        1
    superdong  
       2015-08-28 19:37:50 +08:00
    这个问题的确不好找原因,涉及环节多,而且不能通过调试找到原因。加油……
    code4life
        2
    code4life  
    OP
       2015-08-28 22:44:24 +08:00
    是不是要和这个文章中说的一样: http://www.appcoda.com/local-notifications-ios8/
    我手表的 category 需要和激发通知的 category 保持一致。(这个例子是本地通知,我现在需要处理的是 remoteNotification ,不知道是不是也有 category 这一个属性,周一上班研究一下)
    func scheduleLocalNotification () {
    ...

    localNotification.category = "shoppingListReminderCategory"
    }

    继续等待解答!!
    code4life
        3
    code4life  
    OP
       2015-08-31 11:02:16 +08:00
    已解决.
    的确需要在推送服务器增加自定义的 category 键值对.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5636 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 07:12 · PVG 15:12 · LAX 00:12 · JFK 03:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.