Created
February 12, 2015 12:59
-
-
Save marchbold/a996665bc6ae0c7d4ff8 to your computer and use it in GitHub Desktop.
Check for permissions to access the user contact list
This file contains hidden or 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
if (Contacts.isSupported) | |
{ | |
Contacts.service.addEventListener( ContactsEvent.ACCESS_GRANTED, contacts_accessGrantedHandler ); | |
Contacts.service.addEventListener( ContactsEvent.ACCESS_DENIED, contacts_accessDeniedHandler ); | |
// Check if we have access to the user's contacts | |
if (!Contacts.service.hasAccess()) | |
{ | |
// If not, lets attempt to get access | |
if (Contacts.service.requestAccess()) | |
{ | |
// You will get an ACCESS_GRANTED or ACCESS_DENIED | |
// event dependant on the users response | |
} | |
else | |
{ | |
// They've denied us access previously ... | |
// To get access you'll need the user to manual set it in the device settings: | |
// iOS: Settings / Privacy / Contacts / [Your application name] | |
message( "Access has been denied by the user" ); | |
} | |
} | |
else | |
{ | |
// We have access so you can use the functionality | |
} | |
} | |
... | |
private function contacts_accessGrantedHandler( event:ContactsEvent ):void | |
{ | |
trace( "The user has granted access to the contacts" ); | |
} | |
private function contacts_accessDeniedHandler( event:ContactsEvent ):void | |
{ | |
trace( "The user has denied access to the contacts" ); | |
} | |
// com.distriqt.Contacts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment