Notification service extension for local notification

Does the system download the notification service extension and call it didReceive(_:withContentHandler:)for local notifications in iOS 10? If so, how can we do this?

+6
source share
4 answers

No. The accepted answer describes notification content extensions that allow you to view the ViewController in an extended notification and work with both remote and local notification.

Extensions of notification services that allow you to change the contents of a notification (attach images, etc.) do not work with local notifications. However, you can attach images as part of the process to show local notification.

+6
source

You need to create a notification content extension to display a custom notification using iOS10. In the Xcode menu bar, go to File-> New-> Target. Then in the list, select "Extend notification content." enter image description here

Enter the relevant data and click Finnish. A new folder will appear with the name of your extension. There will be 3 files in the folder:

  • NotificationViewController: here you can create your own interface and implement answers.

  • MainStoryboard: .

  • Info.plist

Info.plist : enter image description here

, .

let category = UNNotificationCategory(identifier: "myNotificationCategory", actions: [], intentIdentifiers:[], options: [])
            UNUserNotificationCenter.current().setNotificationCategories([category])
            content.categoryIdentifier = "myNotificationCategory"

NotificationViewController .

func didReceive(_ notification: UNNotification) {
        //change properties of notification here.
    }

    func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
        //implement response logic here.
    }

. , . , .

+2

, .

UNNotificationServiceExtension , .

0
source

Notification extension is also supported for local notifications. It is clearly mentioned here.

UNNotificationContentExtension An object that represents the user interface for the delivered local or remote notification.

0
source

Source: https://habr.com/ru/post/1665222/


All Articles