Postpone Apple push notification approval from startup - ios

Is it possible to postpone the first time app startup request, about allowing apple push notifications: "X would like to send you push notifications" ("Don't Allow / OK")
I seems to remember having see apps before, where the request first popped-up after a pre conditional action. Is it possible to postpone the request from startup to a time where the user has done a pre conditional action, and the user then knows why they should/shouldn't allow push notifications for this app?
It is also regarding the thought that most people would reject it, if it is the first thing that pops up after they opened an app for the first time, and they have no idea why the should allow it.

Just call
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:notifTypes];
when you want the user to enable push for your app.
That's when the popup will show.

Related

What is the best way to notify backend that push notifications have been disabled?

What's the best way to notify a backend that a user has disabled push notifications?
I've been playing around with a few options but I'm not sure which is the best one to proceed with:
Option 1:
Check if the user has disabled push notifications in the applicationDidFinishLaunching method like this:
UNUserNotificationCenter.current().getNotificationSettings { ... }
The only pitfall to this is let's say a user disables push notifications, and then never reopens the app. The applicationDidFinishLaunching method will never get called and therefore my app will never realize notifications were disabled and won't act appropriately.
Option 2: Is there a way backend is able to check if notifications have been disabled?
Ok, so after looking through the docs I may have figured it out.
Apple should send a 410 status code if the device token is no longer active which means that the user must have stopped push notifications or deleted the app.

Unregister remote notification on logout

About unregisterForRemoteNotifications
From the apple doc
You should call this method in rare circumstances only, such as when a new version of the app removes support for all types of remote notifications. Users can temporarily prevent apps from receiving remote notifications through the Notifications section of the Settings app. Apps unregistered through this method can always re-register.
Some are saying:
Calling it would at times put the app in a state where calling
registerForRemoteNotifications would no longer work.
Why did apple tell us to use it in rare circumstances only and gave such an extreme example of if new version of app removes push notification support completely. Isn't it fit for the logout button action?
In our app users can login with multiple devices. It would be lot easier if unregisterForRemoteNotifications works well. Anybody using unregisterForRemoteNotifications on logout button?
Yes, You can use unregisterForRemoteNotifications on Logout.
This function is used to unregister all the notification from Apple Store.
You always can re register to notification with registerForRemoteNotifications and start receiving the push notification. And that you may need to do it in your success Login.
If you read that sentence from Apple Doc carefully than its last line clearly says that Apps unregistered through this method can always re-register.
They are suggesting developers if they dont want to receive push notification for some time than they can just simply disable from the settings. But for login and logout session you are doing right with by calling unregisterForRemoteNotifications
And New version will stop receiving notification means after your logout you will never receive any notification till you re register for it.

Is Silent Remote Notifications possible if user has disabled push for the app?

In my settings tabbar:
I have a feature specific switch which can be turned OFF or ON based on API response.
From website only admin is authorized to turn ON/OFF.
I can make /user API call everytime on settings tap to check the current settings for the user but there are couple of disadvantage like if user is already on setting then it will not update the UI and calling api everytime on settings tap doesn't sounds a perfect solution.
I think better solution is to send a silent push notification which i can use to make the API call to update the settings UI whenever needed.
But if user has disabled the push notification will I still receive silent push ? What is the recommended approach to handle such situations ?
Short answer, yes
The exciting new opportunity for app developers in iOS 8 is that Apple will now deliver “silent” pushes even if the user has opted out of notifications. Also, “silent push” is no longer just for Newsstand apps. Every app can take advantage of this ability to refresh content in the background, creating the most up-to-date, responsive experience possible, the moment the user opens the app.
Although...
Users still have the ability to switch off your app’s ability to process a “silent push” by means of the “Background App Refresh” control. Even though Apple Push Notification service (APNs) will deliver a push marked “content-available” to your phone, the OS will not wake up your app to receive it, effectively dropping it on the floor. However, opting out of “Background App Refresh” is a lesser-known capability not directly associated with Notifications. You don’t access this preference in your Notifications Settings--it’s located under General > Background App Refresh screen.
Keep this in mind when building your application.
Source:
https://www.urbanairship.com/blog/watch-list-ios-8-opt-in-changes
This matrix might help. At left hand side, it shows if "didReceiveRemoteNotification: " method will get called or not. Other two columns is related to setting app. Settings -> YourApp. If yourApp supports Notifications and background app refresh. Look into matrix to check when you app will receive silent push.
Other answers are good. But they are not official answers.
The official answer is in What's New in Notifications WWDC 2015 video:
Silent notifications are enabled by default. The user does not need to
approve your -- does not give permission to your app to use them, and
you can just start using them without asking the user for permission.
But silent notifications are the mechanism behind background app
refresh. At any point you know that the user can go in settings and
disable them. So you can't depend on them always being available. You
don't know if the user the turn them off, and you are not getting a
notification anymore. This also means that silent notifications are
delivered with the best effort. That means that when the notification
arrives on the user's device, the system is going to make some
choices.
For more see this image and this answer

iOS - Ask to enable push notifications after initial decline

I would like to know if it's possible to force the "XXXXX would like to send you push notifications" popup from within an app, after an initial decline. The use case is as follows:
The user installs the app, gets the alert about push notifications,
and declines because they don't know/trust the app yet.
They use the app and proactively request within the app to be alerted
when something happens (say for example something they want to buy is
sold out so they want to be alerted when it is back in stock).
So now the user has asked the app to notify them about something
specific but has push notifications disabled at the operating system
level.
So if the user requests an alert, but I detect that they declined
alerts on first run, I need to notify them of this and have them turn
push notifications on for the alert to work.
Ideally, I would like to force the "XXXX would like to send you push
notifications alert" at this point (a second time since they
installed the app).
I guess plan b would be to show them my own message telling them they
have to go into their system settings and turn it back on manually in
order to receive the alert they want. This is far from ideal.
Any help would be appreciated. Thanks.
You can't make iOS show the alert again. Here's a better approach:
Keep a flag in your NSUserDefaults indicating whether you should register for push notifications at launch. By default the flag is false.
When you launch, check the flag. If it's true, register immediately. Otherwise, don't register.
The first time the user does something that would cause a push notification, register for push notifications and set the flag in NSUserDefaults.
This way, when the user gets the push notifications alert, he has some idea why he's getting it, and might actually say yes.
I am also facing a similar kind of issue. After searching so much, I decided to do what you call Plan B. That is, show the user my own alert saying that push needs to be enabled for better experience, or something like that.
To check that required push types are enabled, use this method:
- (UIRemoteNotificationType)enabledRemoteNotificationTypes
UIApplication reference
I think that this is the clean solution. Consider a case where after accepting the request at first, the user turns off push, this thing will work even in that scenario.
The best way to do it would be to (if you're making a game) ask them a preemptive question (e.g. Do you want us to notify you when your crops are ready to be harvested? -Yes -No), and when they answer "yes", then fire the native iOS push popup. then you can layer in multiple questions along the user funnel, and you'll eventually catch them all.

Can an application receive a push notification while in the background without the user being informed?

I've read the Apple Push Notification documentation and it seems this isn't possible but was just wondering if there are workarounds etc.
If an application is in the background and a server sends a push notification, if there any way the application can receive an inidcation of that fact independently of the user tapping the action button?
No, that's not possible. The application does not get to know about an incoming push notification unless the user activates it with the action button.
No - but if the app is in the background, you can still use the network if you enable multitasking.
With Apple it's always pretty simple: if something is not possible, there won't be workarounds.

Resources