Created
June 9, 2014 10:48
-
-
Save sideshowcoder/8d9a3200a97e0364f9eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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