APNS 离线锁屏铃声不中断

场景: 被叫端被kill且锁屏状态 主叫端发起音视频呼叫,被叫端显示来电,结束呼叫; 现象: 被叫端来电铃声在主叫端结束呼叫时还在播放
发布时间: 2021-12-08 18:37

回答:

在NotificationService.m文件

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {

NSDictionary *aps = [request.content objectForKey:@"aps"];

    NSString *category = [aps objectForKey:@"category"];

    if (category && [category isEqualToString:@"RC:VCHangup"]) {

        NSString *identifier = [aps objectForKey:@"thread-id"];

        if (identifier) {

            [[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[identifier]];

        }

        

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

            self.bestAttemptContent = [request.content mutableCopy];

            self.contentHandler(self.bestAttemptContent);

        });

    } else {

        self.contentHandler(self.bestAttemptContent);

    }

}