ios - 解析Back4App iOS Swift“PFUser.logInWithAuthType(inBackground:苹果”)方法将任务返回为nil

标签 ios swift parse-platform oauth back4app

我正在尝试在我的iOS Swift应用中实现Apple Login。我已经有手动注册和Facebook登录。

我已经实现了Apple登录,并且每次都返回 TOKEN USER 时,效果很好。

但是,当我在“PFUser.logInWithAuthType(inBackground:apple”)方法中传递该方法时,此方法可以部分工作,有时它可以与任务返回值一起使用,并且在大多数情况下Parse会将任务返回为nil ,错误为“内部服务器错误”。

由Parse返回的错误消息是“内部服务器错误” ,在Parse中解释为错误而没有消息。我不认为代码一定存在问题,因为它可以部分工作,或者如果我这边出了问题,它应该返回错误消息。

不过,我不确定我是否正确执行此操作,请告诉我。提前致谢,


@available(iOS 13.0, *)
    func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
        switch authorization.credential {

            case let credentials as ASAuthorizationAppleIDCredential:

                let token = credentials.identityToken!
                let tokenString = String(data: token, encoding: .utf8)!
                let user = credentials.user

                print("TOKEN: \(tokenString)")
                print("USER: \(user)")

                if let _ = credentials.email, let _ = credentials.fullName {
                    track("Register New Account")
                    PFUser.logInWithAuthType(inBackground: "apple", authData: ["token":tokenString, "id": user]).continueWith { task -> Any? in
                        if ((task.error) != nil){
                            DispatchQueue.main.async {
                                self.hideHUD()
                                alert("Could not login.\nPlease try again.")
                                track("Error with parse login after SIWA: \(task.error!.localizedDescription)")
                            }
                            return task
                        }
                        self.fillAppleDetails(userObject: task.result!, credentials: credentials)
                        return nil
                    }
                } else {
                    track("SignIn with Existing Account")
                    PFUser.logInWithAuthType(inBackground: "apple", authData: ["token":tokenString, "id": user]).continueWith { task -> Any? in
                        if ((task.error) != nil) {
                            DispatchQueue.main.async {
                                self.hideHUD()
                                alert("Could not login.\nPlease try again.")
                                track("Error with parse login after SIWA: \(task.error!.localizedDescription)")
                            }
                            return task
                        }

                        let userObject = task.result

                        if userObject!.email == nil {
                            self.fillAppleDetails(userObject: task.result!, credentials: credentials)
                        } else {
                            DispatchQueue.main.async {
                                mustRefresh = true
                                self.navigationController?.popToRootViewController(animated: true)
                                self.delegate?.capital()
                            }
                        }

                        return nil
                    }
                }
                break

            default: break
        }
    }

最佳答案

这是Parse Back4App方面的错误。它已在Parse版本4.2.0中修复,该版本当前在Private Beta中。您可以邮寄给他们以获得访问权限。

关于ios - 解析Back4App iOS Swift“PFUser.logInWithAuthType(inBackground:苹果”)方法将任务返回为nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61172324/

相关文章:

php - 尝试使用 PHP Parse.com 查询日期之间

swift - 我可以在不在 swift 3.0 中创建导出的情况下访问标签或文本字段的文本吗?

ios - 初始化 UIView 子类属性如何影响 superview 的中心?

ios - 为什么我会收到带有 2 个不同字符串的 UIImageRepresentation 错误?

ios - 在 WatchOS 中使用 parse 准备行

ios - 在显示初始 View Controller 之前显示 View Controller

ios - ViewControllers 未针对 3.5 英寸屏幕调整大小

ios - Swift XCUI 字符串断言失败

ios - 具有 0 行的 UILabel 最初不显示全文

ios - 解析 Swift - 自定义登录警报 View 错误