0

How to handle the deep link in iOS objective c when the app is suspended. If the app is in the background open url delegate will be calling so can handle the url there.

In which delegate method can handle the url when the app is launched from a deep link with custom url scheme and parameters.

Url is something like myapp://params?app_id=1234

Thanks in advance.

  • Are you already using this? https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application?language=objc – R4N Feb 10 '21 at 17:12
  • @R4N yes using the open url and did finish with launch options – Avinas Udayakumar Feb 10 '21 at 17:14
  • @R4N I can handle the url when app in background through the open url delegate. But how to handle when I open the suspended app through a deep link is it safe to handle in did finish launching options. Cuz I’m handling some deferred deep links as well from Facebook – Avinas Udayakumar Feb 10 '21 at 17:15

2 Answers2

2

I have implemented Firebase Dynamic Link in my project(Similar to deferred links from Facebook) and the following delegate helps to handle Universal Dynamic Links :

- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
#else
    (nonnull void (^)(NSArray *_Nullable))restorationHandler {
}

NSUserActivity Object will contain "webpageURL" that you are looking for.

Further, you can look for the below discussion to solve this :

Firebase Deeplink not calling application:continueUserActivity:restorationHandler function of AppDelegate in Swift 3

Girish K T
  • 73
  • 7
  • Thanks I’ll check on this. One more question so if the deep link is something like myapp://params?AD_NAME=testad means this delegate will handle the url once the app is launched ? – Avinas Udayakumar Feb 11 '21 at 07:02
  • Yeah, correct. This delegate will handle the deep link and also the URL can be parsed to get the associated params. – Girish K T Feb 11 '21 at 07:10
  • Thanks a lot for the answer – Avinas Udayakumar Feb 11 '21 at 07:11
  • Hi, I tried this delegate but it not getting called for my deep link when the app got launched. When the app is in background the open URL delegate works fine. But when I force close the app and try to open it via the deep link its not working. Any further setup do I have to do in this ? – Avinas Udayakumar Feb 11 '21 at 11:21
  • Have you tried the Answer from - https://stackoverflow.com/questions/46481509/firebase-deeplink-not-calling-applicationcontinueuseractivityrestorationhandle, for App kill and launch scenario ? – Girish K T Feb 11 '21 at 11:25
  • Yeah, I tried it but user activity not getting called. But I tried to get the URL when app launch via [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey]. Now i can handle the URL in did finish with lauching options. – Avinas Udayakumar Feb 11 '21 at 12:21
  • That should be fine with your requirement then and you should be handle deep links in both App background and killed state launch. – Girish K T Feb 11 '21 at 12:26
  • Yeah that correct. Thanks for the suggestions. – Avinas Udayakumar Feb 11 '21 at 12:27
0

I suspect your main logic expects - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options to be called.

I also suspect in your case it does not get called if the app has been killed.

The solution is simple - make sure you have both - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions and - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions and that they both return YES.

This will make iOS call - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options on app launch.

The_Falcon
  • 287
  • 1
  • 2
  • 10