【发布时间】:2020-05-01 13:24:42
【问题描述】:
我能够收到新来电推送通知并报告来电,但是当应用程序处于终止状态时,我没有收到通知并且我只收到未接来电。
下面是我用来处理新来电推送通知的代码:
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
NSString * nameA = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"]
CXProviderConfiguration *config = [[CXProviderConfiguration alloc]initWithLocalizedName:nameA];
config.supportsVideo = FALSE;
config.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:@"callkit_logo"]);
NSArray *ar = @[ [NSNumber numberWithInt:(int)CXHandleTypeGeneric] ];
NSSet *handleTypes = [[NSSet alloc] initWithArray:ar];
[config setSupportedHandleTypes:handleTypes];
[config setMaximumCallGroups:2];
[config setMaximumCallsPerCallGroup:1];
self.cxProvider = [[CXProvider alloc] initWithConfiguration:config];
NSDictionary *dict = [payload.dictionaryPayload objectForKey:@"aps"];
NSString * callm = [dict objectForKey:@"callfrom"];
if (callm.length == 0) {
callm = @"CALL BB";
}
CXHandle *callHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:callm];
CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
callUpdate.remoteHandle = callHandle;
callUpdate.supportsDTMF = YES;
callUpdate.supportsHolding = YES;
callUpdate.supportsGrouping = NO;
callUpdate.supportsUngrouping = NO;
callUpdate.hasVideo = NO;
self.uuid = [NSUUID UUID];
[self.cxProvider reportNewIncomingCallWithUUID:self.uuid update:callUpdate completion:^(NSError *error) {
NSLog(@"error1 ----> %@",error);
if (error) {
if (@available(iOS 13.0, *)) {
[self.cxProvider reportCallWithUUID:self.uuid endedAtDate:[NSDate now] reason:CXCallEndedReasonFailed];
} else {
}
}
}];
CXCallController *callController = [[CXCallController alloc] initWithQueue:dispatch_get_main_queue()];
dispatch_async(dispatch_get_main_queue(), ^{
CXEndCallAction *endCallAction = [[CXEndCallAction alloc] initWithCallUUID:self.uuid];
CXTransaction *transaction = [[CXTransaction alloc] initWithAction:endCallAction];
[callController requestTransaction:transaction completion:^(NSError *error) {
NSLog(@"error2 ----> %@",error);
if (@available(iOS 13.0, *)) {
[self.cxProvider reportCallWithUUID:self.uuid endedAtDate:[NSDate now] reason:CXCallEndedReasonRemoteEnded];
} else {
}
}];
});
[self processPush:payload.dictionaryPayload];
dispatch_async(dispatch_get_main_queue(), ^{completion();});
}
【问题讨论】:
-
具体是什么不起作用?我的第一个出发点是:您是否确保正确设置了推送通知?
didReceiveIncomingPushWithPayload是否被调用?我也不太清楚您对CXEndCallAction的请求放在代码中的什么位置。这绝对不应该是您的didReceiveIncomingPushWithPayload的一部分。 -
是的,我能够接收通知......和报告。当应用程序处于终止状态时,我只接到未接电话..不是电话..请帮助我
-
这是 didReceieveIncomingPushWithPayload 所有我发布的代码的一部分..
-
@PashaMohamed 你找到解决方案了吗?
标签: xcode voip ios13 callkit pushkit