iOS8 推送註冊相關

registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.程序員

 

appDelegate.mapp

didFinishLaunchingWithOptions:spa

#ifdef __IPHONE_8_0 //這裏主要是針對iOS 8.0,相應的8.1,8.2等版本各程序員可自行發揮,若是蘋果之後推出更高版本還不會使用這個註冊方式就不得而知了……
if  ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
     UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
     [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}   else  {
     UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
#else
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
#endif
 
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
     [application registerForRemoteNotifications];
}
#endif
相關文章
相關標籤/搜索