Can I change APN settings from within app? - iphone

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.

Related

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.

Do Local Notifications need user permission on iOS?

I am using UILocalNotification in my app to schedule notifications. The notifications work fine and show up when I want them to. I dont have an issue with that. I am NOT doing any remote/push notifications.
What got me wondering is that I never saw the famous permissions dialog that you usually see for push notifications in several app. I even reset my device and ran my app. That still didn't cause the permission dialog to show up.
Does this permission dialog not show up if your app is using only local notifications or am I not implementing some method that actually causes the app to ask for this permission?
I know I could implement my own dialog after the app started that asked the user for this permission but I was hoping that Apple took care of that, especially since it treats remote and local notifications the same in the Settings app.
Yes, in iOS8, local notifications do require permissions.
The documentation for registerUserNotificationSettings: stipulates that
If your app displays alerts, play sounds, or badges its icon while in the background, you must call this method during your launch cycle to request permission to alert the user in those ways.
Typically, you make this request if your app uses local or push notifications to alert the user to new information involving your app.
It is recommended that you call this method before you schedule any local notifications or register with the push notification service.
It looks like local notifications do not need any user permission. The Permission dialog just shows up for the Push Notifications. I am able to schedule/cancel local notifications without any user permission.
NOTE: this includes push notifications / remote notifications
when using Xcode6 with iOS7 or iOS8
Test when registerUserNotificationSettings: API is available at runtime.
if ([application respondsToSelector:#selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
Thanks to http://corinnekrych.blogspot.ae/2014/07/how-to-support-push-notification-for.html
Apple's documentation for presentLocalNotificationNow and scheduleLocalNotification says,
Prior to scheduling any local notifications, you must call the registerUserNotificationSettings: method to let the system know what types of alerts, if any, you plan to display to the user.
So I am not sure how others in this page are saying Local Notifications do not need User Permissions.
Checkout this other discussion on the same topic:
Ask for User Permission to Receive UILocalNotifications in iOS 8
Yes, that's correct. Local notifications do not need any OS permissions. However, as a good practice, I'd suggest giving an opt-out option for the user in such cases from your application.
This would work well in two ways:
An annoyed user, getting frustrated because of seeing local notification yet time & again, not knowing the difference between Push/Local notification might leave a bad review on the app store.
Its always a good practice to provide flags to turn ON/OFF such functionality for a given user.

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

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.

Obtaining user consent for Push notification alert view doesn't show on first time launch with my app

In my app, i created a develop provision profile with Push Notification enabled, and i put it to work by adding code
[application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert];
in my app -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
The push notification works fine. the problem is: for the first time i ran my app on my device, there was supposed to be a alert view to ask the user whether they allow the Push notification or not. But this alert option doesn't show, i have deleted my app from my iphone and re-installed many times, never had a time show this alert view for the first time running, the app just go straight to register the push notification.
As in the App Review Guideline:
5.3 Apps that send Push Notifications without first obtaining user consent will be rejected.
my app will be rejected due to this issue.
Please check following conditions:
Instead of using "application" you can use "[UIApplication sharedApplication]" in your code.
For ex:-
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
It usually happens with the apple device's, if once you click allow for notification confirmation & though you delete the app, next time it won't ask for the confirmation(not show the notification alert). But this happens only in case of development profile. If you install the app from app-store(which use distribution profile), it will ask the confirmation each time after installation.
Also check the settings of device on which you are testing notifications, the Notification center should be always "ON" for the notifications.

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.