From 173d957914b7b8e07e87db44dece51dd287f1884 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Fri, 28 May 2021 15:02:20 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20old=20code=20that=20prevented=20from?= =?UTF-8?q?=20registering=20for=20remote=20push=20notification=20when=20st?= =?UTF-8?q?arting=20linphone=20from=20background,=20and=20fix=20a=20bug=20?= =?UTF-8?q?where=20deactivating=20the=20push=20notification=20for=20a=20sp?= =?UTF-8?q?ecific=20account=20wasn=E2=80=99t=20saved=20when=20going=20rest?= =?UTF-8?q?arting=20the=20app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/LinphoneAppDelegate.m | 5 +++-- Classes/LinphoneManager.h | 2 -- Classes/LinphoneManager.m | 24 ++++++++---------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index c34381278..65e996b48 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -81,6 +81,7 @@ - (void)applicationWillEnterForeground:(UIApplication *)application { LOGI(@"%@", NSStringFromSelector(_cmd)); + [LinphoneManager.instance startLinphoneCore]; [LinphoneManager.instance.fastAddressBook reloadFriends]; @@ -486,13 +487,13 @@ didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { LOGI(@"[APNs] %@ : %@", NSStringFromSelector(_cmd), deviceToken); dispatch_async(dispatch_get_main_queue(), ^{ - [LinphoneManager.instance setRemoteNotificationToken:deviceToken]; + linphone_core_did_register_for_remote_push(LC, (__bridge void*)deviceToken); }); } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { LOGI(@"[APNs] %@ : %@", NSStringFromSelector(_cmd), [error localizedDescription]); - [LinphoneManager.instance setRemoteNotificationToken:nil]; + linphone_core_did_register_for_remote_push(LC, nil); } #pragma mark - UNUserNotifications Framework diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 3244079c2..710338ea6 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -199,8 +199,6 @@ typedef struct _LinphoneManagerSounds { @property (readonly) const char* backCamId; @property(strong, nonatomic) NSString *SSID; @property (readonly) sqlite3* database; -@property(nonatomic, strong) NSData *pushKitToken; -@property(nonatomic, strong) NSData *remoteNotificationToken; @property (readonly) LinphoneManagerSounds sounds; @property (readonly) NSMutableArray *logs; @property (nonatomic, assign) BOOL bluetoothAvailable; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index c82a19037..2c922c24e 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1286,14 +1286,18 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat } - (void)startLinphoneCore { - bool pushEnabled = [self lpConfigIntForKey:@"proxy" inSection:@"push_notification_allowed"]; - linphone_core_set_push_notification_enabled([LinphoneManager getLc], pushEnabled); + bool corePushEnabled = [self lpConfigIntForKey:@"proxy" inSection:@"push_notification_allowed"]; + linphone_core_set_push_notification_enabled([LinphoneManager getLc], corePushEnabled); + linphone_core_start([LinphoneManager getLc]); + const MSList *accountsList = linphone_core_get_account_list(theLinphoneCore); while (accountsList) { LinphoneAccount * account = accountsList->data; LinphoneAccountParams * accountParams = linphone_account_params_clone(linphone_account_get_params(account)); - linphone_account_params_set_push_notification_allowed(accountParams, pushEnabled); - linphone_account_params_set_remote_push_notification_allowed(accountParams, pushEnabled); + // In linphone-iphone, remote and voip push autorisations always go together. + bool accountPushAllowed = linphone_account_params_get_push_notification_allowed(accountParams); + linphone_account_params_set_remote_push_notification_allowed(accountParams, accountPushAllowed); + LinphonePushNotificationConfig *pushConfig = linphone_account_params_get_push_notification_config(accountParams); #ifdef DEBUG @@ -1302,13 +1306,10 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat #define PROVIDER_NAME "apns" #endif linphone_push_notification_config_set_provider(pushConfig, PROVIDER_NAME); - linphone_account_set_params(account, accountParams); linphone_account_params_unref(accountParams); accountsList = accountsList->next; } - - linphone_core_start([LinphoneManager getLc]); } - (void)createLinphoneCore { @@ -1794,15 +1795,6 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { [CallManager.instance startCallWithAddr:iaddr isSas:FALSE]; } -#pragma mark - Property Functions -- (void)setRemoteNotificationToken:(NSData *)remoteNotificationToken { - if (remoteNotificationToken == _remoteNotificationToken) { - return; - } - _remoteNotificationToken = remoteNotificationToken; - linphone_core_did_register_for_remote_push(LC, (__bridge void*)remoteNotificationToken); -} - #pragma mark - Misc Functions + (PHFetchResult *)getPHAssets:(NSString *)key { PHFetchResult *assets;