メンバーユーザーの一覧取得
グループのオーナーとメンバーは、グループメンバーの一覧を getMemberList(_:)
メソッドにより取得できます。
返却される KiiUser
のインスンタンスは ID
のみを保持した不完全なインスタンスであることに注意してください。必要に応じて refreshSynchronous()
メソッドを実行して Kii Cloud よりユーザーの最新情報を取得してください。
なお、取得するユーザーとログイン中のユーザーが異なる場合、取得できる情報に制限があります。詳細は ユーザー属性 を参照してください。
グループメンバーの一覧を取得するサンプルコードを以下に示します。
Swift:
-
// Get a list of members of the group. guard let members = try? group.getMemberListSynchronous() as! [KiiUser] else{ // Handle the error. return } for user in members{ do{ // Refresh the member to retrieve the latest data from Kii Cloud. try user.refreshSynchronous() } catch let error as NSError { // Handle the error. return } // Do something. }
-
// Get a list of members of the group. group.getMemberList { (group, members, error) -> Void in if error != nil { // Handle the error. return } // Create a dispatch queue to which blocks can be submitted. let serialQueue = DispatchQueue(label: "com.kii.serial", attributes: []) for obj in members! { let user = obj as! KiiUser // Submit a block for asynchronous execution on the dispatch queue. serialQueue.async(execute: { do{ // Refresh the member to retrieve the latest data from Kii Cloud. try user.refreshSynchronous() } catch let error as NSError { // Handle the error. return } // Do something. }) } }
Objective-C:
-
NSError *error; // Get a list of members of the group. NSArray *members = [group getMemberListSynchronous:&error]; if (error != nil) { // Handle the error. return; } for (KiiUser *user in members) { // Refresh the member to retrieve the latest data from Kii Cloud. [user refreshSynchronous:&error]; if (error != nil) { // Handle the error. return; } // Do something. }
-
// Get a list of members of the group. [group getMemberListWithBlock:^(KiiGroup *group, NSArray *members, NSError *error) { if (error != nil) { // Handle the error. return; } // Create a dispatch queue to which blocks can be submitted. dispatch_queue_t serialQueue = dispatch_queue_create("com.kii.serial", DISPATCH_QUEUE_SERIAL); for (KiiUser *user in members) { // Submit a block for asynchronous execution on the dispatch queue. dispatch_async(serialQueue, ^{ // Refresh the member to retrieve the latest data from Kii Cloud. [user refreshSynchronous:&error]; if (error != nil) { // Handle the error. return; } // Do something. }); } }];