Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Push Notification in iOS8 and other versions

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.20k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: