I have a IOS settings screen (on ios 8.0) which gets generated using this code:
[[UIApplication sharedApplication] registerUserNotificationSettings:
[UIUserNotificationSettings settingsForTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)
categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
the result looked like this it seems:
My goal is to remove just the notifications area but i'd like to let the privacy and 'use cellular data' remain.
On the simulator there is no privacy and 'use Cellular Data' appearing. Is this whole issue because im on a simulator ?
If you use "registerForRemoteNotifications" this settings will be there automatically and can't be omitted. You are not allowed to disable user notifications settings if you want to use notifications.
This could be out of date, but according to Technote 2265:
Resetting the Push Notifications Permissions Alert on iOS
The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.
If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by following these steps:
Delete your app from the device.
Turn the device off completely and turn it back on.
Go to Settings > General > Date & Time and set the date ahead a day or more.
Turn the device off completely again and turn it back on.
Related
I have an iOS app with push notifications enabled using following code
if ([application respondsToSelector:#selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
When this app is run on iOS9 device it asks for permissions in the beginning just fine, but when used on iOS7 , iPhone 4 it doesn't ask for permissions but it receives the notifications just fine, not able to understand the issue.
Seeing as your user is receiving the push notifications despite not being presented a permission dialogue, following must be the scenario:
He had a previous build on his iPhone 4s which he had authorized for push notifications.
He quickly uninstalled the previous build and installed the latest build you gave him, without giving a period of one day to device before reinstalling.
Result was that he wasn't presented any dialogue asking for push notifications permissions as the permissions were already granted previously.
According to Apple Technical Note 2265:
The first time a push-enabled app registers for push notifications,
iOS asks the user if they wish to receive notifications for that app.
Once the user has responded to this alert it is not presented again
unless the device is restored or the app has been uninstalled for at
least a day.
If you want to simulate a first-time run of your app, you can leave
the app uninstalled for a day. You can achieve the latter without
actually waiting a day by following these steps:
Delete your app from the device. Turn the device off completely and
turn it back on. Go to Settings > General > Date & Time and set the
date ahead a day or more. Turn the device off completely again and
turn it back on
If you ask your user to check for app specific permissions in settings menu, He will certainly see the Push permissions. Otherwise he would not have been receiving push notifications at all.
I can't seem to get a prompt to show for registerUserNotificationSettings in iOS 8.1 or 8.2.
Here is what I'm doing in didFinishLaunchingWithOptions:
if ([application respondsToSelector:#selector(registerUserNotificationSettings:)]) {
#ifdef __IPHONE_8_0
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert
|UIUserNotificationTypeSound | UIUserNotificationTypeBadge) categories:nil];
NSLog(#"Reg settings %#", settings);
[application registerUserNotificationSettings:settings];
#endif
}
Also getting the correct call back here:
- (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
NSLog(#"Did register - %#", notificationSettings);
}
Yet no prompt is ever displayed. What's even more annoying is that an alert will display when the device is locked, but won't give the notification alert sound. Any ideas on a work around?
Update for iOS 11+:
Since iOS 11 Resetting the Push Notifications Permissions Alert on iOS procedure seems not to be necessary anymore. Just un-/reinstall the app.
Using your code, I get the prompt on the first app launch, and only on the first launch. But afaik, that's the expected behavior in iOS.
At least it's the same for photo library, microphone access etc:
Permissions Prompt Behavior
Popup on first usage (or at least the request to use it)
Apple adds an entry in settings (e.g. Privacy, or just under Settings for notifications)
First usage
In the Settings App you can configure Notifications for each app
Scroll down, select your app
Select Notifications
Enable/Disable them, or adjust their behavior
Resetting the Push Notifications Permissions Alert on iOS
The first time a push-enabled app registers for push notifications,
iOS asks the user if they wish to receive notifications for that app.
Once the user has responded to this alert it is not presented again
unless the device is restored or the app has been uninstalled for at
least a day.
If you want to simulate a first-time run of your app, you can leave
the app uninstalled for a day. You can achieve the latter without
actually waiting a day by following these steps:
Delete your app from the device.
Turn the device off completely and turn it back on.
Go to Settings > General > Date & Time and set the date ahead a day
or more.
Turn the device off completely again and turn it back on.
Source: https://developer.apple.com/library/ios/technotes/tn2265/_index.html
Change build target latest version you will see the popup message.
Same issue with me in iOS 8 its not showing, but in iOS 10 its showing the alert pop message, This alert message will be displayed only once for the application cycle. Unless you delete and reinstall new one.
- (void)registerLocalNotification{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
If anybody is still stuck, toggling the options worked for me. It was this
UNAuthorizationOptions options = UNAuthorizationOptionAlert & UNAuthorizationOptionSound;
and I changed it to this
UNAuthorizationOptions options = UNAuthorizationOptionAlert;
and back to
UNAuthorizationOptions options = UNAuthorizationOptionAlert & UNAuthorizationOptionSound;
I removed the use of local notifications from my app, but it still appears in the iOS Settings -> Notifications. If I do not use local notifications, it makes no sense to show the app in the settings.
Is there a key in info.plist or anything that I have to delete?
The deployment target is iOS 7.0.
Thanks for help.
Try to unregister user notification settings (iOS8+) by calling
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)]) {
[[UIApplication sharedApplication] registerUserNotificationSettings:nil];
}
I hope you can help me troubleshoot my issue.
When I install my app, I don't get the message alert asking for the authorization to get push notifications.
I am thinking that if I don't get this message it's not my code to be wrong, but maybe it's a matter of certificates.
Am I right? How can I check if my provisioning file is correct?
I am using Xcode 5 and testing on ios7.0.2
I add a little more: I was never able to get the alert working
I had this issue when developing an app, it turned out I'd not set the entitlements up correctly. So make sure you have in your AppDelegate:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Make sure in Developer Center you've generated an AppID for your application as well, specifying that you want to use Push Notifications. Then you need to generate a Provisioning Profile to use for development/deployment with the device ID you want to install it on. Then you need to bring that Provisioning Profile into Xcode, and apply it to your project within the target build settings. That should bring up the Push Notification alert view to get the permission for the app to use push notifications. You then get the fun of setting up the SSL certificates but that's a whole other topic.
I found the Ray Wenderlich Push Notification Tutorial incredibly helpful when I went through it, I'd recommend following through if you're finding yourself stuck.
Edit; also keep in mind Push Notifications do not work on the Simulator, you must test them against an actual device as you won't see the alert view at all on the Simulator.
If you accept or decline it once this screen would not appear again. Go to setting and check permission for push notifications for your app.
Settings->Notifications->YOUREAPP
In order to see the alertView:
uninstall the app
set the device date to at least 1 day after the current date
Reboot the device
Install and launch the app
My app uses push notifications. If the user says no to push notifications when they install the app, but then a few days later decides they want push notifications, how do I program that option in the app in a settings? Do I just call registerForRemoteNotificationTypes (actually AppDelegate does this every time the app is stated) ?
You can't. The user has to go into settings on the device and allow notifications there.
You can see if notifications are enabled with the enabledRemoteNotificationTypes property of UIApplication and prompt the user to go to settings, but this would be incredibly spammy. You'd be better off having some text in a settings screen.