PushNotification code for Latest iOS8 and earlier versions.
You need to find out the iOS version first. Use below Macro keys for iOS check:-
#define IS_iOS7 [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0?YES:NO
#define IS_iOS8 [[[UIDevice currentDevice] systemVersion] floatValue] >= 8?YES:NO
- (void)registerForRemoteNotification {
    if (IS_iOS8) {
        NSLog(@"ios8");
        UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
    } else {
        NSLog(@"ios7");
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }
}
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    [application registerForRemoteNotifications];
}
#endif
Now you can ask user for push notification permission by calling registerForRemoteNotification method anywhere.
*Happy Coding :)
                       
                    
0 Comment(s)