ios alarm functionality limited? - android

I have an app which is on Android and iOS. I have added a local notification to fire every 24 hours at a time specified by the user of the app. In Android, the local notification functionality is exactly what I need, but in iOS it seems to lack the functionality I need, unless maybe I am missing something...
Lets say the user sets the time the notification is to fire to 11:00am. In Android, at 11AM, it will wake up the app, go to the broadcase receiver and I am able to run code in a method that calls out to an API to fetch the latest data. Once it gets the data, it posts the notification to the user.
In iOS, it seems the data being posted to the user has to be pre-scheduled. So I have to create the notification message during scheduling of the notification. What I need is to be able to do something more like the above example.
So the problem is that at the time of when the notification is scheduled to fire, I need to check for fresh data, not the day before...
Any suggestions?

The same functionality doesn't exactly exist on iOS.
You can setup a local notifications using the functionality of a UILocalNotification object. With this you can set fireDate, etc. which is sort of like a push notification without a server. You can send a message, add a badge on the app icon, play a sound, etc.
Now the issue is that the app doesn't get launched by the OS. The app simply registers a notification in the OS, which is then handled at the fireDate time. This means you won't be able to have a chance to check for data and verify whether to continue with the notification, etc.
UILocalNotification Class Reference

Related

Retrieve push notification after coming back to online status. Firebase/Onesignal

I am using Firebase with OneSignal within an hybrid application (Android + JS with cordova app). In some cases the user may become offline and online while he is still using the application.
Note that you can't retrieve a push notification if you don't have connectivity.
So my question is, is it possible to retrieve a push notification if the another user sends a push notification while the first user is offline, and later on this first user retrieves the connectivity (As a delayed push notification)?
Thanks!
Internally, OneSignal uses Firebase Messaging Service, so the constraints should be looked for there.
Firebase has 2 types of pushes: notification messages and data messages. That matters if you want to show a notification straight when a push comes, or you'd like to do some additional processing beforehand.
Then, you can configure Firebase to store and resend every message up to 28 days. Of course, losing a network connection for some time does not prevent a message to arrive.
There is another limitation though: up to 100 messages can be stored per client. So, if there are more than a hundred, it's better to re-request the diff.
And then, when the device finally comes back to the network, you should decide if you'd like the notification to come immediately even if the app is already minimized or the device is sleeping. Here is a part about push priorities.
Finally, to be able to work with Firebase on this lower level, you may need to configure OneSignal accordingly. Here is an instruction telling how to work with the background notifications, if you need them.

iOS Swift 3: implementing chain of notifications emulating Android's AlarmManager

I'm implementing an app with an internal calendar, fetched from a remote web service. I want to send a local notification to the user when an event of interest is scheduled in the calendar, at a specific time chosen by him. Just like the iOS calendar app, when you can create an event and ask to be notified X hours/days before it happens. The main difference is that you can't create events: they are downloaded from a pre-populated remote calendar.
In Android I've solved the problem by using AlarmManager, while in iOS with Swift 3 the closest I've got to porting the same solution was via opportunistic background data fetch. The main difference between the two solutions is that background data fetch doesn't work when the app has been killed.
It would be really important for me that local notifications worked even when the app is killed. I think users expect apps notifications to work even when the app is closed, like it happens with WhatsApp or Facebook. I know that those notifications are triggered by someone writing something and therefore they are Push Notifications, but the average user just expects notifications to keep working even when the app is closed.
What would be the most elegant solution to "emulate" the behaviour of Android's AlarmManager in iOS?
Scheduling a bunch of notifications in advance hoping that the user will eventually open the app before all of them are dequeued looks a badly designed solution.
Also, delegating all the work to the server and push the notifications to the subscribed devices looks quite bad too as it requires much more work on the server side. Plus it requires a server which is able to awake itself to send push notifications, which is something that I don't have. I only have a simple webserver which answers to HTTP requests.
EDIT : The ideal solution I'm looking for isn't any of the previous 2 options, since I find them more like workarounds than actual elegant solutions to what I perceive being a fairly common problem. There has to be a third option...
In iOS there is no way to achieve this. Looking at the documentation of application(_:didReceiveRemoteNotification:fetchCompletionHandler:), it states that
the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
You can receive push notifications, but no code will be executed until the user launches your app. So unless you are sending remote push notifications from a server, you cannot set up new local notifications until the user opens your app.

Know if the app received the notification from server side

