iPhone Facebook SDK Login Problem - iphone

Hey guys
I just tried to implement the facebook sdk like in the DemoApp from Facebook itself into my application. I basically copied everything from the demoApp but I have a problem when I try to login to facebook.
I press the login button and then the facebook app opens. I authorize myself and press OK. Then I am redirected to my app, but then the fbDidLogin() method gets not called. I also defined my app ID in my view controller and the url schema in the info file.
Am I missing something?
Thanks,
Cheers,
Doonot

fbDidLogin() isn't an Objective C method. Is that the way you have it in the code?
Have you handled your custom URL scheme in your app delegate?

Ok after some trying I figured it out. I used the Interface Builder to set up my Tab Bar Application. I had to change the tab bar application to programmatically in order to have a reference to the view controller which implements the facebook login method:
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
settingsController = [[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil];
...
As Jim mentioned, I forgot to implement the custom url scheme in my app delegate. Thanks to the settingsViewController I simply added:
// this method is needed by the facebook login procedure
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[settingsController facebook] handleOpenURL:url];
}
That's it, after these changes I can finally login to facebook.
Cheers,
Doonot

Related

Where should I implement my facebook ios sdk code in my Cocos2d Application?

I am attempting to add facebook integration to my ios game built using Cocos2D. I initially just made the CCLayer object (subclass of NSObject) a FBRequestDelegate, FBDialogDelegate, and FBSessionDelegate. Then I created a facebook object with
fb_permissions = [[NSArray arrayWithObjects:
#"read_stream", #"publish_stream", #"offline_access",nil] retain];
facebook = [[Facebook alloc] initWithAppId:kAppId
andDelegate:self];
next I call
[facebook authorize:fb_permissions];
when the user pushes a button. It all works fine, goes to the facebook login page, correctly authorizes my application etc. Once it returns execution to my game, I expected the
- (void)fbDidLogin
method to be called, but it doesn't seem to be. I'm a little confused and just wondering if I've gone about this wrong? Should I implement my facebook sdk stuff in my root viewcontroller? ie. make my viewcontroller the FB delegate?
Is it that I'm missing a call to handleOpenURL? Which appears to be depracated? I'm having trouble locating decent documentation on this particular issue...
thanks!!
I think you will need to implement handleOpenURL in your App Delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
Edit: I see that execution returns to your game, so you may have already completed the following:
You will also need to edit your .plist file to handle the return from the authorization page. You will add an entry to MyApp-info.plist under
Information Property List->URL Types->Item 0->URL Schemes->Item 0 = "fbYOUR_APP_ID"
Follow the instructions at the end of Step 6 here: http://developers.facebook.com/docs/guides/mobile/#ios

FBConnect's handleOpenURL Method Not Called by my AppDelegate

I have implemented the FBConnect SDK into my app, and it works perfectly on the simulator. I then modified my app's .plist file appropriately, and added the necessary method to my AppDelegate for when Facebook is installed on the device:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(#"handleOpenURL Method was called and sent the following:");
NSString *urlString = [NSString stringWithContentsOfURL:(NSURL *)url];
NSLog(#"URL String: %#", urlString);
return [[flipsideViewController facebook] handleOpenURL:url];
}
From the above NSLogs and the observation that my application is returned to the foreground after authorizing access via Facebook, I infer that the FB App is handing off control to my application appropriately. Unfortunately, Facebook.m's "handleOpenURL:url" method does not actually get called as I request in my AppDelegate (i.e. neither of the below NSLogs are displayed).
- (BOOL)handleOpenURL:(NSURL *)url {
// If the URL's structure doesn't match the structure used for Facebook authorization, abort.
NSLog(#"handleOpenURL was handled by SDK. Good!");
if (![[url absoluteString] hasPrefix:[self getOwnBaseUrl]]) {
NSLog(#"handleOpenURL structure doesn't match the structure used for Facebook authorization. Aborting.");
return NO;
}
//...
As a result, my app's view controller (where I clicked my facebook button to begin with) is simply returned to the screen, and the code I placed in the 'fbDidLogin' method (used in my view controller to publish to the user's wall) never gets called as it did in the simulator.
What am I overlooking? What, if any, other information is needed to solve this problem? Any help would be very much appreciated, as I have been struggling with this for a while.
Important Summary Notes:
1.) Application runs as desired on simulator.
2.) handleOpenURL Method not called when I request it from my AppDelegate.
3.) I do not receive any errors/warnings.
4.) I can run the DemoApp on my device, and I notice that the handleOpenURL Method is called appropiately when requested by the 'DemoAppAppDelegate.'
Thanks in Advance!
I ended up having to make my facebook object a singleton (stored in the appDelegate). Not completely sure why this was necessary though, as I was not using the fb object in multiple viewControllers. Please comment if you know why this was necessary.
See the following links for more information:
handleOpenUrl and TabBar Application
Facebook SDK: Call from multiple viewControllers
Cocoa with Love: Singletons

UIApplication's openURL Crashes My App

I'm using UIApplication's openURL: method to open a website in Safari. When the user came back to the app (fast switching), it relaunched. It means that my app was quit instead of going to the background.
Does anyone have the same issue? Any ideas? Thank you in advance.
It may be possible that you need to retain the URL object. That was once the issue for me
make sure that you are using
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
in your appdelegate rather than
- (void)applicationDidFinishLaunching:(UIApplication *)application

iPhone app login issue

I have an iPhone application which I'm working on and so far i have created a login page for the application such that only the phone's user can access the application. The login works fine and the application works fine, but when i hit the home button, the app is "minimized". And if accessed again from the task switcher it doesn't prompt for a password.
What exactly would be the best way to go about getting the app to request a password. If it helps i use navigation controllers and i have one view dedicated for the login.
Thanks for the help.
Can't you check app activated in the appdelegate?
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self showLoginWindow];
}
You must be working on iOS4. When you hit on Home Button, your app goes into background mode, but still working. So next time, when you open it, it starts exactly from where you left it. Implement the
- (void)applicationDidBecomeActive:(UIApplication *)application
method, to check for login again. Or if you don't want the background processing at all, disable it or use following code
- (void)applicationDidEnterBackground:(UIApplication *)application {
exit(0);
}
EDIT -
Don't go for exit(0) approach, simply disable the background processing if you don't want it from info.plist file.
see this link
you need to prevent the app to load from background.

Facebook iOS problems callbacks etc

I integrated the facebook ios sdk into my application. When I first did this it was connected to my ONLY ViewController class. So it worked just like the demo. It also DID work. I was able to post to everything etc. My app delegate has the correct connect URL stuff in it etc..
The problem came when I changed my app to have a different main screen and the last screen has the facebook connection info. So now my App Delegate has the function:
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
SocialView *socialView = [[SocialView alloc] init];
return [[socialView facebook] handleOpenURL:url];
}
Due to this change my facebook variable is always null when returning from the login and the didLogin never gets called. I'm assuming this is because every time it returns the view is being recreated and the facebook var is re-inited as well.
What is a solution to this? Thanks for any and all help...
-d
Edit: Its worth noting that if I only had one view:
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [[viewController facebook] handleOpenURL:url];
}
works fine..
David, you are right. The solution you are showing allocate the alternative view controller each time the authentication is finished and the app is back from facebook-connect. This way nothing can be saved.
Here's what you should do:
assume your viewcontroller which handles facebook-connect is called facebookViewController, then the code you need is:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[viewController.facebookViewController facebook] handleOpenURL:url];
}
Try and let me know if you got it :)
Good Luck.