Can I turn off/on push notifications through the app?

Hello,

Is there any way I can turn the push notifications on and off through the app? I know the app GroupMe does this so I was checking if Corona can do it.

Thanks,

Warren

You would need to communicate with your push provider and have them deauthorize the user.

Rob

If a user accepts push for the first time you can do as Rob suggests.

However if a user declines to receive push the first time he starts the app you can not enable it again without the user re-installing the app. 

Please vote for this feature request: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5881595-control-the-timing-of-allow-push-notifications-p

Voted. Thanks for the feature suggestion.

Thanks. I was just hoping I could control it through the app itself.

Warren

Most push providers have an API that lets you deregister the device.

Yes I was going to use GameThrive.com for my app. And with it I will have a SQL table with all registered devices. So I guess when the user selects to not receive push notifications I can have the app just send their info to a page I have written to turn it off and back on if needed.

Thanks!

@warrenwsav

As far as I know, there’s no way to intercept if the user has accepted/denied access in the dialog as it’s handled internally by the OS.

@warrenwsav

With the GameThrive plugin you can also add a tag to a user in your Corona app like ‘GameThrive.TagPlayer( “notifications”, “off” )’  Then create a segment for users with that tag and always exclude that segment when sending notifications.

Here’s some example screenshots:

Screenshot%202014-05-21%2022.22.43.png

Screenshot%202014-05-21%2022.23.17.png

@george18

The problem is still that it’s not possible to know if the user has chosen to accept/reject push notifications…

@ingemar

The tag setting in my example would have to be based on an in-app on/off button.

But for iOS it does assume that the user accepted push notifications from the native dialog. And unfortunately until jonjonsson’s feature request is addressed, the moment that the native dialog shows up can not be controlled (it shows up right away when the app is first started).

You can generally tell if a user accepted/declined push notifications in the native dialog starting with iOS7 though. There’s a callback that happens and if the user declined push then the callback will not have a device token passed to it. The caveats are that it will not work if their network connection is not available, and it will return a token even if they declined push notifications on iOS6 and below.

@george18

What I meant is that there’s no way for Pro subscribers to do that within Corona SDK.
Enterprise would be the only exception.

You can do it in all versions of Corona actually. Subject to the caveats in my last message of course.

Here’s how you can do it:

function notificationListener( event ) if ( event.type == "remoteRegistration" ) then     print(“The player accepted push notifications and here is their token: " .. event.token) end end Runtime:addEventListener( "notification", notificationListener )

(Or, if you’re using GameThrive)

function IdsAvailable(playerID, pushToken) if (pushToken) then print(“The player accepted push notifications and here is their token: " .. pushToken) end end GameThrive.IdsAvailableCallback(IdsAvailable)

Sorry, my bad!

We all learn something new every day  ;) …

You would need to communicate with your push provider and have them deauthorize the user.

Rob

If a user accepts push for the first time you can do as Rob suggests.

However if a user declines to receive push the first time he starts the app you can not enable it again without the user re-installing the app. 

Please vote for this feature request: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5881595-control-the-timing-of-allow-push-notifications-p

Voted. Thanks for the feature suggestion.

Thanks. I was just hoping I could control it through the app itself.

Warren

Most push providers have an API that lets you deregister the device.

Yes I was going to use GameThrive.com for my app. And with it I will have a SQL table with all registered devices. So I guess when the user selects to not receive push notifications I can have the app just send their info to a page I have written to turn it off and back on if needed.

Thanks!