【问题标题】:Want to redirect to setting page of Facebook if no account is configured in iPhone's Settings app如果在 iPhone 的设置应用程序中没有配置帐户,想要重定向到 Facebook 的设置页面
【发布时间】:2013-07-23 06:52:06
【问题描述】:

我正在将 Facebook 集成到我的应用中,以便将视频上传到 FB。一切正常。

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
        ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
        __block ACAccount *facebookAccount;
        NSDictionary *options = @{
                                  ACFacebookAppIdKey: @"457887770928321",
                                  ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
                                  ACFacebookAudienceKey: ACFacebookAudienceFriends
                                  };
        [accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {
            if(granted) {
                NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
                if ([accountsArray count] > 0) {
                    facebookAccount = [accountsArray objectAtIndex:0];

                    NSURL *videourl = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];
                    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"thaiPhuketKaronBeach" ofType:@"MOV"];
                    NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
                    NSData *videoData = [NSData dataWithContentsOfFile:filePath];


                    NSDictionary *params = @{
                                             @"title": @"A video post",
                                             @"description": @"Me testing the video upload to Facebook."
                                             };



                    SLRequest *uploadRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                                  requestMethod:SLRequestMethodPOST
                                                                            URL:videourl
                                                                     parameters:params];
                    [uploadRequest addMultipartData:videoData
                                           withName:@"source"
                                               type:@"video/quicktime"
                                           filename:[pathURL absoluteString]];





                    uploadRequest.account = facebookAccount;
                    NSLog(@"Uploading...");

                    [uploadRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                        NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
                        if(error){
                            NSLog(@"Error %@", error.localizedDescription);
                        }else
                            NSLog(@"Success : %@", responseString);
                    }];


                }
                else{
                      // I want to redirect from here to settings app
                    }
            }
        }];

如果accountsArray count == 0,我如何重定向到设置应用来配置FB登录?

【问题讨论】:

  • 你的帖子帮我解决了在fb上传视频的问题。谢谢。

标签: facebook ios6


【解决方案1】:

没有将用户直接带到 FB/TW 设置页面的 API。

但是,如果没有为设置的服务类型 (FB/TW/SW) 配置帐户,SLComposeViewController 将提示用户警报。该警报有一个选项可将用户带到 FB/TW 设置屏幕。

因此,如果您检测到没有配置帐户(SLComposeViewController 也有一个方法),那么您可以展示 SLComposeViweController,知道它会提示用户转到设置选项。

这并不理想。 SLComposeViewController 仍然显示在警报后面,并且键盘也出现了。在某种程度上隐藏这些是可能的(controller.view.hidden = YES before presenting 等),但有可能不是该组件的预期行为。

【讨论】:

    【解决方案2】:

    这可能会有所帮助::

            if (error.code == ACErrorAccountNotFound) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
                    controller.view.hidden = YES;
                    [self presentViewController:controller animated:NO completion:^{
                        [controller.view endEditing:YES];
                    }];
                });
            }
    

    另见这篇文章: Twitter Framework for ios6 how to login through settings from app

    【讨论】:

      猜你喜欢
      • 2012-11-03
      • 2023-03-04
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      相关资源
      最近更新 更多