Skip to content

Removed push token handling to respect RSH3a3a #534

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
55 changes: 26 additions & 29 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,35 @@ - (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];

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
if (PushHandlers.pushActivatorHandle == nil)
return;
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];
}
}
}

/// 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;
if (PushHandlers.pushActivatorHandle == nil)
return;
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 {
Expand Down
6 changes: 0 additions & 6 deletions ios/Classes/AblyInstanceStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ NS_ASSUME_NONNULL_BEGIN

-(ARTPaginatedResult *) getPaginatedResult:(NSNumber *const) handle;

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

@property(nonatomic, nullable) NSData * didRegisterForRemoteNotificationsWithDeviceToken_deviceToken;

@property(nonatomic, nullable) NSError * didFailToRegisterForRemoteNotificationsWithError_error;

-(void)reset;

@end
Expand Down
14 changes: 0 additions & 14 deletions ios/Classes/AblyInstanceStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,6 @@ -(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];
[ARTPush didRegisterForRemoteNotificationsWithDeviceToken:deviceToken realtime:realtime];
}
}

-(void)reset {
for (ARTRealtime *const r in _realtimeInstances.allValues) {
[r close];
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/handlers/PushHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import Foundation
import UserNotifications

public class PushHandlers: NSObject {

@objc
public static var pushActivatorHandle: NSNumber?

@objc
public static var pushNotificationTapLaunchedAppFromTerminatedData: Dictionary<AnyHashable, Any>? = 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 {
Expand All @@ -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 {
Expand Down
Loading