From 71b24d007ae88895370d476f870587d3ed0f3fb1 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Thu, 25 Jul 2024 17:48:02 +0200 Subject: [PATCH] Removed unnecessary push token handling. Token is requested by ably-cocoa and received by flutter, which sends it to ably via the first available `ARTRealtime` object. All instances have the same value for the `device.push` property, since the `device` itself is stored in a static variable. --- ios/Classes/AblyFlutter.m | 22 ---------------------- ios/Classes/AblyInstanceStore.h | 4 ---- ios/Classes/AblyInstanceStore.m | 10 ++-------- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/ios/Classes/AblyFlutter.m b/ios/Classes/AblyFlutter.m index d02602b20..f60963ea8 100644 --- a/ios/Classes/AblyFlutter.m +++ b/ios/Classes/AblyFlutter.m @@ -76,14 +76,6 @@ -(void)reset; ARTRest *const rest = [[ARTRest alloc] initWithOptions:options.clientOptions]; [instanceStore setRest:rest with: handle]; - NSData *const apnsDeviceToken = ably.instanceStore.didRegisterForRemoteNotificationsWithDeviceToken_deviceToken; - NSError *const error = ably.instanceStore.didFailToRegisterForRemoteNotificationsWithError_error; - if (apnsDeviceToken != nil) { - [ARTPush didRegisterForRemoteNotificationsWithDeviceToken:apnsDeviceToken rest:rest]; - } else if (error != nil) { - [ARTPush didFailToRegisterForRemoteNotificationsWithError:error rest:rest]; - } - result(handle); }; @@ -262,19 +254,6 @@ -(void)reset; } ARTRealtime *const realtime = [[ARTRealtime alloc] initWithOptions:options.clientOptions]; [instanceStore setRealtime:realtime with:handle]; - - // Giving Ably client the deviceToken registered at device launch (didRegisterForRemoteNotificationsWithDeviceToken). - // This is not an ideal solution. We save the deviceToken given in didRegisterForRemoteNotificationsWithDeviceToken and the - // error in didFailToRegisterForRemoteNotificationsWithError and pass it to Ably in the first client that is first created. - // Ideally, the Ably client doesn't need to be created, and we can pass the deviceToken to Ably like in Ably Java. - // This is similarly repeated for in _createRest - NSData *const apnsDeviceToken = ably.instanceStore.didRegisterForRemoteNotificationsWithDeviceToken_deviceToken; - NSError *const error = ably.instanceStore.didFailToRegisterForRemoteNotificationsWithError_error; - if (apnsDeviceToken != nil) { - [ARTPush didRegisterForRemoteNotificationsWithDeviceToken:apnsDeviceToken realtime:realtime]; - } else if (error != nil) { - [ARTPush didFailToRegisterForRemoteNotificationsWithError:error realtime:realtime]; - } result(handle); }; @@ -801,7 +780,6 @@ -(void)reset { } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [[UIApplication sharedApplication] registerForRemoteNotifications]; // Check if application was launched from a notification tap. // https://stackoverflow.com/a/21611009/7365866 diff --git a/ios/Classes/AblyInstanceStore.h b/ios/Classes/AblyInstanceStore.h index 8af0edbc1..60c053deb 100644 --- a/ios/Classes/AblyInstanceStore.h +++ b/ios/Classes/AblyInstanceStore.h @@ -27,10 +27,6 @@ NS_ASSUME_NONNULL_BEGIN -(void) didRegisterForRemoteNotificationsWithDeviceToken:(NSData *const) deviceToken; -@property(nonatomic, nullable) NSData * didRegisterForRemoteNotificationsWithDeviceToken_deviceToken; - -@property(nonatomic, nullable) NSError * didFailToRegisterForRemoteNotificationsWithError_error; - -(void)reset; @end diff --git a/ios/Classes/AblyInstanceStore.m b/ios/Classes/AblyInstanceStore.m index 7ef35ab4d..6b684f684 100644 --- a/ios/Classes/AblyInstanceStore.m +++ b/ios/Classes/AblyInstanceStore.m @@ -67,14 +67,8 @@ -(ARTPaginatedResult *) getPaginatedResult:(NSNumber *const) handle { // Set device token on all existing clients -(void) didRegisterForRemoteNotificationsWithDeviceToken:(NSData *const) deviceToken { - _didRegisterForRemoteNotificationsWithDeviceToken_deviceToken = deviceToken; - - for (id restHandle in _restInstances) { - ARTRest *const rest = _restInstances[restHandle]; - [ARTPush didRegisterForRemoteNotificationsWithDeviceToken:deviceToken rest:rest]; - } - for (id realtimeHandle in _realtimeInstances) { - ARTRealtime *const realtime = _realtimeInstances[realtimeHandle]; + ARTRealtime *const realtime = _realtimeInstances.allValues.firstObject; + if (realtime) { [ARTPush didRegisterForRemoteNotificationsWithDeviceToken:deviceToken realtime:realtime]; } }