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

前端 未结 3 819
攒了一身酷
攒了一身酷 2021-01-13 08:39

I have integrated APNS and want to display image in remote notification like below;

I have used below code with reference link;

AppDelegate

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 09:11

    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.

提交回复
热议问题