In my app I want to support both - Remote Notifications
and Local Notifications
. The Remote Notification
should have two actions that let the user interact with it in Notification Center.
Currently I have this code to register for notifications. My question is do I have to call register for local notifications separately or are local notifications already included in this registration process.
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIMutableUserNotificationAction *actionCancel = [[UIMutableUserNotificationAction alloc] init];
[actionCancel setActivationMode:UIUserNotificationActivationModeBackground];
[actionCancel setTitle:@"Cancel"];
[actionCancel setIdentifier:NotificationActionOneIdent];
[actionCancel setDestructive:NO];
[actionCancel setAuthenticationRequired:NO];
UIMutableUserNotificationAction *actionOk = [[UIMutableUserNotificationAction alloc] init];
[actionOk setActivationMode:UIUserNotificationActivationModeBackground];
[actionOk setTitle:@"Ok"];
[actionOk setIdentifier:NotificationActionTwoIdent];
[actionOk setDestructive:NO];
[actionOk setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:@[actionCancel, actionOk]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
当您注册UserNotificationSettings时包括本地语言,因此您的代码很好
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.