我试图在用户通过Facebook登录我的应用程序后保存用户名和用户电子邮件。 我已经设置了一个segue来将信息从登录视图控制器传递到视图控制器,我计划将用户字符串和其他一些字符串保存到我的sqlite数据库中。 当我在目标视图控制器中运行我的应用程序并尝试将所有数据插入sqlite时,我抛出一个错误,说userName和userEmail是nil字符串,所以我的数据没有被保存。我已经正确设置了segue;合成,添加属性。但在我看来问题可能是我如何检索数据。非常感谢帮助!提前谢谢!
-(void)prepareForSegue:(UIStoryboardSegue *)segue user:(id<FBGraphUser>)user sender:(id)sender{
if([segue.identifier isEqualToString:@"loginInfo"]) {
NSString *name = user.name;
NSString *email = [user objectForKey:@"email"];
ViewController *vc = (ViewController *)[segue destinationViewController];
vc.userName = name;
vc.userEmail = email;
NSLog(@"user data is being prepared to segue");
}
}
答案 0 :(得分:0)
您使用过 - (void)prepareForSegue:(UIStoryboardSegue *)segue用户:(id)用户发件人:(id)发件人
在UIViewController类中没有用于segue展开的方法。而不是那个使用 -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"loginInfo"]) {
NSString *name = user.name;
NSString *email = [user objectForKey:@"email"];
ViewController *vc = (ViewController *)[segue destinationViewController];
vc.userName = name;
vc.userEmail = email;
NSLog(@"user data %@, email %@",name,email);
}
}
获取实现facebook委托所需的用户信息。
- (void)meRequestResult:(id)result WithError:(NSError *)error
{
NSLog(@"result %@",result );
if ([result isKindOfClass:[NSDictionary class]])
{
NSDictionary *dictionary;
if([result objectForKey:@"data"])
dictionary = (NSDictionary *)[(NSArray *)[result objectForKey:@"data"] objectAtIndex:0];
else
dictionary = (NSDictionary *)result;
email = [dictionary valueForKey:@"email"];
fName = [dictionary valueForKey:@"first_name"];
lName = [dictionary valueForKey:@"last_name"];
}
}