Application Openurl in Swift

application openURL in Swift

This is fairly typical of a signature mismatch between the method signatures automatically generated by the Swift compiler and the actual signature. It happens when you try to pass nil from Objective-C into a Swift explicitly unwrapped optional. Change the annotation parameter to be implicitly unwrapped and you should be gtg.

Method 'application:openURL:options:' is not called

Implement scene(_:openURLContexts:) in your scene delegate.

If the URL launches your app, you will get scene(_:willConnectTo:options:) instead and it’s in the options.

How to open an URL in Swift?

All you need is:

guard let url = URL(string: "http://www.google.com") else {
return //be safe
}

if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}

application:openUrl:options not called when opening app from share sheet of another app

If your app is using scenes, then instead of application(_:open:options:) from UIApplicationDelegate protocol, iOS will call scene(_:openURLContexts:) from UISceneDelegate.

https://developer.apple.com/documentation/uikit/uiscenedelegate/3238059-scene

Also probably it's better to change com.pkware.Zip-archive to com.pkware.zip-archive as it's defined as lowercase in the list of System-Declared UTIs

How to debug iOS App when opened from TodayExtension with openUrl?

1) Override an initializer in your App Delegate, and add there sleep call.

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

override init() {
sleep(10000)
}
...
}

2) Install this app on your device or simulator.

3) Put a breakpoint in your code.

4) From the extension, trigger the deeplink.

5) While app is opened and in sleep, connect your Xcode debugger to your app via Xcode app menu (Debug->Attach To Process->< your app name >). This will instantly wake up your app and it will fall into the breakpoint immediately.



Related Topics



Leave a reply



Submit