I wrote as follows.
An error occurred on line 14 because of forced unwrapping.
I fixed it by rewriting as below, but I would like to know why nil is included in identityToken or authorizationCode.
An error occurred on line 14 because of forced unwrapping.
Code Block extension SignInViewController: ASAuthorizationControllerDelegate { @available(iOS 13.0, *) func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { var name: String? = nil if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { if let fname = appleIDCredential.fullName?.familyName { name = fname } if let gname = appleIDCredential.fullName?.givenName {name = name == nil ? gname : name!+gname} authenticateWithApple(token: appleIDCredential.identityToken?.toString, code: appleIDCredential.authorizationCode?.toString, name: name) } } func authenticateWithApple(token: String?, code: String?, name: String?) { authenticationScenario.signOut(from: .apple) let param = [LQAAccountAppleTokenKey:token!, LQAAccountAppleAuthorizationCode:code!] ... } }
I fixed it by rewriting as below, but I would like to know why nil is included in identityToken or authorizationCode.
Code Block guard let identityToken = appleIDCredential.identityToken, let idTokenString = String(data: identityToken, encoding: .utf8) else { return } guard let authorizationCode = appleIDCredential.authorizationCode, let authCodeString = String(data: authorizationCode, encoding: .utf8) else { return }