in ios 8 so many things change in one of them one change is related to push notification.
If you run your old push notification code in Xcode 6 then it will give you warning also some methods deprecated in ios 8
registerForRemoteNotificationTypes is deprecated in ios 8 instead of it in ios 8 we use UIUserNotificationSettings like this way:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
} else {
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
}
#else
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
#endif
and for delegate methods,
#pragma mark - Push Notification
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Prepare the Device Token for Registration (remove spaces and < >)
NSString *TokenID = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
[ApplicationPreferences setTokenId:TokenID];
if (DEBUG_MODE) {
NSLog(@"device token - %@",[NSString stringWithFormat:@"Device Token = %@",TokenID]);
NSUUID *oNSUUID = [[UIDevice currentDevice] identifierForVendor];
NSLog(@"Vendor token - %@",[NSString stringWithFormat:@"Device Token = %@",[oNSUUID UUIDString]]);
}
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
if (DEBUG_MODE) {
NSLog(@"Push Error- %@",[NSString stringWithFormat: @"Error: %@", err]);
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
}
Thanks .
If you run your old push notification code in Xcode 6 then it will give you warning also some methods deprecated in ios 8
registerForRemoteNotificationTypes is deprecated in ios 8 instead of it in ios 8 we use UIUserNotificationSettings like this way:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
} else {
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
}
#else
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
#endif
and for delegate methods,
#pragma mark - Push Notification
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Prepare the Device Token for Registration (remove spaces and < >)
NSString *TokenID = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
[ApplicationPreferences setTokenId:TokenID];
if (DEBUG_MODE) {
NSLog(@"device token - %@",[NSString stringWithFormat:@"Device Token = %@",TokenID]);
NSUUID *oNSUUID = [[UIDevice currentDevice] identifierForVendor];
NSLog(@"Vendor token - %@",[NSString stringWithFormat:@"Device Token = %@",[oNSUUID UUIDString]]);
}
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
if (DEBUG_MODE) {
NSLog(@"Push Error- %@",[NSString stringWithFormat: @"Error: %@", err]);
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
}
Thanks .
No comments:
Post a Comment