How to handle if app is opened from URL in didFinishLaunchingWithOptions method?

didfinishlaunchingwithoptions return false
launch options keys
app called -statusbar or -statusbarwindow on uiapplication
appdelegate didfinishlaunchingwithoptions
didfinishlaunchingwithoptions push notification launch options
didfinishlaunchingwithoptions objective-c example
when is application didfinishlaunchingwithoptions called
didfinishlaunchingwithoptions example

When iOS application is opened from some URL AppDelegates's methods are called in such a sequence:

1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

How to know in didFinishLaunchingWithOptions method if application was opened from URL or not. May be there are some launching options which I miss?

You can inspect launchOptions passed to - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions.

Look for section Launch Options Keys in reference docs, specifically UIApplicationLaunchOptionsURLKey

application:didFinishLaunchingWithOptions:, Parameters. application. Your singleton app object. url. A object representing a URL YES if the delegate successfully handled the request; NO if the attempt to of application:didFinishLaunchingWithOptions: , this method is called to open� If the application is designed to handle urls, it should lookup the LaunchOptionsUrlKey key in the launchOptions to extract the url that is being launched, and return true at the end of the method to indicate that the application is able to load that url, or false if it is not.

If your app has been launch from a URL You will find a

UIApplicationLaunchOptionsURLKey 

in the launchOptions Dictionary of - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

On a related note the handleOpenURL: method is deprecated, you should use:

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

application:handleOpenURL:, Only your app knows how to handle your custom URL scheme, and iOS And in your open URL method ( scene(_:openURLContexts:) if dictionary in application(_:didFinishLaunchingWithOptions:) under the UIApplication. The return result from this method is combined with the return result from the application(_: will Finish Launching With Options:) method to determine if a URL should be handled. If either method returns false, the URL is not handled. If you do not implement one of the methods, only the return value of the implemented method is considered.

First, you should implement application:didFinishLaunchingWithOptions: Check the URL. It should return YES if you can open it or NO if you can't.

And then implement application:handleOpenURL: Open the URL. It should return YES if successful or NO.

Handling deeplinks in your app – Donny Wals, In the Firebase console, open the Dynamic Links section. If your app is connected, the apple-app-site-association file contains a reference to instance, typically in your app's application:didFinishLaunchingWithOptions: method: ( iOS 9 and up) methods, handle links received through your app's custom URL scheme. For example the URL fb:// may open the Facebook app, to handle universal links in your app. app had opened by clicking a universal link or not in the didFinishLaunchingWithOptions method:

Actually answers about UIApplicationLaunchOptionsURLKey are correct but not complete. In case if user for example taps Universal Link in Messages app and is redirected into your app, you receive these launch options instead of UIApplicationLaunchOptionsURLKey:

[
    UIApplicationLaunchOptionsSourceApplicationKey: com.apple.MobileSMS,
    UIApplicationLaunchOptionsUserActivityDictionaryKey: [
         UIApplicationLaunchOptionsUserActivityKey: <NSUserActivity>,
         UIApplicationLaunchOptionsUserActivityTypeKey: NSUserActivityTypeBrowsingWeb
    ]
]

So, to check if user landed into the app from URL you need this code in this case:

let isFromUrl = ((launchOptions?[UIApplicationLaunchOptionsKey.userActivityDictionary] as? NSDictionary)?[UIApplicationLaunchOptionsKey.userActivityType] as? String == NSUserActivityTypeBrowsingWeb)

and if the check passes, handle incoming URL in:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        let url = userActivity.webpageURL
        // do your stuff ...
    }
return false
}

Receive Dynamic Links on iOS, Deep Links act the similar way, but it handles the custom URL schemes. are handled by AppDelegate didFinishLaunchingWithOptions method. To straighten the purpose of this article, when we open a specific app page,� Adjust your app's logic accordingly. Open Dynamic Links in your app. In the Info tab of your app's Xcode project, create a new URL type to be used for Dynamic Links. Set the Identifier field to a unique value and the URL scheme field to be your bundle identifier, which is the default URL scheme used by Dynamic Links.

iOS: How to open Deep Links, Notifications and Shortcuts, Apps can launch other apps by passing URLs: When an app is launched from an UIDocumentInteractionController or via AirDrop, the Since this introduces two separate code paths for notification handling, a common approach is to have application:didFinishLaunchingWithOptions: manually call� Apps can cooperatively handle a resource, such as an email or an image file, through the open URL(_:) method. For example, an app that calls this method with an email URL causes the Mail app to launch and display the message. The APIs in this class allow you to manage device-specific behavior. Use your UIApplication object to do the following:

UIApplicationDelegate launchOptions, Events. open url If the URL launches your app, you will get and didFinishLaunchingWithOptions: method calls so any code in those methods will work resources, and start the services you need to handle user requests. URLNavigator allows to map view controllers and URL open handlers with URL patterns. Here's an example of mapping URL patterns with view controllers and a closure. Each closures has three parameters: url, values and context. url is an URL that is passed from push() and present(). values is a dictionary that contains URL placeholder keys and values.

How to work with SceneDelegate in iOS 12, Displaying a Custom Launch Image When a URL is Opened 103 Relevant Chapter: The App Life Cycle (page 21), Strategies for Handling App application :didFinishLaunchingWithOptions:—This method allows you to perform any final. Before continue, let’s clarify the terms: Universal Links is the way to intercept some of the URL’s and instead of handling the URL in Safari, open a specific app page.Universal links require

Comments
  • Specifically the presence of the UIApplicationLaunchOptionsURLKey key