Skip to content

Instantly share code, notes, and snippets.

@destrichEG
Created January 11, 2018 20:50
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 destrichEG/edbaac368d8a9b3d297571cecd6823c3 to your computer and use it in GitHub Desktop.
Save destrichEG/edbaac368d8a9b3d297571cecd6823c3 to your computer and use it in GitHub Desktop.
Log OneSignal settings and send self notification if subscribed
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