在iOS 5和6中使用Facebook实现登录 [英] Implement Login with Facebook in iOS 5 and 6
问题描述
这个问题看起来很重要,你们有50%是重复的,因为我没有找到任何好的答案。
让我把我的问题分成三部分。 / p>
目前情况:
我已经通过电子邮件,出生日期,性别和邮政编码。
这是非常好的工作。我也在iOS 5和6中实现了Facebook和Twitter的共享功能
但是现在我想用Facebook和Twitter进行实现,例如
,如下面的示例屏幕所示:
有什么问题:
我想知道如何在iOS 5中使用Facebook实现登录。twitter与ios 5和6,Facebook与iOS 6,所以这不是很大的(现在我认为)。我已经为iOS 5和Android推出了Twitter和Twitter的共享功能6.所以我需要做些什么来实现登录。
我得到的回应是:
正如我所说,我需要注册时的电子邮件,出生日期,性别和邮政编码。
如果我使用Facebook和Twitter进行登录,我该如何获取这些信息。
如果用户没有给出或阻止此社交网站的信息,该怎么办?
谢谢.......
这是我在应用程序中如何实现这个功能:
-
从此处下载适用于iOS的Facebook SDK
-
在您的
AppDelegate.h
中创建Facebook对象的属性。#import< UIKit / UIKit.h>
#importFacebook.h
@interface OutpearAppDelegate:NSObject< UIApplicationDelegate> {
UIWindow * window;
IBOutlet UINavigationController * navigationController;
}
@property(非原子,保留)IBOutlet UINavigationController * navigationController;
@property(非原子,保留)IBOutlet UIWindow *窗口;
@property(非原子,保留)Facebook * facebook;
+(DemoAppDelegate *)getAppDelegate;
-
在您的
AppDelegate.m
写这个:综合Facebook;
并在您的
applicationDidFinishLaunching
方法中写下://使用应用程序ID初始化Facebook
facebook = [[Facebook alloc] initWithAppId:FB_APP_KEY andDelegate:nil];
//这里FB_AP_Key是您的Facebook应用程序密钥
并发布
在
dealloc
-
您要在哪里登录Facebook功能:
- (void)loginWithFacbookIdClicked
{
[DemoAppDelegate getAppDelegate] .facebook.sessionDelegate = self ;
if(isInternetAvailable)
{
if([[DemoAppDelegate getAppDelegate] .facebook isSessionValid])
{
// [facebookIntegration getUserFacebookPersonalInfo];
NSLog(用户已经登录了Facebook);
}
else
{
[[DemoAppDelegate getAppDelegate] .facebook authorize:[NSArray arrayWithObjects:@read_stream,
@publish_stream,
@email,
@user_birthday,
@friends_about_me,
@friends_activities,
@friends_likes,
nil]];
}
}
else
{
NSLog(无Internet连接);
}
}
-
登录后,Facebook SDK委托方法被自动调用。在委托方法中做你的东西。
- (void)fbDidLogin
{
NSLog( Facebook的);
//你的逻辑在这里。
}
- (void)fbDidNotLogin:(BOOL)已取消
{
DLog(@登录取消);
}
- (void)fbDidExtendToken:(NSString *)accessToken expiresAt :( NSDate *)expiresAt
{
}
- (void)fbSessionInvalidated
{
}
- (void)fbDidLogout
{
}
This question look duplicate and ye it is 50% duplicate because there is no good answer I found any where.
let me divide my question in three part.
Current Situation:
I have implemented sign up screen with Email, Date of birth, Gender and Zipcode.
This is working very nice. I have also implement share feature in facebook and twitter in iOS 5 and 6
But now I want to implement it with facebook and twitter like
shown in following example screen:
What is problem: I want to know how can I implement login with facebook in iOS 5. twitter is integrated with ios 5 and 6, Facebook with iOS 6 so that is not big deal (right now I think so). I have already implemented share feature for both twitter and facebook for iOS 5 & 6. so what more I need to do to implement login.
What I get in response: As I said I need Email, Date of birth, Gender and Zipcode at time of signup. How can I get this information if I use login with facebook and twitter. What should I do if user have not given or block this information of this social site.
Thanks.......
Here is how I implemented this feature in my app:
Download the Facebook SDK for iOS from here
In your
AppDelegate.h
make a property of the Facebook object.#import <UIKit/UIKit.h> #import "Facebook.h" @interface OutpearAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; IBOutlet UINavigationController *navigationController; } @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) Facebook *facebook; +(DemoAppDelegate*)getAppDelegate;
In your
AppDelegate.m
write this:synthesize facebook;
and in your
applicationDidFinishLaunching
method write this:// Initialize Facebook with app ID facebook=[[Facebook alloc]initWithAppId:FB_APP_KEY andDelegate:nil]; //here FB_AP_Key is your Facebook application key
and release
facebook
indealloc
Where you want to login with Facebook write this function:
- (void)loginWithFacbookIdClicked { [DemoAppDelegate getAppDelegate].facebook.sessionDelegate=self; if(isInternetAvailable) { if([[DemoAppDelegate getAppDelegate].facebook isSessionValid]) { //[facebookIntegration getUserFacebookPersonalInfo]; NSLog("User already logined with facebook"); } else { [[DemoAppDelegate getAppDelegate].facebook authorize:[NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"email", @"user_birthday", @"friends_about_me", @"friends_activities", @"friends_likes", nil]]; } } else { NSLog("No Internet Connection"); } }
After login, the Facebook SDK delegate methods are automatically called. Do your stuff in delegate methods.
- (void)fbDidLogin { NSLog("Logged into Facebook"); // Your logic goes here. } -(void)fbDidNotLogin:(BOOL)cancelled { DLog(@"Login Cancelled"); } -(void)fbDidExtendToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt { } -(void)fbSessionInvalidated { } -(void)fbDidLogout { }
这篇关于在iOS 5和6中使用Facebook实现登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!