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

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

问题描述

好吧,这可能看起来像一个重复,但我已经解决了所有的问题,围绕这个问题,我仍然似乎无法让这个工作适用于我的应用程序。



我已经在Facebook开发者网站上遵循了iOS教程,我已经完成了以下工作:


  1. 创建了一个Facebook应用程序获取Facebook应用程序ID。

  2. 我已将此应用程序ID分配给常量,并使用它来初始化我的应用程序中的Facebook对象。

  3. <我已经确定我的应用程序被标记为多任务
  4. 我已经在plist中设置了fbAPP_ID,在URL下拉列表

  5. 我我的AppDelegate是一个FBSessionDelegate,并实现了非常简单的fbDidLogin和fbDidNotLogin委托方法。

版本:Lion,iOS上的XCode 4.3.2 5.1,Facebook iOS 4.1.1



所有这一切,我仍然似乎无法让Facebook将控制权返回给我的应用程序,当它授权。



代码:(注意FB_APP_ID更改为在此查看的基本号码)



AppDelegate.h:

  #import< UIKit / UIKit.h> 
#importFBConnect.h

#define FB_APP_ID @1234567890

@interface AppDelegate:UIResponder< UIApplicationDelegate,FBSessionDelegate>

@property(强,非原子)UIWindow *窗口;
@property(nonatomic,strong)Facebook * facebook;

@end

AppDelegate.m:

  #importAppDelegate.h

@implementation AppDelegate
@synthesize window = _window;
@synthesize Facebook = _facebook;

- (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions :( NSDictionary *)launchOptions
{
_facebook = [[Facebook alloc] initWithAppId:FB_APP_ID andDelegate:self];
if(![_ facebook isSessionValid])
{
[_facebook authorize:nil];
}
}

- (BOOL)应用程序:(UIApplication *)应用程序handleOpenURL:(NSURL *)url
{
return [_facebook handleOpenURL: URL]
}

- (BOOL)应用程序:(UIApplication *)应用程序openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication注释:(id)注释
{
return [_facebook handleOpenURL:url];
}

- (void)fbDidLogin
{
NSLog(@应用程序登录);
}

- (void)fbDidNotLogin :( BOOL)已取消
{
NSLog(@App没有登录);
}

@end

相关Info.plist porton:





Facebook应用程序屏幕(主要是粉红色):





注意:我仅使用基本设置,还可以使用iOS Native应用设置一个假的iTunes商店ID,但是我的配置文件中的相同捆绑ID。



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



另请注意:我知道它总是会问,因为我没有检查auth令牌和到期日期.....这是下一步....现在我想至少得到它返回到我的应用程序,我担心之前。



我错过了这里的东西?还有什么我可以尝试让Facebook返回到我的应用程序?



编辑:当调试时,我似乎找不到任何一个openURL被调用的地方一些原因。编辑#2:在模拟器上运行时,它通过Safari加载FB对话框(如预期),然后当我授权时,safari会抛出错误,就像他们尝试使用的网址无法恢复到我的应用程序:





这仍然没有告诉我太多,因为我的fb1234567890是正确的,就像我在Info.plist中所知道的那样。

解决方案

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



确保url方案嵌套在一个名为URL方案的项目(一个数组)下。



此数组应包含可以启动应用程序的所有可能的URL方案



查看附件,了解URL方案的更好解释



url方案http://f.cl.ly/items/243G1D0H39151q472V1t/Screen%20Shot% 202012-05-16%20at%206.52.06%20 PM.png



此外,URL标识符应该是您的包标识符:ex。 com.mycompany.myapp
这应该符合您在配置配置文件上提供的标识符



希望这有帮助!


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:

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.

解决方案

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 http://f.cl.ly/items/243G1D0H39151q472V1t/Screen%20Shot%202012-05-16%20at%206.52.06%20PM.png

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!

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

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