【问题标题】:iOS6 Facebook: What to do if user has not configured Facebook?iOS6 Facebook:如果用户没有配置Facebook怎么办?
【发布时间】:2012-09-21 18:24:21
【问题描述】:

我正在iOS6 中使用新的 Facebook 集成,如下所示:

SLComposeViewController *fbController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

        [fbController dismissViewControllerAnimated:YES completion:nil];

        switch(result){
            case SLComposeViewControllerResultCancelled:
            default:
            {
                NSLog(@"Cancelled.....");

            }
                break;
            case SLComposeViewControllerResultDone:
            {
                NSLog(@"Posted....");
            }
                break;
        }};

    //[fbController addImage:[UIImage imageNamed:@"1.jpg"]];
    [fbController setInitialText:@"Test message"];
    [fbController addURL:[NSURL URLWithString:self.asset.url]];
    [fbController setCompletionHandler:completionHandler];
    [self presentViewController:fbController animated:YES completion:nil];
} else {
    NSLog(@"no facebook setup");
}

这里的问题是,我在没有登录 Facebook 的情况下测试它,我得到的只是日志消息。

** 奇怪的是,我在模拟器中得到了对话框,但不是设备!**

如何向用户显示提醒他们需要登录 Facebook?我看过系统警报的屏幕截图,但由于某种原因我没有收到。我做错了什么?

【问题讨论】:

    标签: objective-c ios facebook cocoa-touch ios6


    【解决方案1】:

    删除[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] 的检查为我解决了这个问题。

    【讨论】:

    • 是的,当我在模拟器和设备中删除此检查时弹出警报。
    • 是的,也为设备修复了。
    • 已确认,也修复了设备中的问题。
    • 根据 SLComposeViewController 的 documentation,isAvailableForServiceType “返回一个布尔值,指示服务是否可访问并且至少设置了一个帐户...要使帐户可用,用户必须在设备设置中登录社交服务。”所以这可以解释为什么删除它对你有用。希望有帮助!
    【解决方案2】:

    [SLComposeViewController isAvailableForServiceType:] 似乎在模拟器中返回 true,即使您还没有在那里设置帐户。

    【讨论】:

      【解决方案3】:

      我认为您不会收到任何系统警报(我不确定,但基于 Twitter 的经验)。尽管我在最近的一些博客/网络帖子中看到了它,但它对我也不起作用。我建议在这种情况下,您应该询问用户的 FB 凭据(自定义对话框或 FBDialog)并在 iPad 中添加 FB 帐户。以下代码未经测试,但您可以了解一下。我正在为 Twitter 做类似的事情,并且在我的应用程序中运行良好。

      ACAccountStore *store = [[ACAccountStore alloc] init] ;
          ACAccountType *fbType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
          [store requestAccessToAccountsWithType:fbType options:[NSDictionary dictionaryWithObjectsAndKeys:kAppID,ACFacebookAppIdKey, nil] completion:^(BOOL granted, NSError *error) {
              if(YES) {
                  ACAccount *fbAccount = [[ACAccount alloc] initWithAccountType:[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]];
      
                  ACAccountCredential *outhCredential = [[ACAccountCredential alloc] initWithOAuth2Token:[appDelegate.facebook accessToken] refreshToken:refesrhToken expiryDate:[appDelegate.facebook expirationDate]];
      
      
                  fbAccount.credential = outhCredential;
      
                  [store saveAccount:fbAccount withCompletionHandler:^(BOOL success, NSError *error) {
                      if(success)
                      {
                          [self performSelectorOnMainThread:@selector(showFBPostSheet) withObject:nil waitUntilDone:NO];
                      }
                  }];
      
                  [outhCredential release];
                  [fbAccount release];
                  [store release];
              }
              // Handle any error state here as you wish
          }];
      

      【讨论】:

      • 我实际上刚刚意识到我确实在模拟器中得到了对话框,但不是设备。好奇怪。
      猜你喜欢
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-21
      • 1970-01-01
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多