iOS 9中的本地通知覆盖远程通知(可操作通知)设置?
我使用以下代码进行远程通知iOS 9中的本地通知覆盖远程通知(可操作通知)设置?,ios,objective-c,push-notification,uilocalnotification,Ios,Objective C,Push Notification,Uilocalnotification,我使用以下代码进行远程通知 UIMutableUserNotificationAction *action1; action1 = [[UIMutableUserNotificationAction alloc] init]; [action1 setActivationMode:UIUserNotificationActivationModeBackground]; [action1 setTitle:@"REJECT"]; [action1 setIdent
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"REJECT"];
[action1 setIdentifier:NotificationActionOneIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];////UIUserNotificationActivationModeBackground
[action2 setTitle:@"ACCEPT"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
//Right, that is the point
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
//register to receive notifications
[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
这可以很好地显示正确的(接受/拒绝按钮)。在某些情况下,我想将应用程序唤醒到前台,所以我在中使用以下本地通知代码
- (void)应用程序:(UIApplication*)应用程序handleActionWithIdentifier:(NSString*)标识符 forRemoteNotification:(NSDictionary*)userInfo completionHandler:(void (^)()completionHandler方法
问题:第一次远程通知正确显示“接受/拒绝”按钮,但注册本地通知后,“远程通知”不显示操作按钮(接受/拒绝)。我看不到警报中的按钮?您的远程通知设置被本地通知设置覆盖
// Registering UIUserNotificationSettings more than once results in previous settings being overwritten.
- (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
注释此代码:
[[UIApplication sharedApplication] registerUserNotificationSettings:settings2];
请看这个链接看这个链接
[[UIApplication sharedApplication] registerUserNotificationSettings:settings2];