即使更新了内容的情节提要,通知内容也不会被调用
Posted
技术标签:
【中文标题】即使更新了内容的情节提要,通知内容也不会被调用【英文标题】:Notification Content not get called even storyboard of content is updated 【发布时间】:2019-07-10 09:31:42 【问题描述】:我正在尝试使用图像进行推送通知。
以下是我从 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"
Push 带着图像来找我,但问题是当我拉下 push 时,图像没有显示。请看下面的截图。
当我收到图片推送时,我知道通知服务正在工作。 如果我错了,请纠正我。
现在,我觉得通知内容不起作用,所以我添加了背景颜色为橙色的标签。
下面是我在 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)
下面是Content中Info.plist的截图
知道我缺少什么吗?
【问题讨论】:
检查内容扩展的 info.plist 文件中添加的 DCCPush 类别或内容 inf.plist 的邮政编码 【参考方案1】:问题是内容中的 NotificationViewController 未标记为“初始视图控制器”
这是因为我将旧项目的视图控制器复制到当前项目中。 :)
【讨论】:
控制台中没有关于此的警告?以上是关于即使更新了内容的情节提要,通知内容也不会被调用的主要内容,如果未能解决你的问题,请参考以下文章
情节提要 xib 在 viewDidLoad 后“卡住”