【发布时间】:2020-04-15 13:52:12
【问题描述】:
我正在尝试使用 WKWebView 和 Firebase Push 开发 IOS / Swift 应用程序。我想使用 PHP 发送通知,当用户单击通知以在 webview 中打开自定义 URL 时。默认网址是
let url = URL(string: "https://mywebsite.com/index.php?token=\(token)")!
我想在这个 url 中传递一个像这样的 id
let url = URL(string: "https://client.gazduire.net/app3/index.php?token=\(token)&ntid=(id that is send with push notification, ex.:1)")!
我在 appdelegate.swift 中的代码
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)")
}
// Print full message.
print(userInfo)
let notificationName = Notification.Name("test")
NotificationCenter.default.post(name: notificationName, object: nil,userInfo: userInfo)
let ntid = userInfo["ntid"] as! String
print("\(ntid)")
completionHandler()
}
ViewController.swift
@objc func test() {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let ntid = appDelegate.ntid
let token = Messaging.messaging().fcmToken
guard let url = URL(string: "https://mywebsite.com/index.php?token=\(token ?? "")&ntid=\(ntid)") else {
print("Invalid URL")
return
}
let request = URLRequest(url: url)
webView.load(request)
}
当用户点击推送通知时,我可以将 ntid(ntid 已接收并且打印正常)从 appdelegate 发送到 viewcontroller 吗?谢谢!
【问题讨论】:
标签: php ios swift firebase push-notification