您可以使用 ACAccountStore 进行身份验证。感谢http://blogs.captechconsulting.com/blog/eric-stroh/ios-6-tutorial-integrating-facebook-your-applications提供以下大部分代码。
self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = @"987654"; //put your own key from FB here
NSDictionary *dictFB = //use the ACAccountStore ACFacebookPermissionsKey to help create your dictionary of permsission you'd like to request, such as the users email, writing on the wall, etc.
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion: ^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with SSO
self.facebookAccount = [accounts lastObject];
} else {
//Fail gracefully...
NSLog(@"error getting permission %@",e);
}
}];
此时,您可以访问 accountStore 中的 oauth 令牌,您可以将其发送到您的服务器,以便与 facebook 进行任何服务器端交互。