Swift:打开时的方案URL通知不起作用

时间:2018-09-04 08:23:55

标签: swift nsnotifications uiapplication notificationcenter

我使用以下代码:

  

AppDelegate:

var scheme: String!
var path: String!
var query: String!

func application(_ application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?)-> Bool {
    print("S0#: \(url.scheme)")
    print("S1#: \(url.path)")
    print("S2#: \(url.query)")

    scheme = url.scheme
    path = url.path
    query = url.query

    return true
}
  

ViewController:

override func viewDidLoad() {
    super.viewDidLoad()

    NotificationCenter.default.addObserver(
        self,
        selector: #selector(displayLaunchDetails(sender:)),
        name: NSNotification.Name.UIApplicationDidBecomeActive,
        object: nil)
}

@objc func displayLaunchDetails(sender: UITapGestureRecognizer) {
    var appDelegate = UIApplication.shared.delegate as! AppDelegate
    print("S: NO")
    if appDelegate.scheme != nil {
        print("S0: \(appDelegate.scheme)")
        print("S1: \(appDelegate.path)")
        print("S2: \(appDelegate.query)")
    }
}

deinit {
    NotificationCenter.default.removeObserver(
        self,
        name: NSNotification.Name.UIApplicationDidBecomeActive,
        object: nil)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

如果我在浏览器中打开openUrlAfterBack://,则我的应用程序将打开并仅打印S: NO

其他数据未提供且未打印

info.plist中,我添加了方案和标识符

我从https://kitefaster.com/2016/07/13/how-to-open-ios-app-with-custom-url/中学到了

我该如何解决?

0 个答案:

没有答案