美文网首页
iOS 本地推送注意事项

iOS 本地推送注意事项

作者: 王家小雷 | 来源:发表于2018-03-22 10:27 被阅读37次

一定要在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self registerPushForIOS8];

}里面注册通知

  • (void)registerPushForIOS8{

if __IPHONE_OS_VERSION_MAX_ALLOWED >= IPHONE80

//Types
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

//Actions
UIMutableUserNotificationAction *acceptAction = [[UIMutableUserNotificationAction alloc] init];

acceptAction.identifier = @"ACCEPT_IDENTIFIER";
acceptAction.title = @"Accept";

acceptAction.activationMode = UIUserNotificationActivationModeForeground;
acceptAction.destructive = NO;
acceptAction.authenticationRequired = NO;

//Categories
UIMutableUserNotificationCategory *inviteCategory = [[UIMutableUserNotificationCategory alloc] init];

inviteCategory.identifier = @"INVITE_CATEGORY";

[inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault];

[inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextMinimal];

NSSet *categories = [NSSet setWithObjects:inviteCategory, nil];


UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories];

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];


[[UIApplication sharedApplication] registerForRemoteNotifications];

endif

}

相关文章

网友评论

      本文标题:iOS 本地推送注意事项

      本文链接:https://www.haomeiwen.com/subject/ksnoqftx.html