Created
January 11, 2018 20:50
-
-
Save destrichEG/edbaac368d8a9b3d297571cecd6823c3 to your computer and use it in GitHub Desktop.
Log OneSignal settings and send self notification if subscribed
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
OneSignal.log.setLevel('trace'); | |
function isPushNotificationsEnabledVerbose() { | |
Promise.all([ | |
OneSignal.isPushNotificationsEnabled(), | |
OneSignal.getUserId(), | |
OneSignal.getRegistrationId(), | |
OneSignal.getNotificationPermission(), | |
OneSignal.isOptedOut(), | |
OneSignal.context.serviceWorkerManager.getActiveState(), | |
OneSignal.getTags() | |
]) | |
.then(([isSubscribed, userId, registrationId, notificationPermission, optedOut, serviceWorkerActive, tags]) => { | |
console.log('Are they enabled:', isSubscribed); | |
console.log(""); | |
console.log('What is our OneSignal user ID?', userId); | |
console.log('What is our push subscription token?', registrationId); | |
console.log('What is the notification permission status?', notificationPermission); | |
console.log('Are you manually opted out?', optedOut); | |
console.log("Is a service worker registered and active? (should be false on Safari, otherwise should be 'Worker A (Main)')?", serviceWorkerActive); | |
console.log('What is the current URL of this page?', location.href); | |
console.log("What environment does OneSignal think it's in?", OneSignal.sdkEnvironment.getWindowEnv()); | |
console.log("The tags associated with the user are:", tags); | |
}) | |
.then(isSubscribed => { | |
OneSignal.sendSelfNotification(); | |
}) | |
.catch(e => { | |
console.error("Issue determining whether push is enabled:", e); | |
}); | |
} | |
isPushNotificationsEnabledVerbose(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment