1. before iOS 13
AppDelegate.swift
// For earlier versions, use the URL Scheme to start the App when it is not started.
// Add application(app: open: options:) method, don't use this, iOS 10.3.1 test
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if letsechme = launchOptions? [UIApplicationLaunchOptionsKey.url] as? URL{
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
let alert = UIAlertController.init(title: "BBB", message: url.absoluteString, preferredStyle: .alert)
alert.addAction(UIAlertAction.init(title: "cancel", style: .cancel, handler: nil))
self.window? .rootViewController? .present(alert, animated:true, completion: nil)}// Move to openUrl for processing
// _ = self.application(application, open: sechme)}}Copy the code
// iOS 10.3.1 Active/Not active
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
let alert = UIAlertController.init(title: "AAA", message: url.absoluteString, preferredStyle: .alert)
alert.addAction(UIAlertAction.init(title: "cancel", style: .cancel, handler: nil))
self.window? .rootViewController? .present(alert, animated:true, completion: nil)}return true
}
Copy the code
After testing, only application(app: open: options:) method is used in iOS 10.3.1, which can deal with two cases of app being started and not being started.
Using both methods together, well, buggy, will be called. Try ๐คจ. Error welcome correction ๐.
2. The iOS 13.3
1. The App is not started
// iOS 13 not active
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if #available(iOS 13.0, *) {
guard let _ = (scene as? UIWindowScene) else { return }
for context in connectionOptions.urlContexts{
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
let alert = UIAlertController.init(title: "not active", message: context.url.absoluteString, preferredStyle: .alert)
alert.addAction(UIAlertAction.init(title: "cancel", style: .cancel, handler: nil))
self.window? .rootViewController? .present(alert, animated:true, completion: nil)}}}else {
// Fallback on earlier versions}}Copy the code
2. The App has been started
@available(iOS 13.0*),// iOS 13 active
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for context in URLContexts{
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
let alert = UIAlertController.init(title: "active", message: context.url.absoluteString, preferredStyle: .alert)
alert.addAction(UIAlertAction.init(title: "cancel", style: .cancel, handler: nil))
self.window? .rootViewController? .present(alert, animated:true, completion: nil)}}}Copy the code
For iOS13.3 testing, write local script for scene:openURLContexts: unified processing (๐)