application(:open:options:)' 几乎符合可选要求

application(:open:options:)' nearly matches optional requirement

正在尝试从外部打开应用程序。这是我唯一缺少的部分:

Instance method 'application(:open:options:)' nearly matches optional requirement 'application(:open:options:)' of protocol 'UIApplicationDelegate'

在我的 App Delegate 中。

有 2 个建议的修复来消除警告:

将方法标记为私有 在方法中添加@nonobjc 要么使警告静音。但为什么需要这样做?

我的代码:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    let message = url.query?.removingPercentEncoding
    print(message)
    return true
}

你应该用这个函数替换你的函数:

func application(_ app: UIApplication, 
                 open url: URL, 
                 options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool