views:

344

answers:

1

Hi

I am building an app that uses the fine Urban Airship api to send the user push notifications.

The app keeps track of event dates that are added to the app by the user. This means I have no server in place for dealing with push, the app itself simply schedules a push notification with Urban AS when the user add the event date and time.

If the user decides to delete the event before it occurs I un-schedule it with Urban AS. All is good. I, however, would like to not send notifications to a user that has disabled notifications as these notifications are no free:)

I know the Push Notification API from Apple makes sure the user will not receive any notification if they turned them off in settings. They will simply ignore the scheduled notifications Urban AS sends, which is a waste of bandwidth and money.

How can I tell if the user has disabled the notification for my app?

Also, I see no other option than to test if the user has turned off notification and then tell Urban AS to cancel all notifications and if the user turns them back on, I will have to go through all events and re-scheduled them :/ each time the app runs.

Can anyone think of a way for me not to have to fill up my appDelegate with all kinds of conditional code for testing these scenarios? e.g. user has turned off push since last running the app, user has turned them on since last time. I am also concerned if the user will understand this behavior?

Guess I am just asking for a bit of best practice with this push / Urban Airship setup:) Thanks.

+1  A: 

As I see it, [[UIApplication sharedApplication] enabledRemoteNotificationTypes] will return the notification types the user has currently enabled for your app.

Otherwise, you are correct. You have to call this method on every app launch and, in the case that the user has reenabled notifications, reschedule all events that you had formerly deleted.

As to the question of filling up your app delegate with all kinds of conditionals, you might want to write a separate PushNotificationsController (not a UIViewController, just a NSObject subclass) that will handle all push-related stuff.

Ole Begemann
Thanks Ole.Yes I will surely put it in its own Controller. I just meant that I test for a ton of other stuff when the appDelegate receives the applicationDidFinishLaunching message.I will see if I can think up something lightweight that keeps track of the users push preferences from launch to launch and acts accordingly.Thank you again for input.
RickiG