如何实现单点登录(SSO)使用facebook ios sdk的iphone [英] How to implement Single Sign On (SSO) using facebook ios sdk for iphone

查看:337
本文介绍了如何实现单点登录(SSO)使用facebook ios sdk的iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用最新的ios sdk。为了实现SSO,Facebook说:



如下修改应用程序的主要AppDelegate类:

   - (BOOL)应用程序:(UIApplication *)application handleOpenURL:(NSURL *)url 

在此方法中,调用应用程序的Facebook对象的handleOpenURL方法,确保传入url参数。



我的查询是:



  1. 上述方法的用途是什么?为什么叫它?
    如果我隐藏在提供的Facebook演示应用程序的方法,它总是将我重定向到登录页面一次又一次。如果我取消隐藏这种方法,它将重定向到其他按钮的注销选项(这是正确的)


  2. 现在,由于此方法在ApplicationDelegate.m文件中定义,必须在其中调用Facebook对象。如何在这个方法中引用Facebook对象,因为我的Facebook对象是在层次结构下降4倍的视图控制器类中定义的。



注意:我尝试过DemoApp。我不明白他们是如何引用AppController的文件中的Facebook对象在Facebook ControlController文件中声明的对象的对象。

解决方案

该方法用于确定您的应用程序是否将处理传递给它的URL。例如,您的应用程序可以处理特定的URL方案,然后在运行时选择是否处理特定的URL。如果您返回NO,它将转移到其他可能处理相同URL方案的应用程序。虽然在Facebook iOS SDK的情况下,您的应用程序将是处理URL方案的唯一应用程序。



当您尝试登录到Facebook时,SDK将值传递给Facebook应用程序或Facebook网站,并包含回调URL,以便授权过程可以完成。在应用程序委托中没有这种方法,该回调将无法正常工作。



有关oAuth的更多信息,请参阅:



http://developers.facebook.com/docs/authentication/



其次,这个问题比只是Facebook SDK。这与核心架构问题有关。您可以将Facebook对象包括在应用程序委托中,然后在视图控制器中引用它。这是最简单的方法。在视图控制器中,您可以执行以下操作:

  Facebook * facebook = [(YourAppDelegate *)[UIApplication sharedApplication] ]脸书] 

此选项并不总是理想的,因为它使得应用程序委托一个倾倒地面很多共享实例。



另一个选择是让应用程序委托将Facebook对象传递给视图控制器(视图控制器将具有Facebook对象的属性) - 然后应用程序委托将在init之后将其传递给视图控制器。)

  MyViewController * vc = [[MyViewController alloc] initWithNibName:@MyViewControllerbundle:nil]; 
vc.facebook = self.facebook;

还有其他选项用于共享类的实例,例如异议iOS框架,但这些是更高级。


I am using the latest facebook ios sdk in my app. In order to implement SSO, Facebook says:

Modify your application's main AppDelegate class as follows:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

In this method, call your application's Facebook object's handleOpenURL method, making sure to pass in the url parameter.

My query is:

  1. What is the use of the above method? Why to call it? If I hide the method in the facebook demo app provided it always redirects me to login page again and again. If I unhide this method it redirects me to logout with other buttons option (which is right)

  2. Now as this method is defined in ApplicationDelegate.m file and we have to call facebook object in it. How can I refer to the facebook object in this method as my facebook object is defined in a view controller class which is 4 times down the hierarchy.

NOTE: I have tried the DemoApp. I do not understand how did they refer to the facebook object in the AppDelegate.m file inspite of the facebook object declared in ViewController file.

解决方案

The method is used to determine if your application will 'handle' the url that is passed to it. For example, your application can handle a specific URL 'scheme' and then choose at runtime if it will handle the specific URL. IF you return NO, it will move on to other application that may also handle the same URL scheme. Although, in the case of the Facebook iOS SDK, your application would be the only application handling the URL scheme.

When you attempt to login to Facebook, the SDK passes values to either the Facebook application or to the Facebook website and it includes a callback URL so that the authorization process can be completed. Without this method in the app delegate, that callback won't work properly.

For more information on oAuth, see:

http://developers.facebook.com/docs/authentication/

Second, this is a bigger question than just the Facebook SDK. This has to do with a core architectural issue. You can include the Facebook object in your application delegate and then reference it in the view controller. This is the easiest method. Within the view controller, you could just do the following:

Facebook *facebook = [(YourAppDelegate *)[UIApplication sharedApplication] delegate] facebook];

This option isn't always ideal, because it makes the app delegate a dumping ground for a lot of shared instances.

Another option is to have the application delegate pass the Facebook object to the view controller when you create it (the view controller would have a property for the Facebook object - and then the application delegate would pass it to the view controller after init).

MyViewController *vc = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
vc.facebook = self.facebook;

There are also other options for sharing instances of classes such as the Objection iOS framework, but these are a bit more advanced.

这篇关于如何实现单点登录(SSO)使用facebook ios sdk的iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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