My app is successfully opening and setting the parameters (from URL-scheme i.e. myApp://sometextToPrint) to a variable in the AppDelegate
class but whenever I w
Copy your code from
func application(_ app: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:])
-> Bool {
into
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
-> Bool {
In that method, check the launchOptions
. If it contains the url
key, grab that value — and return false
.
if let url = launchOptions[.url] as? URL {
let geturl = url.host?.removingPercentEncoding
UserDefaults.standard.set(geturl, forKey: "DeepLinkUrl")
return false
}
@SalihanPamuk I think this is due to the appWillEnterForeground()
method. UIApplication.willEnterForegroundNotification
- This is the first notification posting an app is coming to the foreground.
As you have already registered an observer for listening to this notification the appWillEnterForeground()
method will invoke before the appDelegate's
application(_ app: UIApplication, open url: URL, options:
[UIApplication.OpenURLOptionsKey : Any] = [:]) - method.
Try implementing the appDelegate's
func applicationWillEnterForeground(_ application: UIApplication) {
// Do your stuffs here
}
Or if you want to show any particular ViewController after opening the app using any URL setup the code for showing that ViewController inside the
func application(_ app: UIApplication, open url: URL, options:
[UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// implemet your code here
}