我试着用图片做推送通知。
下面是我从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中为图像所做的。

当您看到第二个图像时,我们看不到这个橙色标签意味着Notification不工作。
我在跟踪本教程制作图片推送。
下面是我在中的内容
@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在内容上的截图

知道我错过了什么吗?
发布于 2019-07-13 09:05:56
问题是NotificationViewController在内容上没有标记为“初始视图控制器”

这是因为我将旧项目的视图控制器复制到当前项目中。:)
https://stackoverflow.com/questions/56967683
复制相似问题