Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created August 6, 2016 05:24
Show Gist options
  • Select an option

  • Save niwatako/5ffcf2f16ae214068d5e430f9f78b5c4 to your computer and use it in GitHub Desktop.

Select an option

Save niwatako/5ffcf2f16ae214068d5e430f9f78b5c4 to your computer and use it in GitHub Desktop.
TimelineViewControllerのviewDidLoadでTwitterアカウントをOSから取得 #CodePiece #realm_swift #realm_jp
override func viewDidLoad() {
super.viewDidLoad()
let accountStore = ACAccountStore()
let accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
accountStore.requestAccessToAccountsWithType(accountType, options: nil) { (granted, error) -> Void in
if granted {
let accounts = accountStore.accountsWithAccountType(accountType)
if let account = accounts.first as? ACAccount {
self.account = account
self.getHomeTimeline()
} else {
self.showAlert("No Twitter account")
}
} else {
self.showAlert("No account access")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment