如何在iOS 6中进行Facebook登录? [英] how to do facebook login in iOS 6?
问题描述
我的应用程序使用Facebook登录来验证用户,我听说有关facebook整合成为iOS SDK本身的内容,现在如果集成成为iOS内部的一部分,那么现在就可以使用
我自己可以使用它来登录,而无需导入facebook SDK,如果是的话呢?还有我的应用程序将运行iOS 6作为发布目标?
嗯,首先你必须添加 Social.framework
到您的项目。
步骤2 :您需要导入两个类。导入所需的类。
#import< Social / Social.h>
#import< Accounts / Accounts.h>
步骤3 :假设您有按钮为您的应用程序中的Facebook。在按钮上点击这些行。你完成了:$)
- (IBAction)facebookButtonClicked:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
// Facebook服务类型可用
SLComposeViewController * slVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler handler = ^(SLComposeViewControllerResult result)
{
if(result == SLComposeViewControllerResultCancelled)
{
NSLog(@Cancellled);
}
else
{
NSLog(@Done);
}
[slVC dismissViewControllerAnimated:YES完成:Nil];
};
slVC.completionHandler = handler;
[slVC setInitialText:@从iOS6测试帖];
[slVC addURL:[NSURL URLWithString:@http://www.apple.com]];
[slVC addImage:[UIImage imageNamed:@someimage.png]];
[self presentViewController:slVC animated:YES completion:Nil];
}
else
{
NSLog(@Service Unavailable !!!);
}
}
上面给出的是基本步骤。欲了解更多信息,请参阅这个。
修改:对于Facebook用户信息,请参阅 answer 。
快乐编码。 : - )
My app uses the facebook login to authenticate the users, I heard about the facebook integration become inside the iOS SDK itself,
now if the integration become inside the iOS itself can i use it to login without importing the facebook SDK and how if yes? also my app will run the iOS 6 as a release target ?
Well, First of all you have to add the Social.framework
in to your project.
Step 2 : You need to import two classes.Import the needed classes.
#import <Social/Social.h>
#import <Accounts/Accounts.h>
Step 3 : I am going forward in the assumption that you have a button for Facebook in your app. At the button click write these lines. You are done. :-)
- (IBAction)facebookButtonClicked:(id)sender
{
if([SLComposeViewController isAvailableForServiceType: SLServiceTypeFacebook])
{
// Facebook Service Type is Available
SLComposeViewController *slVC = [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler handler = ^(SLComposeViewControllerResult result)
{
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(@"Cancelled");
}
else
{
NSLog(@"Done");
}
[slVC dismissViewControllerAnimated:YES completion:Nil];
};
slVC.completionHandler = handler;
[slVC setInitialText:@"Test Post from iOS6"];
[slVC addURL:[NSURL URLWithString:@"http://www.apple.com"]];
[slVC addImage:[UIImage imageNamed:@"someimage.png"]];
[self presentViewController:slVC animated:YES completion:Nil];
}
else
{
NSLog(@"Service Unavailable!!!");
}
}
The above given is the basic steps. For more you can refer This.
Edit : For Facebook user information refer this answer.
Happy Coding. :-)
这篇关于如何在iOS 6中进行Facebook登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!