I am new to iOS development. I run into a problem where fbDidLogin is not being called when integrating the facebook API in my app. Everything works perfectly when i call the API from the main view controller (meaning, the one that the app delegate calls), but in my case, its under the settings view controller. I literally copy pasted the code from the main view controller (where it worked) to the setting view controller, where it doesnt work.
I did add this method to the app delegate which I understand is the issue for most people, but in my case, i think the problem is elsewhere…any help would be awesome.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[settingsvc facebook] handleOpenURL:url];
}
Where in the app delegate header:
@property (strong, nonatomic) Settings *settingsvc;
A couple things.
-You only need to implement fbDidLogin in one spot in your entire application. You do not implement it on each view controller that uses facebook.
-Assuming you followed the Getting Started steps from Facebook’s iOS documentation, your Facebook object lives as a property of your app delegate. And your fbDidLogin method is only in your app delegate. This should also be the only spot in your code that declares the Facebook variable. That means that whenever you access facebook from anywhere else in your code, you do something like this:
-Your handleOpenURL and openURL methods in your app delegate should look exactly like in the sample documentation from Facebook, not like the code you posted.
-Personally I prefer to move the Facebook object out of the app delegate into a singleton helper class, but if you are a beginner then this is probably more advanced than you need.
UPDATED INFORMATION ANSWERING COMMENTS:
-someMethod is whatever Facebook method you are looking to call (post on the wall, authenticate, whatever)
-You should put all FBSessionDelegate methods in your app delegate
-You need to implement FBDialogDelegate on your view controller where you post to Facebook
-Then in your view controller when you want to post to the user’s wall do something like this:
-For the above to work, you need to post the NSNotificationCenter message “FBLoginComplete” whenever a login completes (success or fail).
-Note: I wrote the above code without compiling it or testing it so it may not be perfect (but it usually is 🙂
-Please note: you CANNOT post to a user’s wall directly without the dailog being popped up. The user always has the ability to edit the post before it hits their wall.