diff --git a/plugin.xml b/plugin.xml index 7bf5330..bdbb08d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -91,6 +91,8 @@ + + diff --git a/src/ios/AppDelegate+IonicDeeplink.m b/src/ios/AppDelegate+IonicDeeplink.m index 4a953c5..1e1713e 100644 --- a/src/ios/AppDelegate+IonicDeeplink.m +++ b/src/ios/AppDelegate+IonicDeeplink.m @@ -1,5 +1,6 @@ #import "AppDelegate.h" #import "IonicDeeplinkPlugin.h" +#import "DeeplinkService.h" static NSString *const PLUGIN_NAME = @"IonicDeeplinkPlugin"; @@ -37,6 +38,7 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl IonicDeeplinkPlugin *plugin = [self.viewController getCommandInstance:PLUGIN_NAME]; if(plugin == nil) { + [DeeplinkService setLastURL:url]; NSLog(@"Unable to get instance of command plugin"); return NO; } @@ -72,6 +74,7 @@ - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserAct IonicDeeplinkPlugin *plugin = [self.viewController getCommandInstance:PLUGIN_NAME]; if(plugin == nil) { + [DeeplinkService setLastUserActivity:userActivity]; return NO; } diff --git a/src/ios/DeeplinkService.h b/src/ios/DeeplinkService.h new file mode 100644 index 0000000..ab23e7c --- /dev/null +++ b/src/ios/DeeplinkService.h @@ -0,0 +1,18 @@ +#ifndef DEEPLINK_SERVICE_H +#define DEEPLINK_SERVICE_H + +#import + +@interface DeeplinkService : NSObject + ++ (void)setLastURL:(NSURL*)url; ++ (NSURL*)getLastURL; ++ (void)clearLastURL; + ++ (void)setLastUserActivity:(NSUserActivity*)userActivity; ++ (NSUserActivity*)getLastUserActivity; ++ (void)clearLastUserActivity; + +@end + +#endif \ No newline at end of file diff --git a/src/ios/DeeplinkService.m b/src/ios/DeeplinkService.m new file mode 100644 index 0000000..827173c --- /dev/null +++ b/src/ios/DeeplinkService.m @@ -0,0 +1,69 @@ +#import "DeeplinkService.h" + +@implementation DeeplinkService + +static NSObject* deeplinkLocker; +static NSURL* lastURL = nil; +static NSUserActivity* lastUserActivity = nil; + +- (id) init +{ + self = [super init]; + + if (self) + { + deeplinkLocker = [[NSObject alloc] init]; + } + + return self; +} + ++ (void)setLastURL:(NSURL*)url +{ + @synchronized(deeplinkLocker) + { + lastURL = url; + } +} + ++ (NSURL*)getLastURL +{ + @synchronized(deeplinkLocker) + { + return lastURL; + } +} + ++ (void)clearLastURL +{ + @synchronized(deeplinkLocker) + { + lastURL = nil; + } +} + ++ (void)setLastUserActivity:(NSUserActivity*)userActivity +{ + @synchronized(deeplinkLocker) + { + lastUserActivity = userActivity; + } +} + ++ (NSUserActivity*)getLastUserActivity +{ + @synchronized(deeplinkLocker) + { + return lastUserActivity; + } +} + ++ (void)clearLastUserActivity +{ + @synchronized(deeplinkLocker) + { + lastUserActivity = nil; + } +} + +@end \ No newline at end of file diff --git a/src/ios/IonicDeeplinkPlugin.m b/src/ios/IonicDeeplinkPlugin.m index 4a22b46..186027f 100644 --- a/src/ios/IonicDeeplinkPlugin.m +++ b/src/ios/IonicDeeplinkPlugin.m @@ -1,11 +1,30 @@ #import "IonicDeeplinkPlugin.h" #import +#import "DeeplinkService.h" @implementation IonicDeeplinkPlugin - (void)pluginInitialize { _handlers = [[NSMutableArray alloc] init]; + + NSURL* lastURL = [DeeplinkService getLastURL]; + + if (lastURL != nil) + { + [self handleLink:lastURL]; + } + + [DeeplinkService clearLastURL]; + + NSUserActivity* lastUserActivity = [DeeplinkService getLastUserActivity]; + + if (lastUserActivity != nil) + { + [self handleContinueUserActivity:lastUserActivity]; + } + + [DeeplinkService clearLastUserActivity]; } /* ------------------------------------------------------------- */