2

動画を FB にアップロードするために、Facebook をアプリに統合しています。すべてが正常に機能しています。

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

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 に答える