在iOS中本地存储Facebook用户数据

时间:2014-02-08 14:32:11

标签: ios facebook sdk

我有两个与iOS和Facebook API相关的问题。

1)当用户点击登录btn获取用户数据时,如何自定义facebook登录视图。

2)在我的应用程序中,我想使用facebook API。通过这种方式,我可以在下面的方法中检索用户数据。但是如何在我的应用程序本地保存这些用户数据。

非常感谢您的帮助!!!

[FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
                                   allowLoginUI:YES
                              completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

                                  switch (state) {
                                      case FBSessionStateOpen:
                                          [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error){


                                              if (error) {


                                                  NSLog(@"error:%@",error);


                                              }
                                              else
                                              {

                                                  // retrive user's details at here as shown below
                                                  NSLog(@"FB user first name:%@",user.first_name);
                                                  NSLog(@"FB user last name:%@",user.last_name);
                                                  NSLog(@"FB user birthday:%@",user.birthday);
                                                  NSLog(@"FB user location:%@",user.location);
                                                  NSLog(@"FB user username:%@",user.username);
                                                  NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
                                                  NSLog(@"email id:%@",[user objectForKey:@"email"]);
                                                  NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
                                                                         user.location[@"name"]]);

self.fbUserDataDict = [NSDictionary dictionaryWithDictionary:user];

                                              }
                                          }];
                                          break;

                                      case FBSessionStateClosed:
                                      case FBSessionStateClosedLoginFailed:
                                          [FBSession.activeSession closeAndClearTokenInformation];
                                          break;

                                      default:

                                          break;
                                  }
                              } ];

1 个答案:

答案 0 :(得分:0)

如何使用Parse之类的东西在本地存储它们?您也可以使用SQLite。虽然您是否介意扩展一下您想做什么?只需将它们存储在本地?