Knowing if an app is authorized to receive push notifications on-the-fly - iphone

Consider this situation. The app runs and application:didRegisterForRemoteNotificationsWithDeviceToken: receives information that the app is authorized to receive push notifications.
User puts app to background and removes app's authorization to receive notifications on the device's configuration.
User runs app again. Returning from background, the app still thinks it has authorization to receive push notifications. Neither application:didRegisterForRemoteNotificationsWithDeviceToken: or application:didFailToRegisterForRemoteNotificationsWithError: receives anything at this point.
Is there a way to know at any given point if an app has authorization to receive push notifications (reading something from device's notification preferences)?
thanks.

You can check for [[UIApplication sharedApplication] enabledRemoteNotificationTypes] each time the app returns from background.
See: iOS - Check for push notification support in the app
Once I have verified that the user has it disabled is there a way to programmatically direct the user to the notification settings on the device's configuration?
No for newer iOS versions. According to Navigate to settings screen in iphone and iOS Launching Settings -> Restrictions URL Scheme, you can use -[[UIApplication sharedApplication] openURL:] to navigate to settings screen, but only on devices running iOS version 5.0 and prior.

Related

Local/Push-Notification and launch app

I have faced problem in below scenario.
1) App is in background.
2) Push notification.
3) Launch app as per as push notification's text.(For the launch app i have use custom URL scheme)
Eq.I have register push notification in A.ipa and wants launch B.ipa via pushnotification.
Is it possible to launch application from Local/Push-Notification(iOS7)?
or
Is there any other way to communicate with background app and launch other app?
Thanks,
Use URLSchemes to launch another App(B) from your App(A). But B App should be registered with URL Schemes.
You can search for URL Schemes and go through the tutorials available.
Yes, it is possible to launch application from Local/Push-Notification. Actually, this is the default behavior.
Prior to iOS7, notifications were all "verbose", meaning that the user is presented an alert view which allows him to launch the app if he wants, or to dismiss the notification, leaving the application unaware. iOS7 has introduced silent push notifications, which launch the application without user interaction.

will push notifications work if user has neither allowed nor "not allowed" push notifications for my app yet?

I am currently updating my App, and I am planning on including Push notifications.
The main purpose for my push notification is to let users know that the app has been updated and they should check out the new features. Now with iOS7 automatically updating apps, users are less likely to open apps after they have been updated, let alone KNOW it has been updated. As a lot of users will just clear their notification centre's with out paying any attention.
So my question is...if a user has not launched my app yet to see the alert "[myApp] would like to send you Push Notifications" - Don't Allow / OK.
Will they see my push notification before they have had chance to allow or not allow?
Do push notifications work until "not allowed" has been pressed? Or do they not work until OK has been pressed???
Thanks for your help.
If they never launched your app, your app never registered to Apple Push Notifications on their device, so you can't send them push notifications.
In addition, your server is not likely to have the device token for a device in which your app was never launched (since it's the app's job to send the device token to your server).
And if you push a notification to a device token of a device on which your app never registered to push notifications, the notification won't be delivered (even if the app is installed on the device), and that device token will eventually be returned to you in the feedback service.

ios unregisterForRemoteNotifications does not work

I am trying to get my device unregistered from the remote notification services in my app, so I tried to use [[UIApplication sharedApplication] unregisterForRemoteNotifications]. But this does not work. My app still shows up on the notifications section of my iPhone's settings app. Is there any other way I can do this?
It is still there but it won't receive any notifications. That is the default behavior, once you registered your app will remain in the notification center and it will be activated/ deactivated when you register/unregister for remote notifications.
Unregister function is not related to iOS app setting.
Only if you turn on the setting and register notification by function, you can get the notification successfully.
If even one of them is off, you should not receive any notification.

Can I change APN settings from within app?

My app, makes use of APN services. At first launch, it sends a
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
request. This triggers a system alert with permission request. No matter what the user chooses, it will be possible to change it from Settings, notification pane. The app gets the notifications and everything seems to work fine.
Now I have been asked to place a switch inside the app to activate/deactivate push notifications from inside the app.
I don't think this is possible, but before answering I'd like to get a confirmation.
Is there a way to access (read and/or write) notification permissions related to a specific app from within the app itself (just like app defaults preferences)?
Is there a way to delete the app from the list of the apps which need push notifications once it has been added due to the initial request?
No, as it is a system setting relating to your app rather than an app setting. Otherwise any app could automatically enable all its notifications whenever launched, which would cause havoc.
Edit:
You can read your app's permissions using UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; and then performing a bitwise and operation with the different types to see which are enabled.

alert for allow or dont allow Apple push notification in iphone application

I am using Apple Push Notification in my application.
when my application is installed on device i want application to ask user if they want allow application to use notification or not, how can i implement so?
something like this application.
Thanks.
You don't need to do any extra work for that. Just configure your app for push notifications and call:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: types];
This happens automatically when an app asks to register itself for push notifications, just as it does when an app first asks for the device's location. You don't need to do anything special beyond the -registerForRemoteNotificationTypes: call (as Max mentioned) which you have to make anyway.