0

Am using SLComposeViewController for posting articles to facebook wall.When App permission is turned off for facebook in device settings, SLComposeViewController still Works by posting article to facebook wall.Is this a SDK issue?

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

        }
spp
  • 103
  • 1
  • 15
  • Code would be helpful... – Mick MacCallum Mar 01 '13 at 12:44
  • Pretty sure that when you use SLComposeViewController the whole permissions thing is managed by iOS; technically, it's iOS posting, not your app. The post that shows up on the user's timeline probably says "via iOS", right? – Thiago Campezzi Mar 04 '13 at 06:39
  • @ThiagoCampezzi: Ya it says "vis iOS".Is there anyway to check "is the app permission is disabled for facebook in device settings ?.. – spp Mar 04 '13 at 06:43
  • You can try opening a Facebook session before and see if it works (if you're using the latest Facebook SDK, you would probably call the `+ (BOOL)openActiveSessionWithReadPermissions:(NSArray*)readPermissions allowLoginUI:(BOOL)allowLoginUI completionHandler:(FBSessionStateHandler)handler;` in the FBSession class passing NO as the allowLoginUI parameter and checking for errors in the completion handler; however, that is mostly used if you're trying to programatically post to Facebook without going through the SLComposeViewController (i.e. if you have your own custom interface). – Thiago Campezzi Mar 04 '13 at 06:51
  • If your goal is to use the SLComposeViewController, you wouldn't need to worry about that as iOS handles the permissions (and it will work even if your app is disabled, since the post is being published by the OS and not your app). – Thiago Campezzi Mar 04 '13 at 06:52
  • @ThiagoCampezzi: is there anyway to achieve this?? – spp Mar 04 '13 at 11:45

1 Answers1

1

I found out the answer myself. Check the below code

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


                    });
                 }
            }];
spp
  • 103
  • 1
  • 15