Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed push token handling to respect RSH3a3a #534

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 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 All @@ -814,16 +792,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}

#pragma mark - Push Notifications Registration - UIApplicationDelegate
/// Save the deviceToken provided so we can pass it to the first Ably client which gets created, in createRealtime or createRest.

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Set deviceToken on all existing Ably clients, and a property which used for all future Ably clients.
[_instanceStore didRegisterForRemoteNotificationsWithDeviceToken: deviceToken];
}

/// Save the error if it occurred during APNs device registration provided so we can pass it to the first Ably client which gets created, in createRealtime or createRest.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
// This error will be used when the first Ably client is made.
_instanceStore.didFailToRegisterForRemoteNotificationsWithError_error = error;
[_instanceStore didFailToRegisterForRemoteNotificationsWithError:error];
}

- (BOOL)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
Expand Down
4 changes: 1 addition & 3 deletions ios/Classes/AblyInstanceStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ NS_ASSUME_NONNULL_BEGIN

-(void) didRegisterForRemoteNotificationsWithDeviceToken:(NSData *const) deviceToken;

@property(nonatomic, nullable) NSData * didRegisterForRemoteNotificationsWithDeviceToken_deviceToken;

@property(nonatomic, nullable) NSError * didFailToRegisterForRemoteNotificationsWithError_error;
-(void)didFailToRegisterForRemoteNotificationsWithError:(NSError *const)error;

-(void)reset;

Expand Down
21 changes: 11 additions & 10 deletions ios/Classes/AblyInstanceStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,21 @@ -(ARTPaginatedResult *) getPaginatedResult:(NSNumber *const) handle {
return _paginatedResults[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];
// 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];
Expand Down
Loading