ログインユーザー情報の取得
ユーザーがログイン状態になると、Kii Cloud SDK が保持しているログインユーザーを API によって取得できます。
ユーザーがログインすると、SDK は Kii Cloud からそのユーザーに対する アクセストークン を取得し、その他の関連情報とともに SDK 内部のスタティック領域に保持します。これは、SDK で「カレントユーザー」を保持していることを意味します。
現在ログイン中のユーザーは getCurrentUser
メソッドを用いて取得します。
-
// Get the currently logged-in user. KiiUser user = KiiUser.getCurrentUser(); try { // Refresh the user to get the latest user info from Kii Cloud. user.refresh(); } catch (IOException e) { // Handle the error. } catch (AppException e) { // Handle the error. }
-
// Get the currently logged-in user. KiiUser user = KiiUser.getCurrentUser(); // Refresh the user to get the latest user info from Kii Cloud. user.refresh(new KiiUserCallBack() { @Override public void onRefreshCompleted(int token, Exception exception) { if (exception != null) { // Handle the error. return; } } });
Kii Cloud よりユーザーの最新情報を取得するには refresh
メソッドを実行します。
getCurrentUser
メソッドが null を返した場合、ログインしていないことを意味します。
ログイン中のユーザーは 1 人しか保持できません。複数のユーザーを扱いたい場合は、別のユーザーでログインし直す必要があります。この場合、切り替え前のユーザーのログイン状態は失われます。