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.
Related
I have many users complaining that when they migrated from iOS 10.3.3 to iOS 11 launched yesterday, they stopped receiving silent push notifications.
One thing is to be noted that, I have a setting in NSUSerDefaults if I have already asked the user for registering for push notifications. And I do :
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
Only if the user hasn't been asked before.
Now if user had already registered for notifications when he was on iOS 10.3.3, and upgrades to iOS 11, the code registerUserNotificationSettings:settings will never be called for him, until he reinstalls. Could that be an issue? However, I believe it is unnecessary for him to register again as he already is.
So how do I fix this?
From documentation:
It is recommended that you call this method before you schedule any
local notifications or register with the push notification service.
So it is advised to call it at least once per app launch, but before your server sends the push notification.
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.
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 have two apps that received Push Notifications. I upgraded both to Xcode 6, and one works fine, the second one does not ever ask the user for permission to receive Push Notifications, nor does it receive the notifications.
I did update the code in the appDelegate to the new iOS 8 calls:
// register for push notification
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeSound];
}
And I believe it is working correctly because didRegisterForRemoteNotificationsWithDeviceToken is being called and I am getting a DeviceToken.
I have:
Recreated (several times) my IDs and Provisioning profiles.
I am testing this on the device, not the simulator
I have tried to load it onto a iOS 8 AND iOS 7 device, neither works.
Checked to make sure that the PN is being sent by PARSE (which I am using to create the PN's). They are. And they are received on the second App.
Pushed up the date on my phone, restarted it, and reinstalled the app (had deleted it first).
Also, the App is listed in the notifications section to receive notifications.
Any thoughts?
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