【发布时间】:2021-02-18 09:36:11
【问题描述】:
我做了一个通知,现在我的通知已经出现在 iOS 上,当我点击通知包时,通知出现我想切换到另一个 View Controller 页面。
这是我在 AppDelegate.swfit
中的代码 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print("user data msg \(userInfo)")
guard let aps = userInfo["aps"] as? [String : AnyObject] else {
print("Error parsing aps")
return
}
print(aps)
if let alert = aps["alert"] as? String {
body = alert
} else if let alert = aps["alert"] as? [String : String] {
body = alert["body"]!
title = alert["title"]!
}
if let alert1 = aps["category"] as? String {
msgURL = alert1
}
print("Body\(body)")
print(title)
print(msgURL)
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "register")
vc.modalPresentationStyle = .overFullScreen
present(vc, animated: true)
}
}
但我收到错误:在范围内找不到“存在”当用户在 Swift 中收到通知时,我应该将导航代码放在哪里。
【问题讨论】:
-
你有没有试过用 push 代替 present
标签: swift xcode push-notification firebase-cloud-messaging