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 ...
随机推荐
- OVER Clause是个好东西,常和ROW_NUMBER()、Sum、AVG、Count、Min、Max配合使用
根据SQL官方帮助的实例: USE AdventureWorks2012; GO SELECT ROW_NUMBER() OVER(PARTITION BY PostalCode ORDER BY S ...
- Delphi7中编译提示“Unsafe type 'PChar'”的原因及处理办法
delphi7中加入了对.net的支持 在.net中是没有指针的(托管环境中),所以指针都是不安全的,不符合.net规范 所以d7里有警告,可以不管它 DELPHI7已经考虑到了移植到点NET的问题, ...
- 第二章 管理程序流(In .net4.5) 之 管理多线程
1. 概述 本章包括同步资源以及取消长时间任务相关的内容. 2. 主要内容 2.1 同步资源 ① lock关键字实现.会阻塞程序,有可能会导致死锁. ② volatile关键字可以禁用编译优化,用于避 ...
- 在Windows下使用BAT调度存储在资源库中的KTR
描述: 在Windows下使用BAT调度存储在资源库中的KTR 准备环境: 1.ktr文件(该KTR必须是存储在资源管库中的) 2.bat文件 @echo off D: cd D:\software\ ...
- 人脸检测的API例子
package cliu.TutorialOnFaceDetect; /* * MyImageView.java * Download by http://www.codefans.net * [AU ...
- Go语言工程结构
Go是一门推崇软件工程理念的编程语言. Go的代码必须放在GOPATH目录下,它应该包含三个子目录: src:用于以代码包的形式组织并保存Go源码文件.应该分为三类:库源码文件.命令源码文件.测试源码 ...
- Memcached 在windows环境下安装
1.memcached简介 memcached是一个高性能的分布式内存对象缓存系统,它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动应用的访问性 能.memcached基于 ...
- ubuntu14.04建立交叉编译环境, 注意事项
ubuntu14.04建立交叉编译环境, 注意事项 ~$ arm-linux-gcc/opt/FriendlyARM/toolschain/4.4.3/bin/arm-linux-gcc: 15: e ...
- Mono for Android (4)-- 图片转为二进制,二进制转回图片
最近纠结蓝牙打印的问题,想着图片先转为二进制发给打印机,找了好多资料,终于成功了,贴出来共享一下 先是图片转换为二进制的: Bitmap bitmap = BitmapFactory.DecodeRe ...
- asp.net自带的异步刷新控件使用
一直都是使用jquery的$.ajax,由于刚刚加入的公司是用asp.net的,webform与之前的ajax加在一起显得很混乱,后来发现asp.net已经封装了一下ajax功能,就查了一下,并且做了 ...