iOS VOIP推送

VOIP推送是在iOS8 之后提出来的,依赖PushKit.framework。

1. 应用场景

用于发送 类似微信的 语音通话或者视频通话 时的推送功能,可以做到A呼叫,B响铃。A挂断,B结束响铃的需求。

2. 证书申请

1.创建APPID
2.钥匙串 -- 从证书颁发机构申请证书
3. 申请证书 选择VoIP Services Certificate
646335-4218d306918c411d.png
image.png

3. 注册VOIP推送

依赖头文件 <PushKit/PushKit.h>

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

4. 代理方法

(1)当接收到指定的凭证(包括push令牌)时,将调用此方法
-- 获取token

@required
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)pushCredentials forType:(PKPushType)type{
    token = [[[[credentials.token description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
                    stringByReplacingOccurrencesOfString:@">" withString:@""]
                   stringByReplacingOccurrencesOfString:@" " withString:@""];

(2)当收到指定PKPushType的推送通知时,将调用该方法。

@optional
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type{
    NSDictionary * apns = payload.dictionaryPayload;
}

(3)当收到指定PKPushType的推送通知时,将调用该方法。

@optional
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void(^)(void))completion NS_AVAILABLE_IOS(11_0);

(4)如果先前提供的push令牌不再有效,则调用此方法。没有行动
必须重新注册。此反馈可用于将应用程序的服务器更新为not longer
将指定类型的推送通知发送到此设备。

@optional
- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type;

5.Capabilities 设置

646335-081e9a19b2806261.png
Capabilities设置.png

6.测试工具

https://github.com/shaojiankui/SmartPush

猜你喜欢

转载自blog.csdn.net/weixin_34291004/article/details/87101651