Registration method for iOS 8 and support for older versions
UIApplication *application = [UIApplication sharedApplication]; if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert) categories:nil]; [application registerUserNotificationSettings:settings]; } else { UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; [application registerForRemoteNotificationTypes:myTypes]; }
and in the application delegate add
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [application registerForRemoteNotifications]; }
iOS8 can receive silent notifications without asking permission. The call - (void)registerForRemoteNotifications . After this application:didRegisterForRemoteNotificationsWithDeviceToken: will be called
Note: a token callback is only called if the application has successfully registered to notify users using the function below or if the background update function is enabled.
Check the settings for your application if the notification type is enabled. If not, you will not receive the device token.
You can now receive silent notifications using
aps { content-available: 1 }
in notification payload
But the notifications that appear still need permission. Call
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert; UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; [application registerUserNotificationSettings:notificationSettings];
This code must request permission.
You should now be prepared to receive push notifications.
zeiteisen Jun 20 '14 at 14:16 2014-06-20 14:16
source share