Skip to content

Commit

Permalink
Removed unnecessary push token handling. Token is requested by ably-c…
Browse files Browse the repository at this point in the history
…ocoa 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.
  • Loading branch information
maratal committed Jul 25, 2024
1 parent ca85d49 commit 71b24d0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 34 deletions.
22 changes: 0 additions & 22 deletions ios/Classes/AblyFlutter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions ios/Classes/AblyInstanceStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions ios/Classes/AblyInstanceStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down

0 comments on commit 71b24d0

Please sign in to comment.