我需要在远程通知中显示超链接以及标题和正文。我做过这样的事:
@IBAction func openPDFButtonPressed(_ sender: Any) {
self.scheduleNotification()
}
func scheduleNotification() {
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Download The Receipt"
content.body = "Kindly Download your purchase bill"
content.categoryIdentifier = "PDF"
content.userInfo = ["customData": "http://www.pdf995.com/samples/pdf.pdf"]
content.sound = UNNotificationSound.default
var dateComponents = DateComponents()
dateComponents.hour = 10
dateComponents.minute = 30
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
center.add(request)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// pull out the buried userInfo dictionary
let userInfo = response.notification.request.content.userInfo
print("Test: \(userInfo)")
if let customData = userInfo["customData"] as? String {
print("Custom data received: \(customData)")
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "PDFViewController") as! PDFViewController
newViewController.strURL = customData
self.present(newViewController, animated: true, completion: nil)
}
completionHandler()
}
在这方面,我在用户信息中发送url,但是我需要这个url作为超链接来显示通知何时出现。当我点击这个超链接时,它会在webView中打开这个URL。在webview部分中加载URL是完成的。只需要知道如何在通知中将这个url显示为超链接。
请帮帮我。
发布于 2020-02-10 12:45:17
不能控制iOS显示通知的方式,但可以为通知声明特定的操作。见此处:https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types
这使您可以将自定义的“支付、拒绝、阻止”操作添加到通知中。iOS将向用户提供这些选择,并在用户选择其中一个时在后台通知您的应用程序,但是您将无法显示URL,而只能显示文本。
在通知之后显示自定义对话框的唯一方法是,如果在应用程序处于前台时收到通知,因为操作系统不会显示通知,它只会通知应用程序,然后您可以决定显示适合您的任何UI。但这种做法与通知的想法背道而驰,通知可以随时出现,特别是当应用程序没有运行时。
https://stackoverflow.com/questions/59825471
复制