Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

objective c - Native iOS Facebook SSO won't return to app

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:

  1. Created a Facebook App to get the Facebook App ID.
  2. I've assigned this App ID to a constant and I use it to initialize the Facebook object within my app.
  3. I've made sure my app is flagged for multitasking
  4. I've setup the fbAPP_ID in the plist under the URLs drop down
  5. 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:

enter image description here

Facebook App screen (mostly pinked out):

Facebook App screen

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:

simulator safari error

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your info.plist seems to be formatted incorrectly

Ensure that the url scheme is nested under an item (an array to be exact) called "URL Schemes"

This array should contain all possible URL Schemes that can launch your app

See the attached image for a better explanation of URL Schemes

url scheme

Also, the "URL identifier" should be your bundle identifier: ex. com.mycompany.myapp This should match the identifier you provide on your provisioning profiles

hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...