iOS消息推送代码(iOS不断更新,稍微有点过时了)

网上有人整理的超详细的iOS 8之后的推送,附上链接: https://www.jianshu.com/p/027120ca9179



实例:
调用方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {//注册通知 [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound]; } //实现 类 #pragma mark - RegisterForRemoteNotifications methods - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { //注册远方通知,获得DeviceToken NSString *str = [NSString stringWithFormat:@"Device Token=%@",newDeviceToken]; NSLog(@"%@",str); } - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { //注册失败 NSString *str = [NSString stringWithFormat: @"Error: %@", err]; NSLog(@"%@",str); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { //收到通知 NSString *topId = [NSString stringWithFormat:@"%@", [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]; //清除图标上的通知记录条数 application.applicationIconBadgeNumber = 0; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { //点击提示框的打开 application.applicationIconBadgeNumber = 0; }

 

posted @ 2013-03-01 16:42  小、  阅读(3140)  评论(1编辑  收藏  举报