发布于 2019-09-11 07:24:01
对于进一步的参考,在我的答复之后,您可以参考https://medium.com/@stasost/ios-how-to-open-deep-links-notifications-and-shortcuts-253fb38e1696。
当应用程序关闭或更多地在后台运行时,点击通知横幅将触发didReceiveRemoteNotification appDelegate方法:
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
}当应用程序在前台模式运行时收到推送通知时,也会触发此方法。因为我们只考虑当您想在特定页面上打开应用程序时的场景,所以我们将不包括在前台模式下处理通知。
为了处理通知,我们将创建一个NotificationParser:
class NotificationParser {
static let shared = NotificationParser()
private init() { }
func handleNotification(_ userInfo: [AnyHashable : Any]) -> DeeplinkType? {
return nil
}
}现在,我们可以将此方法连接到Deeplink Manager:
func handleRemoteNotification(_ notification: [AnyHashable: Any]) {
deeplinkType = NotificationParser.shared.handleNotification(notification)
}并完成appDelegate didReceiveRemoteNotification方法:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Deeplinker.handleRemoteNotification(userInfo)
}最后一步是完成NotificationParser中的解析方法。这将取决于您的通知结构,但是基本的解析技术将类似于:
func handleNotification(_ userInfo: [AnyHashable : Any]) -> DeeplinkType? {
if let data = userInfo["data"] as? [String: Any] {
if let messageId = data["messageId"] as? String {
return DeeplinkType.messages(.details(id: messageId))
}
}
return nil
}如果您将应用程序配置为支持推送通知并希望对其进行测试,下面是我用来传递消息的通知:
apns: {
aps: {
alert: {
title: "New Message!",
subtitle: "",
body: "Hello!"
},
"mutable-content": 0,
category: "pusher"
},
data: {
"messageId": "1"
}
}发布于 2019-09-11 22:59:13
notification.payload = {
url: "https://www.google.com"
}https://stackoverflow.com/questions/57762443
复制相似问题