[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.
This commit is contained in:
Saúl Ibarra Corretgé 2017-07-03 11:37:37 +02:00 committed by Lyubo Marinov
parent 814d56c25c
commit 99b856233d
5 changed files with 34 additions and 9 deletions

View File

@ -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];

View File

@ -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;

View File

@ -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<NSString *, JitsiMeetView *> *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<NSString *, JitsiMeetView *> *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<NSString *, JitsiMeetView *> *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.

View File

@ -34,4 +34,6 @@
@property (nonatomic, readonly, strong) RCTBridge *bridge;
- (instancetype)initWithLaunchOptions:(NSDictionary *)launchOptions;
@end

View File

@ -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;