我正在努力在 Xcode 中将 Snapchat 登录集成到我的 iOS 应用程序中。这是我当前的代码,在我的视图控制器中实现 SCSDKLoginButton :(错误以注释突出显示)
import SCSDKLoginKit
var scLoginButton: SCSDKLoginButton!
let scLoginButton = SCSDKLoginButton()
scLoginButton.center = CGPoint(x: 200, y: 200)
view.addSubview(scLoginButton)
@IBAction func loginButtonTapped(_ sender: Any) {
SCSDKLoginClient.login(from: self, completion: { success, error in
if let error = error {
print(error.localizedDescription)
return
}
if success {
self.fetchSnapUserInfo()
}
})
}
private func fetchSnapUserInfo(){
let graphQLQuery = "{me{displayName, bitmoji{avatar}}}"
SCSDKLoginClient
.fetchUserData(
withQuery: graphQLQuery,
variables: nil,
success: { userInfo in
if let userInfo = userInfo,
let data = try? JSONSerialization.data(withJSONObject: userInfo, options: .prettyPrinted),
let userEntity = try? JSONDecoder().decode(UserEntity.self, from: data) { // ERROR HERE
DispatchQueue.main.async {
self.goToLoginConfirm(userEntity)
}
}
}) { (error, isUserLoggedOut) in
print(error?.localizedDescription ?? "")
}
}
在添加“// ERROR HERE”的行上,我不断收到错误“使用未解析的标识符'UserEntity'”。我直接从 Snapchat LoginKit 教程中复制并粘贴了该方法,但我不知道如何修复它。很感谢任何形式的帮助 :))
(顺便说一句,我的 AppDelegate 和 info.plist 文件已经实现了所需的代码)