【发布时间】:2013-12-05 18:07:50
【问题描述】:
我正在尝试使用 iOS Social.framework 分享到 Facebook。但是,大多数用户不会在 Settings>Facebook 中设置 Facebook,因此当您调出 UIActivityViewController 时,Facebook 不会出现,只是没有列出。 (请参阅UIActivity with no settings for Facebook 或只是谷歌“Facebook 不显示在 UIActivityViewController”,有很多人试图解决这个问题。)
我们的应用程序已经使用了 Facebook SDK,因此我可以获取 Facebook 帐户信息,所以我想我只是获取信息,然后将信息保存在“设置”>“Facebook”中。这是我的代码。 (我从When do we use saveAccount:(ACAccount *)account of ACAccountStore class? 和iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert 得到的)
- (void)storeAccountWithAccessToken:(NSString *)token secret:(NSString *)secret {
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
//We start creating an account by creating the credentials object
ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];
ACAccountType *acctType =[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:acctType];
//Here we assign credentials and now can save account
newAccount.credential = credential;
NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
[VVEnvironment stringForKey:kVVEnvironmentKeyFacebookAppID], (NSString *)ACFacebookAppIdKey,
[NSArray arrayWithObject:@"basic_info"], (NSString *)ACFacebookPermissionsKey,
ACFacebookAudienceEveryone, (NSString *)ACFacebookAudienceKey,
nil];
[_accountStore requestAccessToAccountsWithType:acctType options:options completion:^(BOOL granted, NSError *error) {
if (granted == YES) {
[self.accountStore saveAccount:newAccount withCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"the account was saved!");
}
else {
if ([error code] == ACErrorPermissionDenied) {
NSLog(@"Got a ACErrorPermissionDenied, the account was not saved!");
}
NSLog(@"the account was not saved! %d, %@", [error code], error);
}
}];
}
else {
NSLog(@"ERR: %@ ",error);
}
}];
}
我在那里添加了对 requestAccessToAccountsWithType 的调用,因为没有我从 saveAccount 返回 ACErrorPermissionDenied。当我运行它时,我确实看到我的应用程序在 Facebook 对话框中短暂滑动(如果我在 Facebook 的网站上删除我的应用程序,它确实会显示完整的对话框,询问我授予的权限。)
问题是granted 总是NO,所以我永远没有机会保存帐户。我在这里错过了什么?
我在安装并设置了 Facebook 应用的真实设备上运行它。
如果有任何帮助,我将不胜感激,谢谢!
【问题讨论】:
-
这个1解决了吗?你能说一下你是如何将令牌和秘密从
[FBSession activeSession] accessTokenData.accessToken]Am 中分离出来的吗…… -
我无法解决这个问题。
-
只是想知道您是否在 requestAccessTo 之前尝试了 saveAccount...?
-
是的,来自问题:“我在那里添加了对 requestAccessToAccountsWithType 的调用,因为没有我从 saveAccount 返回 ACErrorPermissionDenied。”
-
所以它似乎适用于 Twitter(根据您引用的问题)但不适用于 Facebook。非常令人沮丧 - 理想情况下,如果我们只需要注册/登录/共享功能,我们甚至不必使用 FacebookSDK。我希望仅使用社交框架就可以实现。
标签: ios acaccountstore