From 0730a10d2af5cdeb47c91717e0faef74ba68a086 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Thu, 5 Mar 2020 09:51:38 +0100 Subject: [PATCH] fix push notification not received for ios13 --- Classes/LinphoneAppDelegate.m | 75 ++++++++++++++++++----------------- Classes/LinphoneManager.m | 1 + 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 61163d01a..0fbad7fcd 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -446,46 +446,47 @@ return; } - NSString *uuid = [NSString stringWithFormat:@"", [LinphoneManager.instance lpConfigStringForKey:@"uuid" inSection:@"misc" withDefault:NULL]]; - NSString *sipInstance = [aps objectForKey:@"uuid"]; - if (sipInstance && uuid && ![sipInstance isEqualToString:uuid]) { - LOGE(@"Notification [%p] was intended for another device, ignoring it.", userInfo); - LOGD(@"My sip instance is: [%@], push was intended for: [%@].", uuid, sipInstance); - return; - } - NSString *callId = [aps objectForKey:@"call-id"] ?: @""; - if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && [self addLongTaskIDforCallID:callId]) - [LinphoneManager.instance startPushLongRunningTask:loc_key callId:callId]; - - if ([callId isEqualToString:@""]) { - // Present apn pusher notifications for info - LOGD(@"Notification [%p] came from flexisip-pusher.", userInfo); - if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { - UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; - content.title = @"APN Pusher"; - content.body = @"Push notification received !"; - - UNNotificationRequest *req = [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL]; - [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:req withCompletionHandler:^(NSError * _Nullable error) { - // Enable or disable features based on authorization. - if (error) { - LOGD(@"Error while adding notification request :"); - LOGD(error.description); - } - }]; - } else { - UILocalNotification *notification = [[UILocalNotification alloc] init]; - notification.repeatInterval = 0; - notification.alertBody = @"Push notification received !"; - notification.alertTitle = @"APN Pusher"; - [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; + if (![callId isEqualToString:@""] && [loc_key isEqualToString:@"IC_MSG"] && [CallManager callKitEnabled]) { + // Report a new Incoming call without lantacy when the callkit is enabled. + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && [self addLongTaskIDforCallID:callId]) { + [LinphoneManager.instance startPushLongRunningTask:loc_key callId:callId]; } - } else { [LinphoneManager.instance addPushCallId:callId]; - if ([loc_key isEqualToString:@"IC_MSG"] && [CallManager callKitEnabled]) { - // callkit only for call not message. - [CallManager.instance displayIncomingCallWithCallId:callId]; + } else { + NSString *uuid = [NSString stringWithFormat:@"", [LinphoneManager.instance lpConfigStringForKey:@"uuid" inSection:@"misc" withDefault:NULL]]; + NSString *sipInstance = [aps objectForKey:@"uuid"]; + if (sipInstance && uuid && ![sipInstance isEqualToString:uuid]) { + LOGE(@"Notification [%p] was intended for another device, ignoring it.", userInfo); + LOGD(@"My sip instance is: [%@], push was intended for: [%@].", uuid, sipInstance); + return; + } + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && [self addLongTaskIDforCallID:callId]) + [LinphoneManager.instance startPushLongRunningTask:loc_key callId:callId]; + + if ([callId isEqualToString:@""]) { + // Present apn pusher notifications for info + LOGD(@"Notification [%p] came from flexisip-pusher.", userInfo); + if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { + UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; + content.title = @"APN Pusher"; + content.body = @"Push notification received !"; + + UNNotificationRequest *req = [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL]; + [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:req withCompletionHandler:^(NSError * _Nullable error) { + // Enable or disable features based on authorization. + if (error) { + LOGD(@"Error while adding notification request :"); + LOGD(error.description); + } + }]; + } else { + UILocalNotification *notification = [[UILocalNotification alloc] init]; + notification.repeatInterval = 0; + notification.alertBody = @"Push notification received !"; + notification.alertTitle = @"APN Pusher"; + [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; + } } } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index e68813a09..58a2b0aea 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1564,6 +1564,7 @@ static int comp_call_id(const LinphoneCall *call, const char *callid) { [pushCallIDs removeObjectAtIndex:0]; [pushCallIDs addObject:callid]; + [CallManager.instance displayIncomingCallWithCallId:callid]; } - (BOOL)popPushCallID:(NSString *)callId {