ログインユーザー情報の取得
ユーザーがログイン状態になると、Kii Cloud SDK が保持しているログインユーザーを API によって取得できます。
ユーザーがログインすると、SDK は Kii Cloud からそのユーザーに対する アクセストークン を取得し、その他の関連情報とともに SDK 内部のスタティック領域に保持します。これは、SDK で「カレントユーザー」を保持していることを意味します。
現在ログイン中のユーザーは currentUser
メソッドを用いて取得します。
Swift:
-
// Get the currently logged-in user. let user = KiiUser.current() do { // Refresh the user to get the latest user info from Kii Cloud. try user?.refreshSynchronous() } catch let error as NSError { // Handle the error. return }
-
// Get the currently logged-in user. let user = KiiUser.current() // Refresh the user to get the latest user info from Kii Cloud. user?.refresh { (user :KiiUser?, error : Error?) -> Void in if error != nil { // Handle the error. return } }
Objective-C:
-
// Get the currently logged-in user. KiiUser *user = [KiiUser currentUser]; NSError *error = nil; // Refresh the user to get the latest user info from Kii Cloud. [user refreshSynchronous:&error]; if (error != nil) { // Handle the error. return; }
-
// Get the currently logged-in user. KiiUser *user = [KiiUser currentUser]; // Refresh the user to get the latest user info from Kii Cloud. [user refreshWithBlock:^(KiiUser *user, NSError *error) { if (error != nil) { // Handle the error. return; } }];
Kii Cloud よりユーザーの最新情報を取得するには refreshSynchronous
メソッドを実行します。
currentUser
メソッドが nil を返した場合、ログインしていないことを意味します。
ログイン中のユーザーは 1 人しか保持できません。複数のユーザーを扱いたい場合は、別のユーザーでログインし直す必要があります。この場合、切り替え前のユーザーのログイン状態は失われます。