I'm implementing OneSignal website push notification for my website. For now I just want to enable push notifications for the registered users. I had expected that there would be some callback methods after the users clicks "Allow" or "Block", but there aren't any. I see that I have to work with OneSignal.isPushNotificationsEnabled()
and OneSignal.push(["getIdsAvailablegetIdsAvailable",..])
, but I'm not sure how everything is supposed to come together.
What I think I should do is every time a registered users is at the homepage to execute something like this:
if isPushNotificationsEnabled
OneSignal.push(["getIdsAvailablegetIdsAvailable",..])`
send_user_id_to_server_where_it_is_saved_in_the_database
else
OneSignal.push(["registerForPushNotifications"..])
end
One thing that bothers me is that if this code gets executed and the user clicks "Allow" it will not trigger any code and a notification will never get to my server that the user has actually allowed push notifications. I'll have to wait for the user to come back or refresh the page. Is this how it's supposed to work or am I missing something?