authenticateUser method

Future<CKAuthState> authenticateUser(
  1. BuildContext? context
)

Open the "Sign-In to iCloud" webpage, if the stored ckAuthURL exists.

Implementation

Future<CKAuthState> authenticateUser(BuildContext? context) async
{
  if (context == null || _ckAuthURL == null) return CKAuthState.failure;

  final CKAuthCallback authCallback = await Navigator.push(context,
    MaterialPageRoute(builder: (context) =>
      CKAuthWebView(
        authenticationURL: _ckAuthURL!,
        redirectURLPattern: _redirectURLPattern
      )
    )
  );

  switch (authCallback.state)
  {
    case CKAuthState.success:
      _ckWebAuthToken = authCallback.authToken;
      await saveWebAuthToken();
      break;
    case CKAuthState.failure:
    case CKAuthState.cancel:
      break;
  }

  print(authCallback.state);

  return authCallback.state;
}