I am developing an application in which I want to snooze the received notification automatically for 10 mins, if user didn't take any action (neither dismiss notification, nor opened the app) on the previously displayed notification. This is required in iOS
You can't do that. Have you ever seen an app behave that way? No, because it's impossible (and incoherent).
Think of it this way. If the user does nothing, your app gets no signal that the notification fired. So it cannot "do" anything in response. You cannot respond to something that didn't happen.
Here's another way to look at it. When the notification fires, your app might not even be running. If the user does nothing, your app still won't be running. So how can it "do" anything?
In a comment, you referenced an app that has an "autosnooze" feature. But that app likely isn't snoozing in response to the fact that the user didn't do anything. It is scheduling a repeating notification (or multiple notifications) in advance, so the repetitions are already present when the user does nothing. When the user does respond, the app deletes the extra scheduled notifications. So you see, as I said before, the app responds to something that the user did do, not to something the user didn't do (though I can see why this behavior might give the illusion that it does what you asked to do).
Related
I want to develop an app, but before I actually start developing, I've been doing some research so that i can be sure it's going to work in the way I'd like to do this.
You can imagine the app as a kind of news app, where the user can indicate whether he wants to receive push notifications, and may also indicate that he only wants to receive a push notification if it is in X distance from his current location.
And this is probally a problem on IOS, On android it would be no problem if a push notification came in to read the current position of the user and settings and then show the push notification or not.
As far as I've read this is a problem on iOS, the system receives the push and the app can not respond to it unless the user clicks on it.
Theres also another problem about closing an app on IOS, ideally a app should not be closed (swiped out) by the user because this would be a force close on IOS.
From ive seen most users still swipe out apps, and this would mean that my app cannot run background tasks anymore.
This is what i thougt about:
Send Silent push, app download data on the background -> Check if this meets the user settings, if so show a local notification. (30 sec time to handle, but do not know if it is possible to throw a local push here too.)
The app sends data on the background over the user's current position before sending a push, the server checks for which apps it should be sent (actually no solution, too much data usage as it may be that the user is only one Specific location, need a good server if the app is used on thousands of devices.).
Does anyone have any idea how to handle this problem?
I am writing a task mgmt app that is using EKReminder.
Works perfectly when using on one iOS device.
When I use on two devices (same apple account), I realise that reminder changes sync is with significant delay and even often incomplete. (tried iCloud, google, company outlook)
This thus seems unrelated to my app (same happens if I change reminders directly in Reminder iOS app).
Can I programmatically force a sync of reminders with whatever service (e.g. iCloud) that they are linked to and trigger this out of my app?
#Losiowaty suggests a valid solution in the comments to the question, but I think there's a bit more information the following solution(s) could provide. To be fair, I have actually noticed this exact same issue specifically with the Apple Reminders app, and think that in general the solution applies to iOS but could carry over to the same notifications that have similar issues on macOS as well.
For iOS, though, the issue seems to be:
Two iOS devices on the same Apple iCloud account will both get a specific Reminder push notification. The issue is, though, that clearing that push notification on 1 device does not sync the second device properly in almost all cases as of right now. This is the question asked above's context, from what I understand.
The second, not as well recognized problem, from what I can tell, is that this problem is due to the fact the "host" application isn't properly clearing it's own push notifications, so to speak. What I mean by this is:
iPad and iPhone receive push notification from Reminders app about a 12:00 TODO item, at 12:00.
iPad push notification is acted on, marked as completed, and cleared on iPad immediately
iPhone push notification is still there (the issue we're attempting to solve), but will likely not be removed until itself is removed (opening Reminders app not from the push notification will often not clear this).
The reason for this is the push notification isn't being cleared by the application, and so even though it's now irrelevant information (since it was cleared after being marked as completed (or snoozed) on another device), but the push notification system doesn't know that (since pushes are just payloads of information, unless you properly use TTL on these, but that's a different answer). The way to fix that, that most/some apps use to an extent, could be:
1) As stated in the comment, in bullet point 2 the action (marked as completed, and cleared from device 1) could update the backend (iCloud in this case) that this item is complete, which then sends a silent push to all associated devices which properly clears the push notification (this would likely happen in a form of an application background task, something like a Notification Service Extension Apple link here (iOS 10+ only)
2) Another method would be to keep an internal "secret" key unique to each push notification you send (across all associated devices). You can then associate any one "task" object (in the Reminders app context as an example, but this can really be any data object held in your app) with a set of push notification "secret" keys (which can expire on a custom timer if you feel these are getting out of hand, especially since pushes will likely be viewed OR irrelevant after 30 days in most use cases). From this, along with a mechanism to make the application update it's data, if the app notices the device has any push notifications it shouldn't (based on the set of "secret" keys which are associated with "active" data), it should clear them for you. This ends up with the same result as method 1, but doesn't require a silent push (a socket can be used, or something else entirely), and could rely on a basic background job
It looks like either way, you need some kind of background task processing to act when something happens (either through a notification service extension as linked or through a simple background task that Apple supports).
I hope this answers your question and points you in the right direction for what you are building!
I am wondering if it's possible to do what the titles says. I have an application that has a refill reminder to refill your prescription drug via local notifications. I have seen that some apps (pill reminder apps mostly) push a notification if you have not taken your pill, or have not answered back to that notification, and was wondering if I can do the same if a user doesn't open/interact with the app after a certain period of time.
I have not began implementation but have thought about this thoroughly. What I am thinking of doing is having some sort of flag when the app is opened that removes that local notification and sets a new one once the app has gone in the background/inactive. The local notification would be set to three months from when the app has gone in the background/inactive. The question then becomes, how do I handle canceling all notifications after this notification has been received, regardless of whether the user opens the app at that notification or not?
If the user opens the app on that notification, I can have a check the method application:didReceiveLocalNotification and then handle the case where that local notification has been set and then use [[UIApplication sharedApplication] cancelAllLocalNotifications]
But if the user does not tap or open the app, how can I check and cancel all local notifications?
Sorry if this is a bit long or worded weirdly (sorry not good with words and explaining things). Let me know if you need more info or better explanation. Thanks in advance!
If I understand your question correctly, you want to know how to keep notifications from repeating when the user does not respond to a notification by opening your app.
You might consider configuring your local notification not to repeat. Instead, you might reschedule notification batches each time the application is launched.
Alternatively, if your application has a server-side component, you can use push notifications on iOS 7+ to wake your app, briefly. There is no equivalent to this behavior using UILocalNotification.
When didReceiveLocalNotification is called, I would like to know if it is because a user clicked the notification from outside of my app, or if it is called because my app was the foreground app when the alarm occurred. It is important to know the difference because in one case the user already got an alert with some info and doesn't need it again, in the other case they have not already received that info.
I am currently setting a flag in applicationWillEnterForeground and clearing in applicationDidBecomeActive. If the flag is set when didReceiveLocalNotification is called, I know it is coming from outside of my app and the user already saw the system notification in some form. However, I just noticed this flag will not be set if the user gets the notification, but doesn't click it yet (so it's just in the pull-down notification area), then clicks it from that area while my app is in the foreground. In this case my app is already in the foreground, so the flag is set.
Ideally there would be a property set on UILocationNotification that I can check to get this info.
I suppose I could use the fireDate and say if it is less than 1 or 2 seconds old, and flag is not set, then I am getting the notification real-time, not at a later time.. but I prefer something more robust if possible.
Edit: Right as I was clicking save I noticed the "related" section had this link:
iOS - Need to distinguish UILocalNotification in application:didReceiveLocalNotification:
Sorry for posting a duplicate question without searching more first (I did search, really!). Hopefully maybe this will get a better answer though, since that one doesn't really have a robust answer -- but maybe there isn't one.
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.