Local Push Connectivity - Send a Silent Notification

I am currently investigating how to use Local Push Connectivity to generate push notifications on the users device similar to the Simple Push Example sample code found here

My question is:

Is it possible to generate a Silent/Background notification using UNUserNotificationCenter in my NEAppPushProvider subclass?

Failing that, it is possible to - somehow - wake my app (not the extension but the main app) in the background and have it respond when data is sent from the server?

There is: appPushManager(_:didReceiveIncomingCallWithUserInfo:)in the NEAppPushDelegate

But will that wake the app up if it is not running?

Thank you for your time reading this :)

Is it possible to generate a Silent/Background notification using UNUserNotificationCenter in my NEAppPushProvider subclass?

Not sure about a silent or background notification, but you can send a local push notification that is received in the host app.

Container App:

import UserNotifications

class NetworkManager: NSObject {

	// ...

	private override init() {
        super.init()
        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) {  granted, error in
            // ....
        }
	}

}

extension NetworkManager: UNUserNotificationCenterDelegate {
    
    
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        // ...
        completionHandler([.badge, .sound, .banner])
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, 
    							withCompletionHandler completionHandler: @escaping () -> Void) {
        
        // ...
        completionHandler()
    }
}

Provider:

import UserNotifications

class AppPushProvider: NEAppPushProvider {
   
    override init() {
        super.init()
    }

    override func start(completionHandler: @escaping (Error?) -> Void) {
        showLocalNotification { error in
        	// ...
            completionHandler(error)
        }
    }

    // ...

    func showLocalNotification(completionHandler: @escaping (Error?) -> Void) {
        
        let content = UNMutableNotificationContent()
        content.title = "Test Notification"
        content.body = "Here is a test notification to verify that the provider is working"
        content.sound = .default
        content.userInfo = [
            "message": "Here is a test notification to verify that the provider is working"
        ]
        
        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
        let request = UNNotificationRequest(identifier: "ProviderNotification", content: content, trigger: trigger)
        
        UNUserNotificationCenter.current().add(request) { error in
            if let error = error {
                // ...
                completionHandler(error)
                return
            }
            
            // ...
            completionHandler(nil)
        }
    }
}

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Local Push Connectivity - Send a Silent Notification
 
 
Q