Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Fix for when app has a UINavigationController #153

Open
wants to merge 3 commits into
base: master
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
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
<source-file src="src/ios/AppDelegate+IonicDeeplink.m" />
<header-file src="src/ios/IonicDeeplinkPlugin.h" />
<source-file src="src/ios/IonicDeeplinkPlugin.m" />
<header-file src="src/ios/DeeplinkService.h" />
<source-file src="src/ios/DeeplinkService.m" />
</platform>

<platform name="browser">
Expand Down
3 changes: 3 additions & 0 deletions src/ios/AppDelegate+IonicDeeplink.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "AppDelegate.h"
#import "IonicDeeplinkPlugin.h"
#import "DeeplinkService.h"

static NSString *const PLUGIN_NAME = @"IonicDeeplinkPlugin";

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
18 changes: 18 additions & 0 deletions src/ios/DeeplinkService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef DEEPLINK_SERVICE_H
#define DEEPLINK_SERVICE_H

#import <Foundation/Foundation.h>

@interface DeeplinkService : NSObject

+ (void)setLastURL:(NSURL*)url;
+ (NSURL*)getLastURL;
+ (void)clearLastURL;

+ (void)setLastUserActivity:(NSUserActivity*)userActivity;
+ (NSUserActivity*)getLastUserActivity;
+ (void)clearLastUserActivity;

@end

#endif
69 changes: 69 additions & 0 deletions src/ios/DeeplinkService.m
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions src/ios/IonicDeeplinkPlugin.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
#import "IonicDeeplinkPlugin.h"

#import <Cordova/CDVAvailability.h>
#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];
}

/* ------------------------------------------------------------- */
Expand Down