I am working on adding facebook SSO and the SDK to my project. All of my main facebook code is in my AppDelegate.m
and AppDelegate.h
.
In my view controller [[[UIApplication sharedApplication] delegate] performSelector:@selector(callLogin)];
is called when I press a button.
The callLogin method in my AppDelegate.m
looks like this:
- (void)callLogin{
facebook = [[Facebook alloc] initWithAppId:@"XXXXX" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
[facebook authorize:nil];
}
}
Then in my - (void)fbDidLogin
method I call the method setInfo
which is located in my viewcontroller.
//this method is located in AppDelegate.m
- (void)fbDidLogin {
NSLog(@"FACEBOOK DID LOGIN");
ViewController * vc = [[ViewController alloc]init];
[vc setInfo];
}
Finally, here is my -(void)setInfo
code which is located in ViewController.m
-(void)setInfo{
infoL.text = [NSString stringWithFormat: @"Connected to Facebook!"];
NSLog(@"%@",infoL);
//NSLog returns null
}
From setInfo I am unable to change the label and NSLog returns that infoL
is null. I can update the label through methods like ViewDidLoad, but not setInfo.
What am I doing wrong and how can I fix this?