本机 iOS Facebook SSO 不会返回到应用程序 [英] Native iOS Facebook SSO won't return to app

查看:14
本文介绍了本机 iOS Facebook SSO 不会返回到应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这似乎是重复的,但我已经解决了围绕该问题的所有问题,但我似乎仍然无法让它适用于我的应用.

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.

我遵循了 Facebook 开发者网站上的 iOS 教程,并完成了以下操作:

I have followed the iOS tutorial on the Facebook Developer site and I have done the following:

  1. 创建了一个 Facebook 应用以获取 Facebook 应用 ID.
  2. 我已将此应用 ID 分配给一个常量,并使用它来初始化应用内的 Facebook 对象.
  3. 我已确定我的应用已标记为多任务处理
  4. 我已经在 URL 下拉菜单下的 plist 中设置了 fbAPP_ID
  5. 我已将 AppDelegate 设为 FBSessionDelegate 并实现了非常简单的 fbDidLogin 和 fbDidNotLogin 委托方法.

版本:XCode 4.3.2 on Lion、iOS 5.1、Facebook iOS 4.1.1

Versions: XCode 4.3.2 on Lion, iOS 5.1, Facebook iOS 4.1.1

所有这一切,我似乎仍然无法让 Facebook 在授权时将控制权交还给我的应用程序.它只是留在 Facebook 中.

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.

代码:(注意FB_APP_ID改为基本号码,这里查看)

Code: (Note FB_APP_ID changed to basic number for viewing here)

AppDelegate.h:

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:

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:

Relevant Info.plist porton:

Facebook 应用程序屏幕(大部分为粉红色):

Facebook App screen (mostly pinked out):

注意:我仅使用基本设置进行了尝试,还使用了带有假 iTunes 商店 ID 但与我的配置文件中的捆绑 ID 相同的 iOS 本机应用程序设置.

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.

无论我做什么,它总是加载 Facebook 并要求授权我的应用程序,然后它只是关闭身份验证屏幕窗口并坐在我的 Facebook 屏幕上,而不是返回到我的应用程序.

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.

我在这里错过了什么吗?我还可以尝试让 Facebook 返回我的应用吗?

Have I missed something here? Anything else I can try to get Facebook to return to my app?

同样在调试时,我似乎找不到任何由于某种原因调用 openURL 的地方.

Also when debugging, I can't seem to find any spot where either openURL is called for some reason.

编辑 #2:在模拟器上运行它时,它通过 Safari 加载 FB 对话框(如预期),然后当我授权时,safari 抛出一个错误,就好像他们试图使用的 URL 回到我的应用无效:

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:

这仍然没有告诉我太多,因为据我所知,我的 fb1234567890 是在 Info.plist 中设置的.

This still doesn't tell me much since my fb1234567890 is setup right as far as I know in the Info.plist.

推荐答案

您的 info.plist 格式似乎不正确

Your info.plist seems to be formatted incorrectly

确保 url 方案嵌套在名为URL 方案"的项目(准确地说是一个数组)下

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

此数组应包含可以启动您的应用的所有可能的 URL Schemes

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

有关 URL Schemes 的更好解释,请参阅附加图片

See the attached image for a better explanation of URL Schemes

此外,URL 标识符"应该是您的包标识符:例如.com.mycompany.myapp这应该与您在配置文件中提供的标识符相匹配

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

希望这有帮助!

这篇关于本机 iOS Facebook SSO 不会返回到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