Using the Twitter Account

Now let’s fill out the post-else case, replacing the simple success NSLog. We’re going to work with the accountStore that the user has graciously given us permission to use. Because it’s a local variable in scope at the time of the closure’s creation, we can use it within the completion handler closure.

On iOS, the user may have set up several accounts of a given type; a fancier app would show them and let the user pick one, but for now, we’ll just make sure there’s at least one. We can use the ACAccountStore’s accountsWithAccountType to get all configured accounts of type twitterAccountType. Code the following, directly before the }) that ends the closure.

Get iOS 9 SDK Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.