I'm building a newspaper-like app and I would like to know how many people received the article's push notification vs how many actually read it.
I was thinking to implement a way in which when the notification is received the app wakes up and send a request to the server saying "Hi I'm _____, I've received the notification of the article ____" and store it in the database. Then afterwards if the user click on the notification and goes to read the article I send another request saying "Hi I'm ____ and I've read the article _____" and I also store it on the database. Afterwards with some queries I'm able to understand the percentage read/received.
I don't understand if it's even possible to wake up the app even if it was not opened by the user in a while and send a request to the server (for background is meant that the application is not launched or that is in the cache ?).
I would like to achieve what they did with Whatsapp:
I receive a new message on Whatsapp
I don't open the app
I go to WhatsApp Web
I open the conversation on WhatsApp Web
The badge and the notification on the phone goes away because I read it somewhere else
I think that that feature is achieved with silent push notifications that just update the app badge and clear the read notification.
Thats a very nice question on how to implement such silent notifications. There are few variables here that we need to consider and deal them in a different way.
Push notifications sent to the users - Some of them would have received it, Some may not have received it at all.
Pushing multiple notifications to the same user in a small amount of time - It becomes difficult here to track the exact notification user opened the app. Because user might have read all the news that received notifications in a single attempt.
The actual content displayed to the user in the app - User might have opened the app because of notifications. Some times he might have seen the notifications and then opened the app directly without interacting with the notifications.
So this is how the implementation can be.
Implement push notifications for the app
User receives the push notifications and the notification badge shows Number (1).
Now when the user views the same news story in any other medium (Your own Mac App or PC app). Server is notified of the users action and the news he/she/whoever just read.
Now the server knows it has sent a notification and it is not read. When you receive the read notification, you can send a remote notification that can be handled by the app in background and update the badge.
Check out this link for more details on how to handle notifications in various modes.
Apple documentation also can be referred here for background mode - remote-notification.
So you will be making your app run in background with certain settings to respond to silent notifications and update the badge just like WhatsApp. I hope this helps.
I've already implemented such thing in one of my app, and it's actually tricky.
You'll have a lot of use cases to handle.
First thing (but you seem to already know it): Apple does not provide
any callback to say : "this notification was sent"
Second thing : when your app is killed (not even in background), nothing at all can be done with your notification, meaning your app won't be able to wake up and read the notification, and therefor do something. The only thing you can do is changing the badge number, even if your app is killed.
Third thing : when your app is in background, you can wake up your app during 30sec. During that time you can send a request to the server, but if it takes too long, the process will be killed by the OS.
Saying that, here is a quick explanation of how you could implement the system:
You'll need on the server side to save in your data base any notifications that were sent. As soon as they are sent, save them as "pending"
On the app side: if your app is in background, as soon as the notification is received, you can wake up your app to send a request to the server. Then in your data base, your notification status will change to "receive" or "notified". If your app was killed, when the user launch your app, send a request to the server to ask for all notification in "pending" state, that way your app will be up to date, as well as your badge number.
If the user click on the notification, this will open your app directly on the article, that way you'll be able to send a request and say to your server that the article was received and read.
If the user read your article on the web side, send a notification. Set the notification badge number with the number of actual "pending" notification in your data base.
Hope this will help you in addition of the answer of #Prav :)
try this Notification Listner service https://github.com/kpbird/NotificationListenerService-Example.
Reply from Apple Developer Technical Support:
Hello Matteo,
Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.
So at the end of the games IT'S NOT POSSIBLE
You want to sync your app with web app or website than once you send notification to application than set notification to particular ID.If user read that message from your web then send push notification again with different message and handle in service or broadcast receiver after that cancel notification if received message contains different message.you can also use Notification Listener.Refer thislink
Refer this link for ios.
Hi #Smile Applications after reading your question I would suggest you see OneSignal website. OneSignal will allow you to send notifications to your subscribed users. It will also show you how many users are using your app and how many of them have received your notifications. If you want to send notifications and track them from the app itself you can use their API. It is easy and I have implemented this in Android and soon will be implementing in IOS.
Now the second part of your question about knowing how to track how many users have read/opened your notification and on which activity they are on you can use Google Analytics. It will allow you to see from which part of the world your users are using your app and which activities of your app are being opened most. It is also easy and I have implemented this also in Android and soon will be implementing in IOS too.

How does an Android time based app work?

How does an Android alarm app or any other time based notifications app like Calendar, Clock, etc work? More specifically, how does it show up the notifications at exactly the time specified by the user? Does it constantly run in the background and as soon as the required time comes up, does it show the notification? Or does it schedule the notification in Android's kernel before exiting? I am working on an app that needs to give the user notifications at times specifies by him. I am not able to figure out how to do that.
Maybe what you mean is to create an alarm, you can see this example.

Should I use push or can I use local notification?

I have a Cordova app for Android and iOS which logs in a sqlite database when the user last opened the app. This data is also sent to a remote storage.
I want to alert the user that they haven't opened the app for x number of days and to do so.
For Android, that was pretty simple; I just scheduled a repeating AlarmManager, query the database and show a notification if the last open date was more than a day ago.
It doesn't appear to be so simple for iOS as, other than scheduled Local Notifications, there doesn't seem to be long running background tasks available, or anything similar to Broadcast Receiver.
Am I correct in thinking that for iOS, I will need to do the calculation of how long it has been since a user last opened the app within my remote datastore server, and then send the alert to the app via a push notification?
Or, is it possible to schedule a local notification and then have that do some calculations to decide whether to show itself?
The task is simple for both platforms by using local notification:
When the user starts or resumes the app, you do a datetime calculation and a predefinition when the notification should popup. That's it.
On next app start/resume, you remove the old notification and make a new setting for the next one.
I'm doing a similar task with this plugin: https://www.npmjs.com/package/de.appplant.cordova.plugin.local-notification

Categories

Resources