1.PushKit的认识

(1)概念

ios8苹果新引入了名为pushkit的框架和一种新的push通知类型,被称作voip push.该push方式旨在提供区别于普通apns push的能力,通过这种push方式可以使app执行制定的代码(在弹出通知给用户之前);而该通知的默认行为和apns通知有所区别,它的默认行为里面是不会弹出通知的

(2)作用

pushkit中的voippush,可以帮助我们提升voip应用的体验,优化voip应用的开发实现,降低voip应用的电量消耗,它需要我们重新规划和设计我们的voip应用,从而得到更好的体验(voip push可以说是准实时的,实侧延时1秒左右);苹果的目的是提供这样一种能力,可以让我们抛弃后台长连接的方案,也就是说应用程序通常不用维持和voip服务器的连接,在呼叫或者收到呼叫时,完成voip服务器的注册;当程序被杀死或者手机重启动时,都可以收到对方的来电,正常开展voip的业务。也就是说,我们当前可以利用它来优化voip的体验,增加接通率;

2.PushKit的使用教程

(1)创建指定APP ID(非通配)

与远程推送类似,App ID不能使用通配ID必须使用指定APP ID并且生成配置文件中选择Push Notifications服务,一般的开发配置文件无法完成注册;应用程序的Bundle Identifier必须和生成配置文件使用的APP ID完全一致。

(2)创建voip服务的证书

跟apns push类似,pushkit的voippush也需要申请证书,voip push的证书申请步骤截图如下:

(3)导出证书为.pem格式(证书和私钥)

详细方法见:http://www.cnblogs.com/cy568searchx/

(4)把.pem文件提供给服务端

(5)在appDelegate中注册PushKit的服务(与注册通知相同),ios8.0方式如下:

UIUserNotificationSettings *userNotifySetting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:userNotifySetting];
[[UIApplication sharedApplication] registerForRemoteNotifications];

3 代码中集成

(1)在应用启动(appdelegate的didfinishlaunchwithoptions)后或根控制器的初始化等方法内调用如下代码:

 PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
pushRegistry.delegate = self;
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];

(2) 在appdelegate或框架viewcontroller类中实现voip push的代理:

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type { }

上面的代理方法是设备从苹果服务器获取到了voip token,然后传递给应用程序;我们需要把这个token传递到push服务器(和apns push类似,我们也是要传递apns token到push服务器,但是这两个token的获取方式不同,分别在不同的代理方法中回调给应用,且这两个token的内容也是不同的)。

(3)在一切正常的情况下,push server在获取到用户的voip token之后,如下回调会在push server下发消息到对应token的设备时被触发

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type { }

上面的回调代码里仅仅打印了日志,触发了一个本地通知;这个代理方法是收到voip push通知时触发的;

如果一切正常,该通知在手机重启、应用被系统回收、手动kill程序的情况下,依然能够被触发,且可以有一段时间用来执行自己的代码(比如voip注册等)

注:应用申请一个精确ID的mobile provision打包;

为了测试方便:可以通过一个网上的一个MAC应用Demo:PushMeBaby

下面是比较官方的一份说明文档:

What PushKit does and why you should use it.

In iOS 8 Apple introduced PushKit as part of their effort to improve battery life, performance, and stability for VoIP applications such as Skype, WhatsApp, and LINE.

Previously, VoIP apps needed to maintain a persistent connection in order to receive calls. Keeping a connection open in the background, drains the battery as well as causes all kinds of problems when the app crashes or is terminated by the user.

PushKit is meant to solve these problems by offering a high-priorty push notification with a large payload. The VoIP app receives the notification in the background, sets up the connection and displays a local notification to the user. When the user swipes the notification, the call is ready to connect.

This guide will walk you through the steps to setup a VoIP application. We'll be using Swift to implement this example. Source files from this example are available on Github.

Differences from regular APNS Push Notifications

VoIP push notifications are different than regular APNS notifications mainly in how they are setup from the iOS app. Instead of using application.registerForRemoteNotifications() and handling the received notifications in application:didReceiveRemoteNotification, we use PushKit and thePKPushRegistryDelegate to request a device token and handle the delegate methods.

Unlike regular push notifications, PushKit does not prompt the user to accept VoIP pushes. PushKit will always grant a device token to apps that have the VoIP entitlements without asking for approval. Further, VoIP pushes do not have any UI and do not show an alert. They act more like content-available pushes, and you must handle the received notification and present a local notification.

Summary of differences:
  Regular Push VoIP Push
