Showing posts with label Push Notification for iOS7. Show all posts
Showing posts with label Push Notification for iOS7. Show all posts

Monday, 18 May 2015

Push Notification in iOS

iOS Push Notification Check

  1. #define IS_iOS8 [[[UIDevice currentDevice] systemVersion] floatValue] >= 8?YES:NO
  1. if (IS_iOS8) {
  2. UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
  3. UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
  4. [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
  5. }else{
  6. UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
  7. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
  8. }

Delegate Methods

  1. #ifdef __IPHONE_8_0
  2. - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  3. [application registerForRemoteNotifications];
  4. }
  5. #endif
  6. #pragma marks- Device_Token
  7. // Getting Device Token and saving it
  8. - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
  9. {
  10. _deviceToken = [[[[deviceToken description]
  11. stringByReplacingOccurrencesOfString: @"<" withString: @""]
  12. stringByReplacingOccurrencesOfString: @">" withString: @""]
  13. stringByReplacingOccurrencesOfString: @" " withString: @""];
  14. NSLog(@"device token is : %@",_deviceToken);
  15. [self updateDeviceToken];
  16. }
  17. - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
  18. {
  19. NSLog(@"Failed to get token, error: %@", error);
  20. }
  21. - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
  22. {
  23. NSString *info = [NSString stringWithFormat:@"%@",userInfo];
  24. NSLog(@"%@",info);
  25. }

For such more Blogs you can visit to http://findnerd.com/NerdDigest