iOS 推送通知的实现
来源:互联网 发布:php 源码加密 代码 编辑:程序博客网 时间:2024/05/16 10:15
消息推送:分为本地通知和远程通知,区别为:
- 本地通知由由应用程序计划,并同一设备上的iOS发出 ;
- 推送通知,又叫远程通知,由远程服务器上的程序(提供者)发至APNs,再由APNs把消息推送至设备上的某个程序。
有码有真相:
首先需要在APNS上注册推送服务
-(void)alertNotice:(NSString *)title withMSG:(NSString *)msg cancleButtonTitle:(NSString *)cancleTitle otherButtonTitle:(NSString *)otherTitle{UIAlertView *alert;if([otherTitle isEqualToString:@""])alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:nil,nil];elsealert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:otherTitle,nil];[alert show];[alert release];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the view controller's view to the window and display. [self.window addSubview:viewController.view]; [self.window makeKeyAndVisible];[self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""];//注册远程推送 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)]; return YES;}
//注册远程通知成功,APNS将返回唯一标示的设备令牌码deviceToken
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { //注册远程通知成功//NSLog(@"devToken=%@",deviceToken);NSString* strToken = [NSString stringWithFormat:@"devToken=%@",deviceToken];NSLog(@"%@", strToken);[self alertNotice:@"" withMSG:strToken cancleButtonTitle:@"Ok" otherButtonTitle:@""];}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ NSDictionary *aps = [userInfo objectForKey:@"aps"]; //在应用Icon右上角显示推送通知的个数 if (aps && [aps isKindOfClass:[NSDictionary class]]) { int badgeNumber = [[aps objectForKey:@"badge"] intValue]; if (badgeNumber > 0) { [UIApplication sharedApplication].applicationIconBadgeNumber = badgeNumber; } }}- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { //注册远程推送失败NSLog(@"Error in registration. Error: %@", err);[self alertNotice:@"" withMSG:[NSString stringWithFormat:@"Error in registration. Error: %@", err] cancleButtonTitle:@"Ok" otherButtonTitle:@""];}
到现在iOS方面的编程已经完工,剩下的就是消息推送后台的设置了
首先,需要制作证书,证书的制作流程,推荐:http://docs.jpush.cn/pages/viewpage.action?pageId=1343727
PS:根据后台语言的不同,最后需要使用的证书文件也不同,Java后台需要使用的就是最后生成证书的秘钥,就是p12证书文件,.Net后台需要再进一步将证书文件生成一个pem文件。
参考文章:http://blog.csdn.net/kmyhy/article/details/6792855- iOS 推送通知的实现
- iOS推送通知实现
- IOS推送通知的实现步骤
- IOS推送通知的实现步骤
- IOS推送通知的实现步骤
- IOS推送通知的实现步骤
- IOS推送通知实现步骤
- ios如何实现推送通知
- IOS推送通知实现步骤
- IOS推送通知实现步骤
- iOS 推送通知 客户端实现
- php实现Ios推送通知
- IOS 如何实现推送通知
- IOS推送通知实现步骤
- ios如何实现推送通知
- IOS推送通知实现步骤
- ios如何实现推送通知
- 推送通知的实现
- Nginx架构和代码风格
- gets getche getch
- 如何向Ruby on Rails 分页插件 will_paginate 的链接插入其它参数
- SQL Server中经常会用到的与时间相关的函数
- 17个新手常见Python运行时错误
- iOS 推送通知的实现
- 2013.10.21 -2013.10.26学习总结
- 基于Flex访问Arcgis Server的rest API中的Geometry server 坐标转换(Project)
- CXF WebService整合Spring
- vs2008下MFC中采用ado连接MySQL(ODBC、非ODBC或C API方式)
- Android SDK R22 Caused by: java.lang.NoClassDefFoundError:
- Linux_user&group
- 约瑟夫环算法
- hbase存储结构及客户端访问hbase表的过程