0

Facebookウォールに記事を投稿するためにSLComposeViewControllerを使用しています。デバイス設定でFacebookのアプリ権限がオフになっている場合でも、SLComposeViewControllerはFacebookウォールに記事を投稿することで機能します。これはSDKの問題ですか?

    SLComposeViewController *facebookViewController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

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

            [facebookViewController dismissViewControllerAnimated:YES completion:nil];

            switch(result){
                case SLComposeViewControllerResultCancelled:
                default:
                {
                    [[[UIAlertView alloc] initWithTitle:@"Facebook"
                                                message:@"Action Cancelled"
                                               delegate:nil
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil]
                     show];

                    [self dismissView];

                }
                    break;
                case SLComposeViewControllerResultDone:
                {
                    [[[UIAlertView alloc] initWithTitle:@"Facebook"
                                                message:@"Posted to Facebook successfully"
                                               delegate:nil
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil]
                     show];

                    [self dismissView];

                }
                    break;
            }};

        [facebookViewController addImage:_shareImage];
        [facebookViewController setInitialText:_shareTitle];
        [facebookViewController addURL:_shareLink];
        [facebookViewController setCompletionHandler:completionHandler];

        [self.dashboard presentViewController:facebookViewController animated:YES completion:nil];

        }
4

1 に答える 1

1

私は自分で答えを見つけました。以下のコードを確認してください

  if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
    {
        ACAccountStore *accountStore=[[ACAccountStore alloc]init];
        ACAccountType * facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

        // At first, we only ask for the basic read permission
        NSArray * permissions = @[@"publish_stream"];

        NSDictionary * dict = @{ACFacebookAppIdKey : @"facebook_appid", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceEveryone};

        [accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
            if (granted && error == nil)
            {

        SLComposeViewController *facebookViewController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
            SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result)
            {

                [facebookViewController dismissViewControllerAnimated:YES completion:nil];

                switch(result){
                    case SLComposeViewControllerResultCancelled:
                    default:
                    {
                        [self dismissView];

                    }
                        break;
                    case SLComposeViewControllerResultDone:
                    {
                        [[[UIAlertView alloc] initWithTitle:@"Facebook"
                                                    message:@"Posted to Facebook successfully"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil]
                         show];

                        [self dismissView];

                    }
                        break;
                }};

            [facebookViewController addImage:_shareImage];
            [facebookViewController setInitialText:_shareTitle];
            [facebookViewController addURL:_shareLink];
            [facebookViewController setCompletionHandler:completionHandler];

            [self.dashboard presentViewController:facebookViewController animated:YES completion:nil];
            }
                else
                {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self dismissView];
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message: @"App Permissions disabled in facebook settings."
                                                                       delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
                        [alert show];


                    });
                 }
            }];
于 2013-03-06T11:05:13.837 に答える