1.将UNNotificationServiceExtension中的pilst文件中添加
(1)在Info.plist中添加NSAppTransportSecurity类型Dictionary。
(2)在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES
这是因为从iOS9开始苹果不允许直接http访问,加上这两个字段就可以访问http,如果你不添加,只有你推送https的media文件才能被下载,http则不能被下载;
2.如果项目支持多个target,相应的UNNotificationServiceExtension也要构建多个,与target之间一一对应,运行NotificationServiceExtension时选择与构建时对应的target作为主程序。
3.⚠️mutable-content字段一定要与alert平级。推送时playload内容简单示例:
{
"aps":{
"alert":{
"title":"Realtime Custom Push Notifications",
"subtitle":"Now with iOS 10 support!",
"body":"Add multimedia content to your notifications"
},
"sound":"default",
"badge": 1,
"mutable-content": 1,
},
"media":{"type":"image","url":"https://www.fotor.com/images2/features/photo_effects/e_bw.jpg"}
}
开发过程参考:https://onevcat.com/2016/08/notification/
https://www.jianshu.com/p/265bf362cc3b
网友评论