Facebook SDK登录弹出窗口视图的更改

4
我正在尝试使用Facebook登录我的应用程序。为此,我已经安装了Facebook SDK。现在的问题是,我正在尝试从SDK的示例代码SessionLoginSample开始。问题是,要登录,它会将我带到Safari浏览器中输入凭据。难道不能像弹出视图一样打开登录页面吗(如图2)...
图1直接进入Safari,需要哪些更改才能像图2那样以弹出窗口的形式打开?
 - (IBAction)buttonClickHandler:(id)sender {

SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];


if (appDelegate.session.isOpen) {

    [appDelegate.session closeAndClearTokenInformation];

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {

        appDelegate.session = [[FBSession alloc] init];
    }


    [appDelegate.session openWithCompletionHandler:^(FBSession *session, 
                                                     FBSessionState status, 
                                                     NSError *error) {
        // and here we make sure to update our UX according to the new session state
        [self updateView];
    }];
} 
 }

你想要什么?像Twitter一样直接公开吗? - Paras Joshi
没错,就像右边的图片一样...(不在Safari中)... - Christien
6个回答

3

使用FBConnect可以实现此功能,请参考以下教程...

iPhone-fbconnect-facebook-connect-tutorial

如下所示查看登录对话框...

enter image description here

只需按照说明创建您的ID并使用它即可。

同样还有另一个带有示例的教程,请参见...

这里


1
哦,朋友好的,如果我找到了什么东西,我会发布一些内容。请详细检查这些链接,也许它们会起作用。好的,伙计。 - Paras Joshi
1
@Christien,你尝试过使用ShareKit吗? - Vishal
1
嘿@Vishal,给我一些链接吧,兄弟..我认为做这样的事情..你有一个最新的iOS 5解决方案的想法,所以伙计.. :) - Paras Joshi
1
@Christien 我知道这是一些应用程序的组合,但它并不复杂。你只需要忽略所有其他应用程序...我认为你的问题将通过这种方式得到解决...我经常使用分享工具包,你所需要的可以很容易地通过分享工具包实现...请看我给出的答案,分享工具包如何实现:https://dev59.com/SW3Xa4cB1Zd3GeqPaAZr#14250554 - Vishal
2
@ParasJoshi 兄弟,终于完成了不用Safari的Facebook登录。这让我头疼不已。Sharekit也让我更加头疼。它太复杂了,只为了使用Facebook而已。最后,我决定在SDK中进行更改,否则就算了。你不会相信,只需要改动两行代码就可以了。我为此苦恼了这么多天... :) - Christien
显示剩余16条评论

1

是的,那就是我想要的,但我无法从这里正确登录...即使我已经输入了我的Facebook ID。 - Christien
你遇到了什么问题? - Pranjal Bikash Das
FBFun[769:f803] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> Application tried to present modally an active controller <FBFunViewController: 0x6a36ac0>. - Christien
问题出在你的视图结构中。在呈现 WebView 方面,你做错了些什么。 - Pranjal Bikash Das
我只是简单地使用了示例代码...没有做任何更改...然后使用了我的ID。 - Christien

0

你可以试试这个,对我来说很有效:

loginView.loginBehavior=FBSessionLoginBehaviorForcingWebView;

这里的 loginView 是我的 FBLoginView。这是针对你右侧屏幕截图的。

对于屏幕截图1,请使用以下代码:

loginView.loginBehavior=FBSessionLoginBehaviorForcingSafari;

0
  let loginView : FBSDKLoginButton = FBSDKLoginButton()

  loginView.loginBehavior = FBSDKLoginBehavior.Web

对我来说它有效,这是在类FBSDKLoginManager中的源代码:

public enum FBSDKLoginBehavior : UInt {

/*!
 @abstract Attempts log in through the native Facebook app. If the Facebook app is
 not installed on the device, falls back to \c FBSDKLoginBehaviorBrowser. This is the
 default behavior.
 */
case Native
/*!
 @abstract Attempts log in through the Safari browser
 */
case Browser
/*!
 @abstract Attempts log in through the Facebook account currently signed in through Settings.
 If no Facebook account is signed in, falls back to \c FBSDKLoginBehaviorNative.
 */
case SystemAccount
/*!
   @abstract Attemps log in through a modal \c UIWebView pop up

   @note This behavior is only available to certain types of apps. Please check the Facebook
   Platform Policy to verify your app meets the restrictions.
   */
case Web

}


0

您可以在会话中使用这个:

FBSession setActiveSession:[[FBSession alloc]initWithAppID:nil permissions:@[@"email", @"user_friends"] urlSchemeSuffix:@"foo" tokenCacheStrategy:nil]];

更多信息请参见:Facebook开发者


0
在XCode项目中的info.plist文件中查找或创建键为"FacebookUrlSchemeSuffix"和字符串值的行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接