How to customize short preview of notifications in iOS 10+

最后都变了- 提交于 2019-12-02 04:01:49

问题


I have implemented iOS rich notifications in my app based on Local and Remote Notification Programming Guide.

I watched WWDC Introduction to Notifications, Advanced Notifications, and Best Practices, and read UNNotificationContentExtension. All of these show that I can implement Notification Content extension to customize notification presentation. But to me it seems that they all assume that we can customize only the expanded view (the view that opens up when we 3D press the short preview).

Now I know that I can customize the presentation of the short preview in a very restricted way - using title/body I can decide if I want a bold or normal font; by using Notification Service extension I can add a media preview. However, what I need is to be able to build the UI of this short preview myself - add custom UIImageView, etc. Right now it seems that this is not possible, but I wasn't able to find any explicit information that would confirm it.

So my question is: Can we customize the short preview of a notification? If not, is there any explicit statement in official docs that explain this? If yes, can you refer me to some docs/tutorials on how to do it?


回答1:


I just stumbled upon the following line in the Customizing the Appearance of Notifications article in the official documentation:

The system provides the interface for the abbreviated banner, but you can customize the full interface using a notification content app extension.

This confirms that currently there is no way of customizing the short preview ("abbreviated banner" in the docs).




回答2:


I think (I'm not 100% sure) that you can only display an Attachment Image in the Notification banner, because you don't have Storyboad or UI file for this. It is the default Notification banner design.

You can follow this great guide (links below), it helps me understand Notification Content Extension and Notification Service Extension and all the logic behind and how it really works.

You can try to make some adjustments to the project, trying with anything else than ImageView, but as far as I know, the attachment is by default positioned at the right corner, as a miniature.

I am interested if you find additional informations.

Here is the great links that helped me build my Notification Feature in my App.

Sources:

Rich Notification Guide

Notification with Attachment

PS: I am also sad and disapointed that the expended view only appears with 3D Touch (People don't use it, 3D Touch is a failure to me).



来源:https://stackoverflow.com/questions/49488243/how-to-customize-short-preview-of-notifications-in-ios-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!