pushKit学习
(2019-02-21 15:59:40)| 分类: iOS |
pushkit方式,有别于普通的apns,它不会弹出通知,而是悄悄的告诉我们的app有推送过来,让app做出相应的处理。
当app在线,后台,离线pushkit都有推送此时当在线时不希望弹出本地推送的状态栏。
第一步:申请证书。
步骤:
1)跟apns差不多,在Creating a VoIP certificate in the Apple Developer Member Center
Production中选择VoIP Services certificate.
2)生成的证书CertificateSigningReques
客户端和pushkit server端都安装这个证书
3)客户端从“钥匙串”->左侧:我的证书->VoIP Services:com.testxx.suiyizhengshu.右击导出此证书。格式可以选:.p12,.cer等格式。
4)VoIP不区分生产环境还是开发环境(production or development)也就是生成的证书是一个。
第二步:ios客户端
1)Xcode Project > Capabilities pane。Enabling the VoIP background mode in an app。
Background Modes:Voice over IP。
题外话:我因为个人原因很久没升级xcode,发现没有这选项,xcode升级到10就出现了。当然mac系统也升级到MacOSHighSierra10.16.6。话说升级mac,各种折腾,后来重装mac系统才升级成功。
借鉴:
a.https://jingyan.baidu.com/article/d169e1867d1d7d436711d86a
b.https://support.apple.com/zh-cn/macos/high-sierra 升级到macOS High Sierra
c.http://blog.sina.com.cn/s/blog_67a6d62e0102xae7.html Mac电脑如何清理硬盘空间
2)
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOp
{
}
//注册pushkit
- (void)registePushKitApi {
}
#pragma - pushkitDelegate
// PushKit delete
- (void)pushRegistry:(PKPushRegistry *)registry
didUpdatePushCredentials
}
备注:把credentials.token提供给pushkit server端。
- (void)pushRegistry:(PKPushRegistry *)registry
didReceiveIncomingPushWi
}
备注:pushkit server端的payload即是上面回调函数中的payload.dictionaryPayload:
格式如下:
{
“aps":{"alert":"This is some fancy message.","badge”:1},
“msg_id”:”12345678”
}
-(void)pushRegistry:(PKPushRegistry *)registry
didInvalidatePushTokenFo
}
第三步骤,Pushkit server端解析
server端代码:https://github.com/stefanhafeneger/PushMeBaby
1.打开:README.md。就是把生成的证书起个生产证书名称:aps0.cer,开发模式:aps_development0.cer.其实是同一个证书,只是名字不一样。替换项目中的./PushMeBaby-master这个目录下面的aps0.cer,aps—development0.cer。
2.server端production地址:gateway.push.apple.com。development地址:gateway.sandbox.push.apple.com。
.const char *hostName = _production?"gateway.push.apple.com":"gateway.sandbox.push.apple.com";
3.self->_certificateRef:
com.testxx.suiyizhengshu i: Apple Worldwide Developer Relations Certification Authority>
参考文章:
1.https://www.jianshu.com/p/213641cf524a PushKit 的简单实验 作者:谁动了我的芝麻糖
2.Pushkit官网:https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html
3.https://www.jianshu.com/p/afc8de658931

加载中…