0

Having set up a Twitter sharing function in an iOS app, I have a question. Here is the code, it is based on what I have found, browsing the net:

func shareImageOnTwitter() {
    if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter){
        let twit = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
        // Do all the necessary local cooking for whatever we want to share ………….
    } else {
        // In which case are we suppose to be here ?????
        var alert = UIAlertController(title: "Accounts", message: "Please login to a Twitter account to share.", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
    }
}

Let me say that it is basically working. But the question is when do we reach the second branch of the if. That is where my comment (// In which case are we suppose to be here ?????) is.

I have made a few experiments to prevent Twitter from working, I then get other messages, but never the ones in the code above. So when is exactly this code supposed to execute? In which exact conditions?

Michel
  • 10,303
  • 17
  • 82
  • 179
  • Did you try to go to Settings->Twitter and delete all accounts from there? – Peter K Mar 30 '16 at 11:12
  • you need to setting account for use twitter post . goto : setting -> twitter -> add account – Hiren Dhamecha Mar 30 '16 at 11:14
  • I went to the settings and deleted my account. Of course, my function does not share on twitter in that case. But the message I get is not the one you would expect by reading the second branch of the if: this is what I find puzzling. It seems like the system is taking care of the "Twitter missing" before reaching my function. May be I am not reproducing the right conditions. Or this second branch (in case of failure) should not even appear in my function? – Michel Mar 30 '16 at 11:25

0 Answers0