用户在惠普Facebook上歌唱我的应用后,我不会显示他的名字和个人资料照片,我从AppDelegate类获取数据并将其添加到视图中的属性(UserNameLable)控制器,在ios应用程序中显示facebook用户的详细信息
在AppDelegate中所有nslogs显示视图控制器nslogs数据
显示空
我如何能在大声对我在mainViewController属性的数据?
在AppDelegate中这是代码
AppDelegate.h
@property (retain, nonatomic) NSString *first_name_property;
AppDelegate.m
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
[[NSNotificationCenter defaultCenter]
postNotificationName:SCSessionStateChangedNotification
object:session];
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(@"error");
}
else
{
NSLog(@"FB user first name:%@",user.first_name);
NSLog(@"FB user last name:%@",user.last_name);
// Add the data to the property I crated
first_name_property = user.first_name;
}
}];
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
//这是在显示数据的代码我查看
mainViewController.h
@property (strong, nonatomic) IBOutlet UILabel *UserNameLable;
mainViewController.m
-(void)viewDidAppear:(BOOL)animated{
if (!UserNameLable) {
UserNameLable.text=((AppDelegate *)[UIApplication sharedApplication].delegate).first_name_property;
}
else{
[email protected]"not set";}
}
你在哪里加载mainViewController。在AppDelegate.m上设置first_name_property后,应该在sessionStateChanged上调用它。 mainViewController是facebook必须异步的地方。 – Shad