以编程方式获取"允许这些应用使用您的帐户"在Twitter上

时间:2015-05-25 12:17:24

标签: ios objective-c twitter

我想以编程方式获取"允许这些应用使用您的帐户"在Twitter设置页面中,如果已禁用,请打开“设置页面”,以便用户可以手动更改值。

我尝试使用以下代码在iOS 8.1的Twitter中打开设置页面:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”prefs:root=TWITTER”]];

但它在iOS 8 +中没有任何作用。有人知道如何以编程方式获取此值并重定向到Twitter的设置页面吗?

enter image description here

2 个答案:

答案 0 :(得分:1)

prefs scheme不再有效,你现在所有的应用程序都可以通过UIApplicationOpenSettingsURLString常量打开一个应用程序首选项。见this回答。

另请注意,如果这是第一次调用,requestAccessToAccountsWithType:options:completion:方法将触发权限对话框。因此,当您尝试使用Twitter做某事时,更好的方法是优雅地失败。权限对话框应该是用户操作的结果,因此不会让他感到困惑。

答案 1 :(得分:0)

试试以下...

ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
                              ACAccountTypeIdentifierTwitter];

[account requestAccessToAccountsWithType:accountType options:nil
                              completion:^(BOOL granted, NSError *error)
 {
     if (granted == YES)
     {
         NSLog(@"Twitter Access");
     }
     else
     {
         NSLog(@"No Twitter Access");
     }
 }];