如果iPhone的“设置”应用中未配置任何帐户,则需要重定向到Facebook的设置页面

时间:2013-07-23 06:52:07

标签: facebook ios6

我正在将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登录?

2 个答案:

答案 0 :(得分:1)

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

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

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

这不太理想。 SLComposeViewController仍然显示在警报后面,键盘也会出现。隐藏这些(控制器.view.hidden = YES在呈现之前等)可能有些可能,但存在这个组件不是预期行为的风险。

答案 1 :(得分: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];
                }];
            });
        }

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