Is it possible to send SILENT LOCAL notification o

2019-06-15 14:49发布

问题:

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?

回答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)


回答2:

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



回答3:

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.



回答4:

Here you go buddy :) Apple documentation over silent notification



回答5:

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;