1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Sign in with Appleの注意点

Last updated at Posted at 2020-04-24

Sign In with Apple

実装は、公式サンプルコードを参照すれば比較的容易です。

「Appleでサインイン」によるユーザー認証の実装

注意点

何処かに記載があるのかもしれませんが、下記コード(公式サイトより引用)内のgetCredentialState()は、現時点のシミュレータ(version 11.4.1)では常に.notFoundを返すようです。動作確認は実機で実行する必要があります。

最初シミュレータでも.authorizedが返ってきていて、試行錯誤しているうちに動かなくなったように見えたのですが、このやり取りを読むと勘違いのようです。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let appleIDProvider = ASAuthorizationAppleIDProvider()
    appleIDProvider.getCredentialState(forUserID: KeychainItem.currentUserIdentifier) {(credentialState, error) in
        switch credentialState {
        case .authorized:
            break // The Apple ID credential is valid.
        case .revoked, .notFound:
            // The Apple ID credential is either revoked or was not found, so show the sign-in UI.
            DispatchQueue.main.async {
                self.window?.rootViewController?.showLoginViewController()
            }
        default:
            break
        }
    }
    return true
}
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?