gpt4 book ai didi

ios - 即使内容的 Storyboard已更新,也不会调用通知内容

转载 作者:行者123 更新时间:2023-11-28 13:33:48 28 4
gpt4 key购买 nike

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

下面是我从 pushtry.com 发送的推送

{
"aps": {
"alert": "message with meow image 11",
"badge": 1,
"sound": "default",
"category": "DCCPush",
"mutable-content": "1"
},
"Type": "product",
"Id": 165,
"imageURL": "/image/FXmv3.jpg"
}

Push 正在向我发送图像,但问题是当我拉下 Push 时,图像没有显示。请参阅下面的屏幕截图。

enter image description here

enter image description here

当我收到图像推送时,我知道通知服务正在运行。 如果我错了请纠正我。

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

下面是我在 UI 中的图像。

enter image description here

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

我正在关注 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的截图

enter image description here

知道我错过了什么吗?

最佳答案

问题是 Content 中的 NotificationViewController 没有被标记为“Initial View Controller”

enter image description here

发生这种情况是因为我将旧项目的 View Controller 复制到了当前项目中。 :)

关于ios - 即使内容的 Storyboard已更新,也不会调用通知内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56967683/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com