如题!
模拟器没有问题,因为用的是本地的 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 应用,多了一个展示的途径。
关于这个问题也是找了很多资料,但是一直无法解决,不是伸手党。看了网易新闻的通知,是带有自定义按钮的。说明是我某个地方处理不当引起的。但是因为经验不足,无法准确定位以及解决。所以请大家指点一下。