在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一、简介An object that modifies the content of a remote notification before it's delivered to the user. 是一个能在远程通知传递到用户之前进行修改内容的对象。 二、概述A UNNotificationServiceExtension object provides the entry point for a Notification Service app extension, which lets you customize the content of a remote notification before it is delivered to the user. A Notification Service app extension doesn't present any UI of its own. Instead, it is launched on demand when a notification of the appropriate type is delivered to the user’s device. You use this extension to modify the notification’s content or download content related to the extension. For example, you could use the extension to decrypt an encrypted data block or to download images associated with the notification. UNNotificationServiceExtension对象提供通知服务应用程序扩展的入口点,允许您在远程通知传递给用户之前对其内容进行自定义。通知服务应用程序扩展本身不提供任何UI,相反,当通知发送到用户设备时,你可以根据需要启动,可以通过通知扩展来修改通知内容或下载关联的扩展内容。例如:你可以使用扩展来加解密数据或下载与通知关联的图像。 You don't create UNNotificationServiceExtension objects yourself. Instead, the Xcode template for a Notification Service Extension target contains a subclass for you to modify. Use the methods of that subclass to implement your app extension’s behavior. When a remote notification for your app is received, the system loads your extension and calls its didReceive(_:withContentHandler:) method only when both of the following conditions are met: 你不需要自己创建UNNotificationServiceExtension对象,相反,Xcode模板已经包含了一个通知扩展需要修改的子类,使用子类方法来实现引用程序的扩展行为,当时一个远程通知到应用程序时,系统加载你的扩展并调用didReceive(_:withContentHandler:) 方法,但需要通知满足以下条件: The remote notification is configured to display an alert. 远程推送通知被设置为alert提示 远程通知的aps字典中包含mutable-content键值,而且其值设置为1. The didReceive(_:withContentHandler:)方法执行扩展的主要工作。你可以是使用该方法对通知内容做一些更改,该方法提供了有限的时间去执行任务和提供的数据块,如果你的方法在该时间内没有完成,系统会执行 As for any app extension, you deliver a Notification Service app extension class as a bundle inside your app. The template provided by Xcode configures the 对于任何应用程序的扩展,都会将通知服务扩展类交付给应用程序中,对于Xcode中提供的末班,在info.plist文件中都会自动扩展类型。具体说,为通知扩展子类添加两个键值NSExtensionPointIdentifier 和 NSExtensionPrincipalClass For information about how to set up and send remote notifications, see Setting Up a Remote Notification Server. 如何设置和发送远程通知,看链接。 三、Subclassing Notes The Xcode templates provide a subclass of Xcode模板为通知扩展提供了子类,你必须实现完成以下两个方法。 func didReceive(UNNotificationRequest, withContentHandler: (UNNotificationContent) -> Void) //Asks you to make any needed changes to the notification and notify the system when you're done. func serviceExtensionTimeWillExpire() //Tells you that your extension is about to be terminated.
如何创建UNNotificationServiceExtension请自行百度。
|
请发表评论