Search code examples
iosfacebooktwittersocial-framework

Adding iOS app to Twitter accounts in settings??


I am adding some sharing in my app to allow the use to post to FaceBook and to Twitter. I decided to use the Social Sharing framework as it does exactly what I need and works well.

However I noticed that my app doesn't ask the user for permission it assumes it has permission and does a check if there is an account setup.

The problem I see here is due to this - my app doesn't appear in the Settings - > Twitter under "Allow these apps to use your account" section.

Her is the code I use when I want to share an item - user taps on a UIButton which presents a UIActionSheet with various options"

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){

            SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

            SLComposeViewControllerCompletionHandler completionBlock = ^(SLComposeViewControllerResult result){

                if (result == SLComposeViewControllerResultCancelled){
                    NSLog (@"Cancelled");
                }else {
                    NSLog(@"Done");
                }

                [controller dismissViewControllerAnimated:YES completion:nil];
            };

            controller.completionHandler = completionBlock;

            NSURL *url = [NSURL URLWithString:self.item.url];

            /* Adding the text to the Tweet */
            [controller setInitialText:@"Online now!"];
            [controller addURL:url];
            [controller addImage:self.imageView.image];

            [self presentViewController:controller animated:YES completion:nil];
    }
    else {
            [self showUserAlert:@"" message:@"Please make sure your FaceBook account has been setup on this device"
                       delegate:self
              cancelButtonTitle:@"Okay"];
    }

How do I ask for access first? And add the app to the settings part of iOS so the user can turn it on or off?


Solution

  • I think you don't need a permission because your app can't post without user action. User have all control.

    You can check if sharing possible with canSendTweet method in TWTweetComposeViewController. Look up Xcode documentation. I'm sure Apple has something similar for Facebook.

    Apple documentation