Is it possible to send SILENT LOCAL notification on iOS
Asked Answered
A

4

20

My app wakes up from suspended mode on silent remote notification from a server, exactly as I want. This server sends a push notification with "content-available:1", which does the job.

Now I want to do this without the help of a server and so I want to send silent local notifications (from the app) at a time in the future (like after 15 min.), but can't find a way to set "content-available:1". So I end up getting local notification that doesn't wake up my app, as I can with remote notification.

I've searched for information and all I can find are examples of interactive notifications and how to set title, body, alert and triggers (based on location, date and so on.). But nothing about how to set content-available property.

So, is possible to set content-available for local notifications?

Abreact answered 6/7, 2017 at 9:4 Comment(3)
A local notification only launches your app if the user taps the notification. A silent local notification therefore makes no sense, and it isn't possible.Kherson
@Kherson I'm not talking about launching the app, I'm talking about waking up the app from suspended mode.Abreact
You can setup a local notification with your specified time and by this way you can wake your app.Pears
A
8

It's just not possible without user intervention. There is no Android's AlarmManager kind of solution to wake up the app from suspended mode in iOS. In iOS there's no way to periodically wake up app from suspended mode, except from remote push notification (if an extern application sends a push notification periodically).

Abreact answered 13/4, 2018 at 10:15 Comment(1)
If you are using BLE connection you can wake up your app with a BLE notification in iOS or Android. Actually, the only way to wake up an app in iOS is with the notification pattern.Incardinate
I
1

I think it is not really possible to wake up app without user intervention on local notifications. Background fetch could be the possible solution for your case.

application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)

This UIApplicationDelegate method gets called when iOS decides a background fetch can happen:

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)
Immolate answered 6/7, 2017 at 10:7 Comment(2)
"This UIApplicationDelegate method gets called when iOS decides a background fetch can happen". Than you have no control over it. So it's just NOT POSSIBLE.Abreact
BackgroundFetch is called randomly (it depends on so many things, and apple doesn't provide any informations about it)Leucoplast
F
1

Background fetch is the only solution here.

There is some info in the Xamarin docs that explains it well

It would seem that PushNotifications use Background Fetch anyway so this is really the same route albeit through an imprecise timing mechanism.

Funkhouser answered 10/4, 2018 at 23:26 Comment(0)
A
-6

The notification should be silent if you don't set all of this values:

notification.alertBody = message;
notification.alertAction = @"Show";
notification.category = @"ACTION"; 
notification.soundName = UILocalNotificationDefaultSoundName;
Ambulate answered 6/7, 2017 at 9:16 Comment(3)
Yes, but this doesn't wake up my app if it's in suspended mode (meaning in the background and not running).Abreact
ooooh okay, not sure you can achieve that with local notification then. you can look at "beginBackgroundTaskWithName:expirationHandler:" to do some work in background but you got limited amount of time to complete your tasksAmbulate
it's not possible to receive local notification without user trigger (ex. touch on notification).Leucoplast

© 2022 - 2024 — McMap. All rights reserved.