Skip to content

Instantly share code, notes, and snippets.

@tsraveling
Last active April 26, 2017 18:34
Show Gist options
  • Save tsraveling/0c151bad9a2e78811b2c21354581ec55 to your computer and use it in GitHub Desktop.
Save tsraveling/0c151bad9a2e78811b2c21354581ec55 to your computer and use it in GitHub Desktop.
Twitter Integration

Twitter sharing

1. Install TwitterKit

Use Fabric. Make sure to reference the right app in info.plist -> Fabric -> Kits.

2. In VC:

Import:

import TwitterKit

Perform login thusly:

// Log in with Twitter
Twitter.sharedInstance().logIn { session, error in
    if (session != nil) {
        print("signed in as \(session!.userName)");
    } else {
        print("error: \(error!.localizedDescription)");
    }
}

Check extant token thusly:

// Check Twitter login
let store = Twitter.sharedInstance().sessionStore
twitterSession = store.session()

3. To log out:

Thusly:

let store = Twitter.sharedInstance().sessionStore

if let userID = store.session?.userID {
  store.logOutUserID(userID)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment