【发布时间】:2020-05-06 14:11:50
【问题描述】:
我需要在远程通知中显示超链接以及标题和正文。我做过这样的事情:
@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 已完成。只需要知道如何将此网址显示为通知上的超链接。
请帮帮我。
【问题讨论】:
-
就我而言,我建议使用Notification Content Extension 来自定义您的通知。有很多关于它的文章,但我不知道它是否适合您的流程。
-
是的,我通过了它们...但是要求不允许使用扩展名...由于某种原因....
-
你看过这个answer
-
@chirag:如果你看到代码,我已经完成了这个 chirag。打开网址不是问题。问题是在通知中显示超链接文本。
标签: ios objective-c swift xcode rich-notifications