18

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?

AndaluZ
  • 1,410
  • 3
  • 15
  • 33
  • 1
    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. – Paulw11 Jul 06 '17 at 10:44
  • 3
    @Paulw11 I'm not talking about launching the app, I'm talking about waking up the app from suspended mode. – AndaluZ Dec 06 '17 at 13:47
  • You can setup a local notification with your specified time and by this way you can wake your app. – good4pc Apr 15 '20 at 16:10

4 Answers4

7

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).

AndaluZ
  • 1,410
  • 3
  • 15
  • 33
  • 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. – dicarlomagnus Apr 15 '19 at 19:16
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)
Ellen
  • 5,180
  • 1
  • 12
  • 16
  • "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. – AndaluZ Apr 13 '18 at 10:09
  • BackgroundFetch is called randomly (it depends on so many things, and apple doesn't provide any informations about it) – ShadeToD Mar 23 '21 at 12:12
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.

Nick Jones
  • 131
  • 1
  • 7
-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;
John Smith
  • 1,194
  • 1
  • 12
  • 30
  • Yes, but this doesn't wake up my app if it's in suspended mode (meaning in the background and not running). – AndaluZ Jul 06 '17 at 09:20
  • 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 tasks – John Smith Jul 06 '17 at 09:35
  • it's not possible to receive local notification without user trigger (ex. touch on notification). – ShadeToD Mar 23 '21 at 12:11