Getting Device Token application.registerForRemoteNotifications() set PKPushRegistry.desiredPushTypes
Handle Registration application:didRegisterForRemoteNotificationsWithDeviceToken: pushRegistry:didUpdatePushCredentials
Handle Received Notification application:didReceiveRemoteNotification pushRegistry:didReceiveIncomingPushWithPayload
Payload Size 2048 bytes 4096 bytes
Certificate Type iOS Push Services VoIP Services
Requires User Consent Yes No*

* The user must agree to receive local notifications.

关于PushKit的使用总结的更多相关文章

  1. IOS的APNS和PushKit门道详述

    基本功 iOS在诞生之初为了最大程度的保证用户体验,做了一些高瞻远瞩且影响深远的设计.APNs(Apple Push Notification service)就是其中一项. 早期iOS设备的内存和C ...

  2. PushKit和传统长连接方式的比较

    iOS and PushKit This post will cover basic concepts for VoIP apps on iOS. I will not post any code ( ...

  3. iOS 系统架构

    https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/ ...

  4. 【腾讯Bugly干货分享】QQ电话适配iOS10 Callkit框架

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/58009392302e4725036142fc Dev Club 是一个交流移动 ...

  5. iOS各个版本的新特性介绍

    官方汇总 What's News in iOS iOS 9.3 to iOS 10.0 API Differences Objective-C /usr/include Accelerate Audi ...

  6. iOS10新特性之CallKit开发详解:锁屏接听和来电识别

    国庆节过完了,回家好好休息一天,今天好好分享一下CallKit开发.最近发现好多吃瓜问CallKit的VoIP开发适配,对iOS10的新特性开发和适配也在上个月完成,接下来就分享一下VoIP应用如何使 ...

  7. 关于Socket建立长连接遇到的bug信息

    下面是本人在Socket连接的开发中遇到的bug总结 1."远程服务器关闭了Socket长连接'的错误信息 2.关于"kCFStreamNetworkServiceTypeVoIP ...

  8. device framework(设备框架)

    Table A-1  Device frameworks Name First available Prefixes Description Accelerate.framework 4.0 cbla ...

  9. iOS8新增加的frameworks, 在目前基于7以上开发的情况下, 使用下列sdk要注意设置成optional

    Added frameworks: AVKitCloudKitCoreAudioKitCoreAuthenticationHealthKitHomeKitLocalAuthenticationMeta ...

随机推荐

  1. 并查集+拓扑排序 赛码 1009 Exploration

    题目传送门 /* 题意:无向图和有向图的混合图判环: 官方题解:首先对于所有的无向边,我们使用并查集将两边的点并起来,若一条边未合并之前, 两端的点已经处于同一个集合了,那么说明必定存在可行的环(因为 ...

  2. CodeForces Round 197 Div2

    这次出的题水爆了,借着这个机会终于把CF的号变蓝了.A. Helpful Mathstime limit per test2 secondsmemory limit per test256 megab ...

  3. 游戏 window

    using UnityEngine; using System.Collections; public class YY : MonoBehaviour { ,,,); ,,,); // Use th ...

  4. 【BZOJ】3709: [PA2014]Bohater(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3709 很水的题...但是由于脑洞小..漏想了一种情况.. 首先显然能补血的先杀.. 然后杀完后从补血 ...

  5. 【wikioi】1018 单词接龙

    题目链接 算法:DFS+考你阅题 题目描述: 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中 ...

  6. 【BZOJ】2761: [JLOI2011]不重复数字(set+巨水题+超坑题)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2761 太水了,不说了. 但是这格式错误我已经没话说了....行末不能有空格 #include < ...

  7. 用LinqPad查看Nhibernate生成的sql语句

    使用Nhibernate开发一般都要对Nhibernate生成的sql语句进行查看及分析,查看Nhibernate生成的sql语句,可以使用NHProfiler和log4net.但NHProfiler ...

  8. c#操作excel后关闭excel.exe的方法

    关闭进程 C#和Asp.net下excel进程一被打开,有时就无法关闭,   尤其是website.对关闭该进程有过GC.release等方法,但这些方法并不是在所有情况下均适用.  于是提出了kil ...

  9. linux用户和组管理

    添加组groupadd sftp 把用户mysftp加入组sftp中:gpasswd -a mysftp sftp 把用户mysftp加入组sftp中:usermod -a -G sftp mysft ...

  10. 免杀ASP一句话

    <% wei="日日日)""wei""(tseuqer lave 日" execute(UnEncode(wei)) function ...