this is my first time posting as I usually just come by to do research for issues, but this one I cannot figure out myself.
Basically my problem is similar to other developers using the facebook sdk for iOS, my fbDidLogin function never gets called even after I log in and can make my posts to feed successfully. I looked at the other threads here such as fbDidLogin never called (facebook-ios-sdk) and fbDidLogin not called, however I haven’t been successful. My app has a main view that is loaded and upon button press it pulls in the second nib and replaces the view. That second view controller has the facebook functionality in there, and I feel like my issue might be connecting from the Appdelegate to that secondViewController. I noticed in the sample app that everything is set up in the appdelegate but that is not the way my program functions.
I’m new to objective c programming but I’ve been fine in terms of building some apps so far, just this facebook sdk is killing me.
I appreciate any direction people could throw at me. Thank you.
Here’s some of the code:
- (void)login {
facebook=[[Facebook alloc]initWithAppId:FB_APP_ID];
NSLog(@"Inside login/post to wall function.");
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"mystuff",@"test",
@"mystuff", @"link",
@"mystuff", @"picture",
mystuff, @"name",
@"mystuff", @"caption",
@"mystuff", @"description",
@"mystuff", @"message",
nil];
[facebook dialog:@"feed" andParams:params andDelegate:self];
}
/**
* Invalidate the access token and clear the cookie.
*/
- (void)logout {
[facebook logout:self];
}
/**
* Called when the user has logged in successfully.
*/
-(void)fbDidLogin{
NSLog(@"Inside fbDidLogin function.");
}
/**
* Called when the user canceled the authorization dialog.
*/
-(void)fbDidNotLogin:(BOOL)cancelled {
NSLog(@"User did not login.");
}
The issue here is that your delegate isn’t around anymore once the authorization process completes. I would create a class that implements FBSessionDelegate and keep it as a property on your application delegate. Now, when you wire up the delegate, set it to that property. You can also wire this up using interface builder if you would like. Simply set the delegate to that property that you defined on the app delegate.
For example, you could have a class that does the following (this code covers 80% of it – hopefully it gets you on the right track):
And the implementation would be:
You would need to define this class as a property on your application delegate:
Now, whenever you need your FacebookController, you simply can do this: