美文网首页
PushKit实践记录

PushKit实践记录

作者: runsuc | 来源:发表于2023-04-20 14:42 被阅读0次

前提:使用的iOS16系统测试

1.需要引入PushKit和CallKit,两个都需要

#import <PushKit/PushKit.h>

#import <CallKit/CallKit.h>

如果没有用CallKit,会存在推送成功,但是手机上app不在前台收不到回调的情况(后台或者杀死app情况,不会唤起app)

2.注册pushkit

    PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];

    pushRegistry.delegate=self;

    pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];

3.上报token

#pragma mark PKPushRegistryDelegate

- (void)pushRegistry:(PKPushRegistry*)registrydidUpdatePushCredentials:(PKPushCredentials*)credentialsforType:(NSString*)type

{

    if ([type isEqualToString:PKPushTypeVoIP])

    {

        constunsigned*tokenBytes = (constunsigned*)[credentials.tokenbytes];

        NSString *result = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",

                                            ntohl(tokenBytes[0]),ntohl(tokenBytes[1]),

                                            ntohl(tokenBytes[2]),ntohl(tokenBytes[3]),

                                            ntohl(tokenBytes[4]),ntohl(tokenBytes[5]),

                                            ntohl(tokenBytes[6]),ntohl(tokenBytes[7])];

        NSLog(@"pk token str = [%@]",result);

    }

}

4.收到pushkit推送触发的回调

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type withCompletionHandler:(nonnull void (^)(void))completion

{

    NSLog(@"receive payload %@ type %@", payload.dictionaryPayload,type);

    NSNumber*badge = payload.dictionaryPayload[@"aps"][@"badge"];

    badge =@99;

    if([badgeisKindOfClass:[NSNumberclass]])

    {

        [UIApplication sharedApplication].applicationIconBadgeNumber = [badge integerValue];

    }

    CXHandle *callHandle = [[CXHandle alloc] initWithType:CXHandleTypePhoneNumber value:@"123"];

    CXCallUpdate*callUpdate = [[CXCallUpdatealloc]init];

    callUpdate.remoteHandle= callHandle;

    callUpdate.localizedCallerName=@"John Smith";

    callUpdate.supportsHolding=NO;

    callUpdate.supportsGrouping=NO;

    callUpdate.supportsUngrouping=NO;

    callUpdate.hasVideo=NO;

    CXProviderConfiguration *config = [[CXProviderConfiguration alloc] initWithLocalizedName:@"My App"];

    config.maximumCallsPerCallGroup = 1;

    config.supportsVideo=NO;

    CXProvider*provider = [[CXProvideralloc]initWithConfiguration:config];

    [providerreportNewIncomingCallWithUUID:[NSUUID UUID] update:callUpdate completion:^(NSError * _Nullable error) {

        completion();

    }];

}

这个里面要处理使用CallKit来reportNewIncomingCallWithUUID。不然在后台虽然走了这个回调,会crash,Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push。表示您的应用程序在接收到VoIP推送后未能将来电事件通知系统导致crash。

5.要添加xcode项目配置

相关文章

  • PushKit

    通过发送push消息来更新你的app。 总览 PushKit框架通过直接给你的app发送特定种类的消息来进行处理相...

  • pushkit

    pushkit是苹果在iOS8以后引入的一种新的push类型。使用pushkit收到通知时不会弹出警报。首先要申请...

  • PushKit总结

    简介 Question:pushkit是什么?Answer:ios8苹果新引入了名为pushkit的框架和一种新的...

  • Voip Pushkit Callkit的使用

    1、Responding to VoIP Notifications from PushKit https://d...

  • iOS PushKit调试小记

    1、在appdelegate中引入PushKit 并遵循PKPushRegistryDelegate协议 2、设置...

  • iOS PushKit 调试

    1、与第三方联调是发现,在app配置在开发环境,收不到Voip推送,后台提示 token无效2、如果把app配置成...

  • PushKit的使用

    1、为什么使用PushKit? iOS10之后,苹果推出了CallKit框架增强VoIP应用的体验,主要表现在3个...

  • 【精时力管理】时间记录02

    崔律的《时间记录》第2讲的课后实践。 〈实践事项Do〉 调整我的类别: 〈实践日志(记录)〉 1.我的实践: ①在...

  • 求职每日说——岗前实践24

    岗前实践同样需要记录,大学生求职者在进行完岗前实践后,建议向实践单位索取实践证明,这样既是对实践经历的记录也是对自...

  • iOS Voip push部分笔记

    Voip push与普通push区分开的部分 引入PushKit头文件 #import 遵守协议 声明属性 @pr...

网友评论

      本文标题:PushKit实践记录

      本文链接:https://www.haomeiwen.com/subject/szirjdtx.html