您的位置:首页 > 移动开发 > IOS开发

IOS消息推送APNs

2016-04-28 23:14 113 查看
- (BOOL)pushApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {

// Override point for customization after application launch.

if([application
respondsToSelector:@selector(registerUserNotificationSettings:)])

{

UIUserNotificationType notificationTypes =
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert;

UIUserNotificationSettings *settings = [UIUserNotificationSettings
settingsForTypes:notificationTypes
categories:nil];

[application registerUserNotificationSettings:settings];

}

#if !TARGET_IPHONE_SIMULATOR

//iOS8 注册APNS

if ([application
respondsToSelector:@selector(registerForRemoteNotifications)]) {

[application registerForRemoteNotifications];

}else{

UIRemoteNotificationType notificationTypes =
UIRemoteNotificationTypeBadge |

UIRemoteNotificationTypeSound |

UIRemoteNotificationTypeAlert;

[[UIApplication
sharedApplication]
registerForRemoteNotificationTypes:notificationTypes];

}

#endif

return
YES;

}

// 将得到的deviceToken

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData
*)deviceToken{

NSLog(@"deviceToken = %@", [deviceToken
description]);

}

//失败

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError
*)error{

}

//处理收到的消息推送

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo {

[self
pushApplication:application
didReceiveRemoteNotification:userInfo];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: