How to handle notification click action when app is terminated when i click the notification my app just lunch first screen as normal lunch not the expected screen i don't now or how can i debug this problem to find out what happening exactly
when app is running or in background mode, i handle my notification click actions through this method:
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()
}
this notification will send to scene delegate class and from my scene delegate i will open the appropriate screen:
@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)
}
}
as shown in above code my notification received in connectionOptions.notificationResponse