即使内容的故事板已更新,也不会调用通知内容

Notification Content not get called even storyboard of content is updated

我正在尝试使用图像进行推送通知。

下面是我从pushtry.com

发送的推送
{
  "aps": {
    "alert": "message with meow image 11",
    "badge": 1,
    "sound": "default",
   "category": "DCCPush",
   "mutable-content": "1"
  },
  "Type": "product",
  "Id": 165,
  "imageURL": "https://i.stack.imgur.com/FXmv3.jpg"
}

推送带有图像,但问题是当我拉下推送时,图像不显示。请参阅下面的屏幕截图。

因为我正在推送图像,所以我知道通知服务正在工作。 如果我错了,请纠正我。

现在,我觉得通知内容不起作用,所以我添加了背景颜色为橙色的标签。

下面是我在 UI 中的图片。

正如您看到的第二张图片,我们没有看到这个橙色标签,这意味着通知内容不起作用。

我关注this tutorial to make push with image.

下面是我在 App Delegate 中的内容

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    let notificationDelegate = SampleNotificationDelegate()

    func configureNotification() {
        if #available(iOS 10.0, *) {
            let center = UNUserNotificationCenter.current()
            center.requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
            center.delegate = notificationDelegate
            let openAction = UNNotificationAction(identifier: "OpenNotification", title: "clickToView".localized(), options: UNNotificationActionOptions.foreground)
            let deafultCategory = UNNotificationCategory(identifier: "DCCPush", actions: [], intentIdentifiers: [], options: [])
            center.setNotificationCategories(Set([deafultCategory]))
        } else {
            UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
        }
        UIApplication.shared.registerForRemoteNotifications()
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.


        self.configureNotification()

下面是我在 SampleNotificationDelegate

中的内容
import UIKit

import Foundation
import UserNotifications
import UserNotificationsUI

class SampleNotificationDelegate: NSObject , UNUserNotificationCenterDelegate {

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert,.sound])
    }

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        switch response.actionIdentifier {
        case UNNotificationDismissActionIdentifier:
            print("Dismiss Action")
        case UNNotificationDefaultActionIdentifier:
            print("====Open Action======")

            print("response===\(response)")

            let userInfo = response.notification.request.content.userInfo
            PushNotificationResponse(Data:userInfo as NSDictionary)


        case "Snooze":
            print("Snooze")
        case "Delete":
            print("Delete")
        default:
            print("default")
        }
        completionHandler()
    }

    func PushNotificationResponse(Data:NSDictionary){

        DispatchQueue.main.asyncAfter(deadline: .now() + 1) { // change 2 to desired number of seconds

             switch (Data["Type"] as! String) {

                case "product":

                    print("push details")

                    UserDefaults.standard.set(Data["Id"] as? Int, forKey: "pushId")
                    UserDefaults.standard.synchronize()

                    Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.prepareDataNotifications), userInfo: nil, repeats: false)
                    break
            default:
                break

            }
        }

    }

    @objc func prepareDataNotifications() {
        var mProduct : Products = Products()
        mProduct.id = UserDefaults.standard.integer(forKey: "pushId")
        Transition.openProductDetailsVCScreen2(withAnimation: true, productObject: mProduct)
    }

}

下面是内容Info.plist中的截图

知道我错过了什么吗?

问题是内容中的 NotificationViewController 没有被标记为 "Initial View Controller"

发生这种情况是因为我将旧项目的视图控制器复制到当前项目。 :)