diff --git a/ios/Classes/AblyFlutter.m b/ios/Classes/AblyFlutter.m index cdbdfcc78..df9630d72 100644 --- a/ios/Classes/AblyFlutter.m +++ b/ios/Classes/AblyFlutter.m @@ -793,12 +793,30 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( #pragma mark - Push Notifications Registration - UIApplicationDelegate --(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - [_instanceStore didRegisterForRemoteNotificationsWithDeviceToken: deviceToken]; +- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + ARTRealtime *const realtime = [_instanceStore realtimeFrom:PushHandlers.pushActivatorHandle]; + if (realtime) { + [ARTPush didRegisterForRemoteNotificationsWithDeviceToken:deviceToken realtime:realtime]; + } + else { + ARTRest *const rest = [_instanceStore restFrom:PushHandlers.pushActivatorHandle]; + if (rest) { + [ARTPush didRegisterForRemoteNotificationsWithDeviceToken:deviceToken rest:rest]; + } + } } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { - [_instanceStore didFailToRegisterForRemoteNotificationsWithError:error]; + ARTRealtime *const realtime = [_instanceStore realtimeFrom:PushHandlers.pushActivatorHandle]; + if (realtime) { + [ARTPush didFailToRegisterForRemoteNotificationsWithError:error realtime:realtime]; + } + else { + ARTRest *const rest = [_instanceStore restFrom:PushHandlers.pushActivatorHandle]; + if (rest) { + [ARTPush didFailToRegisterForRemoteNotificationsWithError:error rest:rest]; + } + } } - (BOOL)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { diff --git a/ios/Classes/AblyInstanceStore.h b/ios/Classes/AblyInstanceStore.h index c2164ce8f..4567f2a83 100644 --- a/ios/Classes/AblyInstanceStore.h +++ b/ios/Classes/AblyInstanceStore.h @@ -25,10 +25,6 @@ NS_ASSUME_NONNULL_BEGIN -(ARTPaginatedResult *) getPaginatedResult:(NSNumber *const) handle; --(void) didRegisterForRemoteNotificationsWithDeviceToken:(NSData *const) deviceToken; - --(void)didFailToRegisterForRemoteNotificationsWithError:(NSError *const)error; - -(void)reset; @end diff --git a/ios/Classes/AblyInstanceStore.m b/ios/Classes/AblyInstanceStore.m index 99ced5c49..fbf97a812 100644 --- a/ios/Classes/AblyInstanceStore.m +++ b/ios/Classes/AblyInstanceStore.m @@ -65,21 +65,6 @@ -(ARTPaginatedResult *) getPaginatedResult:(NSNumber *const) handle { return _paginatedResults[handle]; } -// Set device token for the first created realtime object, device of which is available for others, because it's static --(void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *const)deviceToken { - ARTRealtime *const realtime = _realtimeInstances.allValues.firstObject; - if (realtime) { - [ARTPush didRegisterForRemoteNotificationsWithDeviceToken:deviceToken realtime:realtime]; - } -} - --(void)didFailToRegisterForRemoteNotificationsWithError:(NSError *const)error { - ARTRealtime *const realtime = _realtimeInstances.allValues.firstObject; - if (realtime) { - [ARTPush didFailToRegisterForRemoteNotificationsWithError:error realtime:realtime]; - } -} - -(void)reset { for (ARTRealtime *const r in _realtimeInstances.allValues) { [r close]; diff --git a/ios/Classes/handlers/PushHandlers.swift b/ios/Classes/handlers/PushHandlers.swift index 7ffdc13ef..64e917266 100644 --- a/ios/Classes/handlers/PushHandlers.swift +++ b/ios/Classes/handlers/PushHandlers.swift @@ -2,12 +2,17 @@ import Foundation import UserNotifications public class PushHandlers: NSObject { + + @objc + public static var pushActivatorHandle: NSNumber? + @objc public static var pushNotificationTapLaunchedAppFromTerminatedData: Dictionary? = nil; @objc public static let activate: FlutterHandler = { ably, call, result in if let push = getPush(instanceStore: ably.instanceStore, call: call, result: result) { + pushActivatorHandle = (call.arguments as! AblyFlutterMessage).handle PushActivationEventHandlers.getInstance(methodChannel: ably.channel).flutterResultForActivate = result push.activate() } else { @@ -18,6 +23,7 @@ public class PushHandlers: NSObject { @objc public static let deactivate: FlutterHandler = { ably, call, result in if let push = getPush(instanceStore: ably.instanceStore, call: call, result: result) { + pushActivatorHandle = nil PushActivationEventHandlers.getInstance(methodChannel: ably.channel).flutterResultForDeactivate = result push.deactivate() } else {