I'm using the ngCordova LocalNotification plugin in my Ionic app and I am trying to get it to repeat but with a random time span.
For example the user will trigger the notification to launch in 1 minute, and after that I would need to have the notification launched again in another 2 minutes (hypothetical example, in real life scenario the time span would be much higher, ie a couple days).
So far I can get the notification to execute for the first time.
Then, I am using the $cordovaLocalNotification:trigger method to detect when the notification was triggered and inside of that method I have a code to schedule a new notification.
All of this works, but in order to launch whatever it is inside of that method's body, I have to acknowledge the notification on my device and click on it, then it launches this method.
So I am wondering if there's a way to have it schedule a new notification without me having to open the previous notification?
All of this has to happen locally on the device and the notification should persist even if the device is rebooted. Thanks a lot!
When the application go in backround, the webview stops the javascript execution. When you click on the notification, the app became a foreground process and javascript continue the execution.
So it seems that it works only when you click on the notification (that open the app) because only when the app is opened, the js code is executed.
You could double check this if you don't click on the notification, opening the app after the notification is displayed (without clicking it).
To clear all the triggered notification you could use the getTriggeredIds(scope) method to get all triggered notification IDs and the clear(ids, scope) method to clear them.
See the localNotification plugin documentation for more information.
Related
I have an application in which it receives the notification when fired from Backend. Now what I want to achieve is that the notification should disappear after 2 minutes if user has not clicked on it (even if my app is killed or background). I know that this can be achieved by using the Notification manager's setTimeoutAfter() but that will work only if am making my custom notification using Notifcation Manger.But i want to dismiss the Notification generated by System after 2 minutes.
Any kind of suggestion or help will be welcomed.
It is not possible to do that. The default system notification builder is pretty bare bones and will not handle it. The best you can do is set a delivery timeout so if the device was off it won't get the notification once it expires.
See https://firebase.google.com/docs/cloud-messaging/concept-options#when_to_use_platform_specific_keys (only works on Android and Web)
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
I am currently using version 0.11 of the AlarmManager module for my Titanium app (currently built with version 3.2.2 of the SDK). I am noticing some odd behavior when cancelling alarms, specifically when cancelling a notification after resuming the app. Here is the case:
In some cases, when the app is put into the background, a reminder notification may be set for a configurable amount of time in the future. If the user resumes the app before this notification fires, the app should cancel the pending notification, as the user doesn't need it. However, the notification is not being cancelled. Now, I see in the log that the module is attempting to cancel the notification (using the correct request code for the notification), and no error is thrown by either my app or the module, but, again, the notification is not cancelled.
In testing, if I create a notification via the module in the app, and cancel that notification without pausing the app, that notification is cancelled correctly.
I suspect this has something to do with a context switch when the app resumes (since the module relies on the app's current context when spinning up the notification service), but I'm not sure why this occurring.
The issue actually had to do with the type of the request code being sent to the alarm module's cancel function. If the type of the request code variable is not a number (as in java.lang.Number), the module uses a default request code, which would not match the code of the previously scheduled alarm.
I am using local notification plugin in my application. Here i set notification like alarm. Its working fine. what ever time i set in my database, alarms are working fine.
But while i force stop the application(Setting->Applications->Manage applications->MyApplication->ForceStop), next alarm is not coming. any one can help me?.. i tried with following link,
http://www.javacodegeeks.com/2012/05/android-broadcast-receiver-change-in.html
but still is not working.
force stop app will remove alarm associated with the app
so your pending task will never be done.
read in details:
http://blog.csdn.net/gemmem/article/details/8858461
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