Apple Remote Push Notifications
1、帮助文档参考:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194-CH104-SW1
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW1
2、服务器证书文件生成文档:
http://fecbob.pixnet.net/blog/post/39286091-蘋果推送apns
3、APNS全流程:
http://www.cnblogs.com/gpwzw/archive/2012/03/31/apple_push_notification_services_tutorial_part_1-2.html
4、Google描述APNS:
https://code.google.com/p/apns-php/wiki/CertificateCreation
5、APNs之我见:
整个流程中的角色: apple push notification server(aServer), the third push notification server(mServer), APP, iphone(device)
目的:aServer将mServer发送过来的通知推送到device上
条件:1. mServer证书,因为aServer需要区分是谁发送通知过来
2. APP证书,因为aServer同样需要知道通知是对应于哪个APP的
3. device token, aServer需要知道将通知发送到哪个地址
6、实际操作流程
1)生成.certSigningRequest文件。方法:apple developer website->APP IDs->选择你需要创建push通知的bundle id编辑Push Notifications那项。有具体文档说明如何生成.certSigningRequest文件
2) 得到aps_development.cer(或者distribution也行)。上传.certSigningRequest文件文件后,apple会自动生成aps_development.cer文件,直接下载然后双击便装进了keychain中
3)生成apns-dev.p12(当然可以是其他名字)文件。在keychain中选择aps_development.cer,右键导出为.p12格式便可
4)生成apns-dev.pem文件。此文件可以直接发给server端用便可。使用此命令(参照上面google的文档):
openssl pkcs12 -in apns-dev.p12 -out apns-dev.pem -nodes -clcerts
5)xcode工程设置:注意provisioning profile 的bundleID一定要和aps_development.cer证书的bundleID是一样的
6) 在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中register push notification
if (!TARGET_IPHONE_SIMULATOR && ![[NSUserDefaults standardUserDefaults] objectForKey:DeviceTokenKey]) {
NSLog(@"Registering for push notifications...");
if([[[UIDevice currentDevice] systemVersion] floatValue] > 7.1)
[[UIApplication sharedApplication] registerForRemoteNotifications];
else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
7) push notification delegate
#pragma mark -
#pragma mark Push Notification
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"deviceToken: %@", deviceToken);
if (deviceToken != nil)
{
NSString *deviceTokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""];
if (deviceTokenString) {
NSLog(@"deviceTokenString = %@", deviceTokenString);
[[NSUserDefaults standardUserDefaults] setObject:deviceTokenString forKey:DeviceTokenKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
LogError(@"Error in registration. Error: %@", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"receive notification date:%@, server send notification info:%@", [NSDate date], userInfo);
NSString * jsonStr = [userInfo objectForKey:@"acme"];
NSData *data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary * parsedData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:CloudSeverPushNotification object:parsedData];
// [[CloudDriverManager shared] startCloudSync];
}
Apple Remote Push Notifications的更多相关文章
- [Erlang 0106] Erlang实现Apple Push Notifications消息推送
我们的IOS移动应用要实现消息推送,告诉用户有多少条消息未读,类似下图的效果(笑果),特把APNS和Erlang相关解决方案笔记于此备忘. 上面图片中是Apple Notif ...
- iOS 中的Push Notifications简单实现(APNS)
Android中的通知只有一种,就是Local Notifications,而iOS中除了Local Notifications外,还有一种Push Notifications.ios的这2种noti ...
- (转)pem, cer, p12 and the pains of iOS Push Notifications encryption
转自:http://cloudfields.net/blog/ios-push-notifications-encryption/ The serious pains of setting up a ...
- Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth Key
Send Push Notifications to iOS Devices using Xcode 8 and Swift 3 OCT 6, 2016 Push notifications are ...
- Xcode - Your development team, "", does not support the Push Notifications capability.
1.问题描述: 从git上checkout了别人的一个工程文件,选择team时,Xcode显示如下问题 Your development team, "xxx.xxx.xxx", ...
- [PWA] Add Push Notifications to a PWA with React in Chrome and on Android
On Android and in Chrome (but not on iOS), it's possible to send push notifications with a PWA. We'l ...
- iOS8 Push Notifications
本文转载至 http://blog.csdn.net/pjk1129/article/details/39551887 原贴地址:https://parse.com/tutorials/ios-p ...
- Your development team, "", does not support the Push Notifications capability.
问题: Your development team, "", does not support the Push Notifications capability. 解决方法: 1 ...
- iOS10 App适配权限 Push Notifications 字体Frame 遇到的坑!!!!
添加配置权限 <!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key> <string>"x ...
随机推荐
- linux资源监控命令详解
Linux统计/监控工具SAR详细介绍:要判断一个系统瓶颈问题,有时需要几个 sar 命令选项结合起来使用,例如: 怀疑CPU存在瓶颈,可用 sar -u 和 sar -q deng 等来查看 怀疑内 ...
- String类的比较
//strcmp只能运用于数组的比较 //string类可以用成员函数compare() //即a.compare(b) //例如 "; "; a.compare(b)返回值= & ...
- C#读取和写入配置文件
使用.Net2.0中的ConfigurationManager可以方便的实现对配置app.config的读取和写入. ConfigurationManager默认没有自动载入项目,使用前必须手动添加, ...
- .NET开源工作流RoadFlow-流程设计-流程步骤设置-按钮设置
按钮设置是配置当前步骤的处理者可以执行哪些操作,每个按钮都有对应的执行脚本(javascript脚本). 从左边的按钮列表中选择当前步骤需要的按钮. 注意:如果是流程最后一步则要配置完成按钮而不是发送 ...
- [原创]PostgreSQL Plus Advanced Server监控工具PEM(四)
四.PEM管理工具 1.编辑配置 选择进行管理的目标服务器,点击菜单Tools->Server Configuration->postgresql.conf管理服务器配置,可以看到我们经常 ...
- [整理]Selector、shape详解
Selector.shape详解(一) Selector的结构描述: <?xml version="1.0" encoding="utf-8"?> ...
- Swift :?和 !
Swift语言使用var定义变量,但和别的语言不同,Swift里不会自动给变量赋初始值, 也就是说变量不会有默认值,所以要求使用变量之前必须要对其初始化 .如果在使用变量之前不进行初始化就会报错: v ...
- Resizing the View(待续。。。。)
在iOS开发的过程中,控件的大小和位置如何去安排是一个现在看来比较麻烦的事情,需要从上到下的通知和从下到上的调整.而这部分在整个开发过程中是比较重要的,但是却经常没有被掌握.如果将这部分掌握,不管界面 ...
- (转)android Fragments详解四:管理fragment
要管理fragment们,需使用FragmentManager,要获取它,需在activity中调用方法getFragmentManager(). 你可以用FragmentManager来做以上事情: ...
- Django ajax MYSQL Highcharts<1>
Another small project with django/Ajax/Mysql/Highcharts. 看下效果图 - delivery dashboard .嘿嘿 是不是还蛮好看的. 废 ...