Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Created June 9, 2014 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sideshowcoder/8d9a3200a97e0364f9eb to your computer and use it in GitHub Desktop.
Save sideshowcoder/8d9a3200a97e0364f9eb to your computer and use it in GitHub Desktop.
def authenticate &block
account_store = ACAccountStore.alloc.init
fb_account_type = account_store.accountTypeWithAccountTypeIdentifier( ACAccountTypeIdentifierFacebook)
facebook_options = {}
facebook_options[ACFacebookAppIdKey] = @application_id
facebook_options[ACFacebookPermissionsKey] = ["email"]
account_store.requestAccessToAccountsWithType(fb_account_type, options:facebook_options, completion: lambda do |granted, error|
if granted
accounts = account_store.accountsWithAccountType(fb_account_type)
fb_account = accounts.last
@access_token = fb_account.credential.oauthToken
NSUserDefaults.standardUserDefaults.setObject @access_token, forKey:access_token_key
block.call fb_account
else
Dispatch::Queue.main.async do
alert = UIAlertView.alloc.initWithTitle("Account Error",
message:"There is no Facebook Accounts configured. You can configure a Facebook acount in Settings.",
delegate:nil,
cancelButtonTitle:"Ok",
otherButtonTitles: nil)
alert.show
end
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment