嗨,我正在“使用 facebook 登录”,
我的代码如下
这里没有进入 if(granted ) 循环。
在我单击弹出窗口中的“确定”后,控制台打印如下
2 012-11-28 15:47:08.558 Tattoo Later[2748:1d34b] type:com.apple.facebook
identifier: B962F897-6BAE-4769-8C04-B1B3D2C872A2
accountDescription: Facebook
username: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5a0bda4a8b5a9a085bca4adaaaaeba6aaebacab" rel="noreferrer noopener nofollow">[email protected]</a>
objectID: x-coredata://EBF41CAD-7388-45E0-8621-3958C7A67491/Account/p1
enabledDataclasses: {(
"com.apple.Dataclass.Contacts",
"com.apple.Dataclass.Calendars"
)}
enableAndSyncableDataclasses: {(
)}
properties: {
fullname = "Example";
uid = 100001462475956;
}
parentAccount: (null)
owningBundleID:(null)
当我们点击“使用 Facebook 登录”时我的代码:
-(IBAction)loginWithFacebookClicked:(id)sender
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = [NSArray arrayWithObjects:@"email",@"user_location", nil];
NSDictionary * dict=[NSDictionary dictionaryWithObjectsAndKeys:@"238864112907671",ACFacebookAppIdKey,permissions,ACFacebookPermissionsKey,ACFacebookAudienceEveryone,ACFacebookAudienceKey, nil];
[accountStore requestAccessToAccountsWithType:accountType options:dict completion:^(BOOL granted, NSError *error) {
if(granted ) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
ACAccount *fbAccount = [accountsArray objectAtIndex:0];
NSLog(@"%@",fbAccount);
}
}
else
{
NSLog(@"%@",[error localizedDescription]);
}
}];
}
最初我遇到了一些错误,例如
Facebook 服务器无法满足此访问请求:代理应用程序在未事先安装的情况下无法请求发布权限。
错误 Domain=com.apple.accounts Code=7 “Facebook 服务器无法满足此访问请求:无效的应用程序 ID” UserInfo=0xa29f520 {NSLocalizedDescription=Facebook 服务器无法满足此访问请求:无效的应用程序 ID}
后来我通过搜索解决了,但我没有找到解决方案
请指导我 提前致谢
最佳答案
答案很简单!稍后在任意线程上调用完成 block 。因此,如果您一步一步进行,它实际上会退出您的方法并继续在主线程上工作,稍后当您收到响应时,它会进入 if 或 else 部分。您的日志实际上证明您已进入 if 部分(它记录帐户)。如果您在 if 部分放置一个断点,您会注意到此行为。所以你的代码没问题。
关于iphone - 在 facebook ios6 中未进入 if(granted ) 循环 "Sign in with Facebook",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13602809/