ios unregisterForRemoteNotifications does not work - iphone

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.

Related

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.

'Alert Style' option missing from Notifications settings

I have set up an iOS app with push notifications.The problem is that the app ignores notifications while not being active or more precisely banners don't show up.One stranger thing is that the 'Alert Style' option is missing.
I wonder whether the .entitlements file is necessary and should I define something there.Except for that I think all settings are made correctly.
The environment is production.
All push notification are handled by iOS not your app, iOS will deliver the push notification to your app after the user clicked/swiped the view option.
Did you set the correct type of notification, UIRemoteNotificationTypeAlert for alerts(banners) when you register for notifications?
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound)];
More you can't set the 'Alert Style', the user can do this in settings app. You can't force the way Notifications are presented.

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.