Ok this may seem like a duplicate but I've been through all of the questions that center around the issue and I still can't seem to get this to work for my app.
I have followed the iOS tutorial on the Facebook Developer site and I have done the following:
- Created a Facebook App to get the Facebook App ID.
- I've assigned this App ID to a constant and I use it to initialize the Facebook object within my app.
- I've made sure my app is flagged for multitasking
- I've setup the fbAPP_ID in the plist under the URLs drop down
- I've made my AppDelegate a FBSessionDelegate and implemented very simple fbDidLogin and fbDidNotLogin delegate methods.
Versions: XCode 4.3.2 on Lion, iOS 5.1, Facebook iOS 4.1.1
All of this and I still can't seem to get Facebook to return control back to my app when it authorizes. It just stays in Facebook instead.
Code: (Note FB_APP_ID changed to basic number for viewing here)
AppDelegate.h:
#import <UIKit/UIKit.h>
#import "FBConnect.h"
#define FB_APP_ID @"1234567890"
@interface AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) Facebook* facebook;
@end
AppDelegate.m:
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize facebook = _facebook;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_facebook = [[Facebook alloc] initWithAppId:FB_APP_ID andDelegate:self];
if (![_facebook isSessionValid])
{
[_facebook authorize:nil];
}
}
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL *)url
{
return [_facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [_facebook handleOpenURL:url];
}
- (void)fbDidLogin
{
NSLog(@"App logged in");
}
- (void)fbDidNotLogin:(BOOL)cancelled
{
NSLog(@"App did not login");
}
@end
Relevant Info.plist porton:
Facebook App screen (mostly pinked out):
Note: I tried it with only basic settings and also with the iOS Native app settings with a fake iTunes store ID but the same bundle ID from my provisioning profile.
No matter what I do it always loads up Facebook and asks to authorize my app and then it simply closes the auth screen window and sits there on my Facebook screen instead of returning to my app.
Also note: I know it will always ask because I'm not checking for the auth token and expiration date.....that's the next step....for now I want to at least get it to return to my app before I worry about that.
Have I missed something here? Anything else I can try to get Facebook to return to my app?
EDIT: Also when debugging, I can't seem to find any spot where either openURL is called for some reason.
EDIT #2: When running it on the simulator, it loads up the FB Dialog via Safari (as expected) and then when I authorize, safari throws an error as if the URL they are trying to use to get back to my app is invalid:
This still doesn't tell me much since my fb1234567890 is setup right as far as I know in the Info.plist.
See Question&Answers more detail:
os