ionic 4 local notifications when app closed - ionic-framework

I need to call my local notifications at a predefined time. This is working when my app is not closed. but once I closed the app, the notification is not working.

have you resolved this issue?
What you can try:
check if your app autostart/notification permission is enable.
Sometimes, depending on your device model, the autostart permission is
disabled by default, so if the application is closed you can not
receive notifications.
I had the same issue before.
Go thru this thread, where one user commented
On Mi4, with or without the every, after the app is exited,
notifications not received.
On Samsung S5, with "every" notifications stopped after the app
exited. Seems to be fine if scheduled without "every".
As stated in katzer
It might be possible that the underlying framework like Ionic is not compatible with the launch process defined by cordova. With the result that the plugin fires the click event on app start before the app is able to listen for the events.
So, what has work for me is to set in app.component.ts:
window.skipLocalNotificationReady = true;
subscribeLocalNotifications() {
this.localNotifications.on('click').subscribe((notification) => {
});
this.localNotifications.on('trigger').subscribe((notification) => {
});
this.localNotifications.fireQueuedEvents();
}

First you have to make your app can run at the background when you close your app.
Second you have to schedule the local notification through the condition you want. E.x: When you don't have wifi connection , push the notification with user
Did you use cordova-plugin-local-notifications?

Related

iOS, Can I schedule a local notification and notice it in AppDelegate with the app running in background?

I'm using local and silent remote notifications in the app I'm working at work. I need to launch some methods according to events received from our servers or from the app itself via silent remote and local notifications respectively. I have no problem with remote notifications with the app in foreground, background or with the notification touched but I can't get the scheduled local notifications to be noticed by AppDelegate if the app is running in background (I mean, without user tapping the banner).
Is this even possible? If yes, which parameter should I add to the notification or what method is supposed to be called when it arrives?
I don't think it's possible to send a local notification that runs silently and starts your app. The normal way to do things like this is Background App Refresh:
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/updating_your_app_with_background_app_refresh
You have no control of the time. iOS will periodically give you short slices of time

IOS background work

I have an iPhone application like facebook for iPhone. My application must connect my server and read all message every two hours regularly. I have a thread to read all message but when the application is terminated the thread cannot work. Can the thread run undependently from main delegate or how can I find solution for this problem?
You cannot have your app do stuff in the background. There is an API to finish tasks like uploading a photo but even that will be killed after around 10 minutes.
But the Apple Push Notification Service seems like the most appropriate solution for your problem. Your server notifies the device that there is something new happening and you fetch the actual messages when the user opens the app.
edit: As of iOS 7 Apple implemented a feature where you can schedule running tasks to fetch data in the background. Those tasks are not guaranteed to run at any specific times. See the release notes for iOS 7 and the linked methods below:
Apps that regularly update their content by contacting a server can
register with the system and be launched periodically to retrieve that
content in the background. To register, include the UIBackgroundModes
key with the fetch value in your app’s Info.plist file. Then, when
your app is launched, call the setMinimumBackgroundFetchInterval:
method to determine how often it receives update messages. Finally,
you must also implement the
application:performFetchWithCompletionHandler: method in your app
delegate.
There is no solution.
Apple does not permit applications to run in the background unless they are of a specific type such as location or audio or voip or newstand (your app can continue to run for about 10 minutes after it was active if it uses shouldBeginBackgroundTaskWithExpirationHandler).
There is no workaround, many many other people have wondered how to do the same thing as yourself before, but there is no legitimate way. Your app cannot schedule any sort of periodic call home activity.
The only way your app can run once its gone into a suspended or terminated state is for the user to launch it, either explicitly or in reponse to a local notification or remote push notification.

How to invoke a method daily at a specific time in iPhone application?

I want to invoke a method daily at a specific time in my iPhone application.
How can I achieve this?
There's not a whole lot you can do with the iPhone SDK and a closed app. You can have it send local push notifications at specific times, but that won't execute your code until the user manually opens your app.
See this related question recently asked: Is it possible to have my closed app run code in iOS?
One thing I've seen apps do (like alarm clock apps, etc) is have you leave your app open and just let the phone fall asleep and then it will still execute code when you want it to. But that only works as long as the user doesn't hit the home button.
Schedule a local notification. This is how most basic alarm apps work. The app needs to be running sometime before the method execution time to schedule a local notification. After the local notification has been scheduled, the app can be closed and the method will be invoked at the specific time.
If you have push notifications configured, then your app does not need to run at all to schedule the method. It can all be done from another application.
Check out this documentation on local and push notifications from Apple.
you cannot run a specific code inside your application when its not running ..iOS allow only limited functionality to be run in background or when app is quit.

Making the app give an alert without running in the background or using notifications?

I'm wondering if it's possible to make an iphone app give the user an alert in a certain time without being run in the background or using notifications?
I see it happening in an app called iPray Pro. It gives an alert for the prayer time even though it's not running in the background or using notifications. I checked under the Setting-Notifications and the app is not there at all.
How is it done?
Scheduled local notifications will trigger even if the app is closed. iPray probably schedules notifications for a given time which are then triggered by the OS without the app having to be open.
Look for Local Notifications in the iOS documentation. They are like push notifications, but don't require a server. They are quite simple API to use too; make a UILocalNotification and use the scheduleLocalNotification: method on UIApplication to add the notification onto the system.
It will then fire in accordance to the fireDate property of the local notification you scheduled.
Local Notifications require iOS4.0 or later.
It is using Local Notifications, not Remote Notifications.

Push notification and launch application for Iphone4

I have an APNS enabled application.
In Iphone4 when user press the HOME button application remains in cache.
Now in this condition when a push notification received after clicking on the VIEW button
the application starts running from the cache!!!.
I have found that it is invoking didReceiveRemoteNotification() and also the state of the application is UIApplicationStateActive rather than UIApplicationStateBackground
But in Iphone 3 it is working fine and invoking didLaunchingWithOptions().
What I want is when the application is not open(currently not running) , if a push notification received it will invoke the handler for push notification and launch the application from start.
any help or guidelines will be highly appriciated .
As far as I know, the application is in SUSPENDED state after tapping home button (after several transitions). So it is not executed (moreover it can be terminated in case system low memory warning).
Your possible solution is to set up the key "Application doesn't run in background" to imitate iOS3 behavior (in your .plist file).
Maybe this link will be useful for you:
iOS 4 backgrounding
If your phone is connected to your MAC and you are debugging then that is the thing that cause your problem, so try disconnect your iphone and try again, that will solve the problem.