2

我正在将 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
                    }
            }
        }];

如果出现以下情况,我如何重定向到设置应用程序来配置 FB 登录accountsArray count == 0

4

2 回答 2

1

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

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

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

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

于 2013-08-02T21:29:27.527 回答
0

这可能会有所帮助::

        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];
                }];
            });
        }

另请参阅这篇文章: iOS6 的 Twitter 框架如何通过应用程序的设置登录

于 2013-11-22T21:23:27.997 回答