From 99b856233dae58a37233714bfae5e0fec39e332c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 3 Jul 2017 11:37:37 +0200 Subject: [PATCH] [iOS] Fix joining initial URL if app was closed On iOS, if the app is closed the startup options are only passed as the `launchOptions` dictionary of `applicationDidFinishLaunching`. Thus add a helper method to be called from there by embedding applications so we can copy that dictionary. --- ios/app/src/AppDelegate.m | 9 +++++---- ios/sdk/src/JitsiMeetView.h | 3 +++ ios/sdk/src/JitsiMeetView.m | 23 ++++++++++++++++++++--- ios/sdk/src/RCTBridgeWrapper.h | 2 ++ ios/sdk/src/RCTBridgeWrapper.m | 6 ++++-- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/ios/app/src/AppDelegate.m b/ios/app/src/AppDelegate.m index 495508bd4c..3073dc84a3 100644 --- a/ios/app/src/AppDelegate.m +++ b/ios/app/src/AppDelegate.m @@ -22,14 +22,15 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - return YES; + return [JitsiMeetView application:application + didFinishLaunchingWithOptions:launchOptions]; } #pragma mark Linking delegate methods -- (BOOL)application:(UIApplication *)application -continueUserActivity:(NSUserActivity *)userActivity - restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler { +- (BOOL)application:(UIApplication *)application + continueUserActivity:(NSUserActivity *)userActivity + restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler { return [JitsiMeetView application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; diff --git a/ios/sdk/src/JitsiMeetView.h b/ios/sdk/src/JitsiMeetView.h index e9b330338f..685dcc52bc 100644 --- a/ios/sdk/src/JitsiMeetView.h +++ b/ios/sdk/src/JitsiMeetView.h @@ -25,6 +25,9 @@ @property (nonatomic) BOOL welcomePageEnabled; ++ (BOOL)application:(UIApplication *_Nonnull)application + didFinishLaunchingWithOptions:(NSDictionary *_Nonnull)launchOptions; + + (BOOL)application:(UIApplication * _Nonnull)application continueUserActivity:(NSUserActivity * _Nonnull)userActivity restorationHandler:(void (^ _Nullable)(NSArray * _Nullable))restorationHandler; diff --git a/ios/sdk/src/JitsiMeetView.m b/ios/sdk/src/JitsiMeetView.m index eed5dd8bfa..1f89300ad6 100644 --- a/ios/sdk/src/JitsiMeetView.m +++ b/ios/sdk/src/JitsiMeetView.m @@ -35,7 +35,8 @@ RCTFatalHandler _RCTFatal = ^(NSError *error) { @try { NSString *name = [NSString stringWithFormat:@"%@: %@", - RCTFatalExceptionName, error.localizedDescription]; + RCTFatalExceptionName, + error.localizedDescription]; NSString *message = RCTFormatError(error.localizedDescription, jsStackTrace, 75); [NSException raise:name format:@"%@", message]; @@ -110,12 +111,27 @@ void registerFatalErrorHandler() { static RCTBridgeWrapper *bridgeWrapper; +/** + * Copy of the {@code launchOptions} dictionary that the application was started + * with. It is required for the initial URL to be used if a (Universal) link was + * used to launch a new instance of the application. + */ +static NSDictionary *_launchOptions; + /** * The {@code JitsiMeetView}s associated with their {@code ExternalAPI} scopes * (i.e. unique identifiers within the process). */ static NSMapTable *views; ++ (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Store launch options, will be used when we create the bridge. + _launchOptions = [launchOptions copy]; + + return YES; +} + #pragma mark Linking delegate helpers // https://facebook.github.io/react-native/docs/linking.html @@ -201,7 +217,7 @@ static NSMapTable *views; /** * Internal initialization: * - * - sets the backgroudn color + * - sets the background color * - creates the React bridge * - loads the necessary custom fonts * - registers a custom fatal error error handler for React @@ -211,7 +227,8 @@ static NSMapTable *views; dispatch_once(&dispatchOncePredicate, ^{ // Initialize the static state of JitsiMeetView. - bridgeWrapper = [[RCTBridgeWrapper alloc] init]; + bridgeWrapper + = [[RCTBridgeWrapper alloc] initWithLaunchOptions:_launchOptions]; views = [NSMapTable strongToWeakObjectsMapTable]; // Dynamically load custom bundled fonts. diff --git a/ios/sdk/src/RCTBridgeWrapper.h b/ios/sdk/src/RCTBridgeWrapper.h index f201281505..8e599124d7 100644 --- a/ios/sdk/src/RCTBridgeWrapper.h +++ b/ios/sdk/src/RCTBridgeWrapper.h @@ -34,4 +34,6 @@ @property (nonatomic, readonly, strong) RCTBridge *bridge; +- (instancetype)initWithLaunchOptions:(NSDictionary *)launchOptions; + @end diff --git a/ios/sdk/src/RCTBridgeWrapper.m b/ios/sdk/src/RCTBridgeWrapper.m index 052bb81107..4fc5b03aa4 100644 --- a/ios/sdk/src/RCTBridgeWrapper.m +++ b/ios/sdk/src/RCTBridgeWrapper.m @@ -22,10 +22,12 @@ */ @implementation RCTBridgeWrapper -- (instancetype)init { +- (instancetype)initWithLaunchOptions:(NSDictionary *)launchOptions { self = [super init]; if (self) { - _bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil]; + _bridge + = [[RCTBridge alloc] initWithDelegate:self + launchOptions:launchOptions]; } return self;