Display image in notification bar with remote notification(Rich media push notification) in iOS 10

自古美人都是妖i 提交于 2019-12-01 06:01:15

You need to put the "mutable-content": "1", flag outside the "alert"-object in your payload.

You have a mistake here:

Then, I have created new target with UNNotificationServiceExtension and created new bundle id "com.RichPush.app.Service-Extension" , I have also created new certificate and provision profile with above bundle for UNNotificationServiceExtension.

use UNNotificationContentExtension instead of UNNotificationServiceExtension

after create new target, xcode will create swift (obj- c) file and storyboard interface

I have a simple example on swift code, which load image and show on large push notification view

class NotificationViewController: UIViewController, UNNotificationContentExtension {


//image provided from storyboard
@IBOutlet weak var image: UIImageView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any required interface initialization here.
}

func didReceive(_ notification: UNNotification) {
    let userInfo = notification.request.content.userInfo
    // get image url 
   // and load image here  
} 
}

From Apple doc:

UNNotificationServiceExtension Modifies the content of remote notifications before they are delivered to the user.

and

UNNotificationContentExtension Presents a custom interface for a delivered local or remote notification.

Your notification payload should be like this:

   aps =     {
        alert =         {
            body = Testing;
            title = Dining;
        };
        badge = 1;
        "content-available" = 1;
        "mutable-content" = 1;
        sound = "Bleep-Sound.wav";
    };

}

Content-available and mutable-content should be outside the alert and also you should add the badge count too....

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