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的更多相关文章

  1. [Erlang 0106] Erlang实现Apple Push Notifications消息推送

        我们的IOS移动应用要实现消息推送,告诉用户有多少条消息未读,类似下图的效果(笑果),特把APNS和Erlang相关解决方案笔记于此备忘.          上面图片中是Apple Notif ...

  2. iOS 中的Push Notifications简单实现(APNS)

    Android中的通知只有一种,就是Local Notifications,而iOS中除了Local Notifications外,还有一种Push Notifications.ios的这2种noti ...

  3. (转)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 ...

  4. 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 ...

  5. Xcode - Your development team, "", does not support the Push Notifications capability.

    1.问题描述: 从git上checkout了别人的一个工程文件,选择team时,Xcode显示如下问题 Your development team, "xxx.xxx.xxx", ...

  6. [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 ...

  7. iOS8 Push Notifications

    本文转载至 http://blog.csdn.net/pjk1129/article/details/39551887   原贴地址:https://parse.com/tutorials/ios-p ...

  8. Your development team, "", does not support the Push Notifications capability.

    问题: Your development team, "", does not support the Push Notifications capability. 解决方法: 1 ...

  9. iOS10 App适配权限 Push Notifications 字体Frame 遇到的坑!!!!

    添加配置权限 <!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key> <string>"x ...

随机推荐

  1. Delphi CxGrid 汇总(4)

    1.     CxGrid汇总功能 ① OptionsView-Footer设置为True,显示页脚   ② CxGrid的Summary选项卡定义要汇总的列和字段名及汇总方式,Footer选项卡定义 ...

  2. DevExpress 中 在做全选的全消功能的时候 加快效率

    在做 DevExpress 中对增加的选择 Check列 控制全选的全消时通过以下代码红色字代码效率会有明显的提升: private void CheckedRow() { try { splashS ...

  3. GoogleMapApi 发布后提示安全问题

    今天日本那边发过来一个Bug说是Google Map打不开,提示安全问题. 最后发现,日本那边的发布路径如下: https:xxxxx.gspserver.co.jp 而Source中Google M ...

  4. 淘宝:OceanBase分布式系统负载均衡案例分享

    Heroku因"随机调度+Rails单线程处理导致延迟增加的负载均衡失败"的案例之后,我们在思考:在负载均衡测试时发现问题并妥善解决的成功经验有没有?于是,挖掘出"淘宝在 ...

  5. 记一个python+sqlalchemy+tornado的一个高并发下,产生重复记录的bug

    场景:在用户通过支付通道支付完成返回时,发现我收到的处理数据记录中有两条同样的数据记录, 也就是同一笔钱,我数据库中记为了两条一样的记录. tornado端代码 from tornado import ...

  6. Hello World程序

    本文最初发表于2015-8-??,是由别的地方迁移过来的 本文利用改写内存的办法在屏幕中央显示“Hello world”字符串. 首先我们需要了解80*25彩色字符模式显示缓冲区的结构. 〉〉内存中B ...

  7. Mybatis 实现手机管理系统的持久化数据访问层

    最近公司需要对客户手机进行管理并提供二维码存储手机串号的加密字符.供其他接入系统通过扫面二维码解析使用.系统提供手机信息管理,客户管理,用户管理功能. 1.使用到的POJO类 1.1 User pac ...

  8. JVM学习总结四——内存分配策略

    之前几篇我们介绍了jvm的内存模型以及垃圾回收机制,而本篇我们将介绍几个JVM中对象在分配内存是应该遵循的策略.毕竟,想要去优化程序,不仅要考虑垃圾回收的过程,还要从对象内存分配的角度减少gc的代价. ...

  9. C#类型的转换:Converter<TInput, TOutput> 委托的使用

    Converter<TInput, TOutput> 委托 表示将对象从一种类型转换为另一种类型的方法. 此委托由 Array 类的 ConvertAll<TInput, TOutp ...

  10. 【EF Code First】 一对一、一对多的多重关系配置

    这里使用相册Album和图片Picture的关系做示例 1,Album与Picture最基本的关系是1-n(一个相册可以有多张图片) 这时Album.Picture实体类可以这么定义 /// < ...