I'm trying to implement Apple Login in my iOS Swift App. I already have manual signup and Facebook login.
I have implemented apple login, and it works fine as it returns the TOKEN and USER each time.
But when I pass it in "PFUser.logInWithAuthType(inBackground: apple" method, this works partially, sometimes it works fine with task returning value and other most of the time Parse returns task as nil, with error "internal server error".
The error message returned by Parse is "internal server error", which in Parse explains as Error without a message. I don't think there must be problem with code as it works partial times or it should've returned error message if something is wrong from my side.
Still I'm not sure am I doing this right, please let me know. Thanks in advance,
@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
}
}
This is an error on Parse Back4App's side. It has been fixed in Parse Version 4.2.0, which is currently in Private Beta. You can mail them to get access.