Created
February 10, 2015 06:32
-
-
Save marchbold/fb0438cf326a44cea0cf to your computer and use it in GitHub Desktop.
The suggested usage of the isEnabled flag
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
var hasRequestedPermissionsOnce:Boolean = false; | |
// You should load hasRequestedPermissionsOnce from some persistent storage, defaulting to false | |
... | |
PushNotifications.init( APP_KEY ); | |
if (PushNotifications.isSupported) | |
{ | |
if (PushNotifications.service.isEnabled) | |
{ | |
// Notifications have been enabled by the user | |
// You are free to register and expect a registration success | |
register(); | |
} | |
else if (!hasRequestedPermissionsOnce) | |
{ | |
// You should implement hasRequestedPermissionsOnce somewhere to check if this is the first run of the app | |
// If we haven't called register once yet the isEnabled flag may be false as we haven't requested permissions | |
// You can just register here to request permissions or use a dialog to delay the request | |
register(); | |
} | |
else | |
{ | |
// The user has disabled notifications | |
// Advise your user of the lack of notifications as you see fit | |
} | |
} | |
... | |
private function register():void | |
{ | |
// You should save hasRequestedPermissionsOnce to a shared object, file or other persistent storage | |
hasRequestedPermissionsOnce = true; | |
PushNotifications.service.addEventListener( PushNotificationEvent.REGISTER_SUCCESS, registerSuccessHandler ); | |
PushNotifications.service.addEventListener( PushNotificationEvent.REGISTER_FAILED, registerFailedHandler ); | |
PushNotifications.service.register( GCM_SENDER_ID ); | |
} | |
// com.distriqt.PushNotifications |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment