SceneDelegate - 调用 'flatMap' 的结果未使用

SceneDelegate - Result of call to 'flatMap' is unused

大家好,我正在与 Firebase authentication 合作,我允许用户使用他的电子邮件和验证 [= =31=] 发送到他的电子邮箱...

一切正常,但 iOS 13 我必须使用 SceneDelegate 而不是 AppDelegate 并且在 func scene method (_ scene: UIScene, continue userActivity: NSUserActivity ) 我收到一条警告,警告我我没有调用 flatMap 调用的结果。

谁能帮我解决这个警报?

Result of call to 'flatMap' is unused

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
     userActivity.webpageURL.flatMap(handlePasswordlessSignIn)
}

func handlePasswordlessSignIn(withURL: URL) -> Bool {
    let link = withURL.absoluteString

    if Auth.auth().isSignIn(withEmailLink: link) {

        guard let email = UserDefaults.standard.value(forKey: FirebaseUserAuthWithLink.email) as? String else {
            print("L'email utilizzata per accedere non esiste")
            return true
        }

        Auth.auth().signIn(withEmail: email, link: link) { (user, error) in
            if let error = error {
                print(error.localizedDescription)
                return
            }

            guard let user = user else {
                print(" Authentication con Link Fallita")
                return
            }
            let uid = user.user.uid
            print("Autenticazione Riuscita")

            let data = [
                "email" : email
            ] as [String : Any]

            Firestore.firestore().collection("Users").document(uid).setData(data) { (error) in
                if let error = error {
                    print(error.localizedDescription)
                    return
                }
            }
        }
        return true
    }
    return false
}

按照教程的实现,队列的所有示例都引用了 AppDelegate 而不是我尝试更新在 SceneDelegate 上工作的代码

你可以这样重写:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    if let url = userActivity.webpageURL {
        handlePasswordlessSignIn(withURL:url)
    }
}

但是你会仍然被投诉,因为现在你忽略了handlePasswordlessSignIn的结果!您可以通过将 handlePasswordlessSignIn 指定为 @discardableResult:

来解决该问题
@discardableResult
func handlePasswordlessSignIn( //...