gpt4 book ai didi

应用程序终止时iOS Swift处理通知单击

转载 作者:行者123 更新时间:2023-12-01 21:31:58 25 4
gpt4 key购买 nike

应用程序终止时如何处理通知点击操作
当我单击通知时,我的应用程序只是午餐第一个屏幕,就像普通午餐一样
不是预期的屏幕
我现在不知道,或者我如何调试这个问题来找出到底发生了什么
当应用程序正在运行或处于后台模式时,我通过此方法处理我的通知点击操作:

func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID) tap")
}
NotificationCenter.default.post(name: .remoteNotificationActionName, object: nil, userInfo: userInfo)
print("willPresent userInfo", userInfo)
completionHandler()
}
此通知将发送到场景委托(delegate)类,并从我的场景委托(delegate)中打开相应的屏幕:
@objc
private func remoteNotificationClickAction(notification: Notification){
performRemoteNotificationClickAction(notification: notification)
}

private func performRemoteNotificationClickAction(notification: Notification){
guard let userInfo = notification.userInfo else { return }
guard let clickAction = NotificationsActions(rawValue: userInfo["click_action"] as? String ?? "") else { return }
switch clickAction {
case .dashboardAds:
routeToNotifications()
case .dashboardAdsContent:
routeToNotifications()
case .providerAcceptOrder, .providerOnWay, .providerArrive, .tripStarted, .addReceiverToChat:
guard let orderString = userInfo["order"] as? String else { return }
routeToActiveOrder(orderString: orderString)
case .orderComplete:
guard let orderString = userInfo["order"] as? String else { return }
routeToServiceReport(orderString: orderString)
case .orderCanceled, .receiverTracking, .receiverCancelOrder, .transportationDocumentIssued, .adminCancelOrder, .userCancelOrder:
guard let orderString = userInfo["order"] as? String else { return }
self.routeToOrderDetails(orderString: orderString)
case .providerCancelOrderAccepted, .offerAdded, .receiverTrackingAccept, .orderExpired, .receiverTrackingReject, .offerWithdrawn:
guard let orderString = userInfo["order"] as? String else { return }
routeToSearchForServiceProvider(orderString: orderString)
case .messageReceive:
guard let orderString = userInfo["order"] as? String else { return }
routeToChat(orderString: orderString)
case .amountSent, .amountReceive, .amountAdded, .amountSubtracted, .withdrawAccepted, .withdrawRejected, .bankTransferAccepted, .bankTransferRejected:
routeToWallet()
case .pointsAdded:
routeToTopUpPoints()
case .reportClosed:
routeToComplaints()
default: break
}

}

最佳答案

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else { return }
window = UIWindow(windowScene: windowScene)
whereToGo(window!)
if let notificationResponse = connectionOptions.notificationResponse{
NotificationCenter.default.post(name: .remoteNotificationActionName, object: nil, userInfo: notificationResponse.notification.request.content.userInfo)
}
}
如上面的代码所示,我在 中收到的通知connectionOptions.notificationResponse

关于应用程序终止时iOS Swift处理通知单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62926165/

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