您需要使用适用于 iOS 的 FBSDK 来为 Facebook 好友列表发出图形请求。
我不太明白您是否要添加已在您的应用中注册或拥有 Facebook 帐户的“朋友”,但无论如何您都需要将您的用户存储在数据存储中,我相信 Parse 有 PFObject ,你可以这样保存:
var appUser = PFObject(className:"AppUser")
appUser["userFullName"] = "John Doe"
appUser["userFacebookID"] = 1
appUser["userEmail"] = "j.doe@doe.com"
appUser.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
从那里您需要将用户与“友谊”对象相关联,例如:
var userFriendship = PFObject(className:"Friendship")
appUser["invitedUserEmail"] = "jane.doe@doe.com"
appUser["invitingUserEmail"] = "j.doe@doe.com"
appUser["invitationStatus"] = "pending"
appUser.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
之后您可以更新对象以将邀请状态更改为“接受”或“拒绝”、“取消”等。
要获取用户邀请和好友列表,您需要使用您正在寻找的参数进行 ParseQuery,例如:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"invitingUserEmail = 'j.doe@doe.com' AND invitationStatus = 'accepted'"];
PFQuery *query = [PFQuery queryWithClassName:@"Friendship" predicate:predicate];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d friends.", objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
您可以在此处https://parse.com/docs/ios/guide 的 Parse 文档中找到更多信息