ios - 在带有消息的远程通知中显示超链接

标签 ios objective-c swift xcode rich-notifications

我需要在远程通知中显示超链接以及标题和正文。我做过这样的事情:

@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()
}

sample for hyper link "SHOW BILL"



在此我在用户信息中发送 url,但我需要这个 url 作为超链接,当通知出现时显示。当我单击该超链接时,它将在 webView 中打开此 URL。
在 webview 部分中加载 URL 已完成。只需要知道如何将此网址显示为通知上的超链接。

请帮帮我。

最佳答案

您无法控制 iOS 显示通知的方式,但您可以为通知声明特定操作。见这里:https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types

这使您可以将自定义的“支付、拒绝、阻止”操作添加到通知中。 iOS 将向用户提供选择,并在用户选择一个时在后台通知您的应用,但您将无法显示 URL,只能显示文本。

在通知之后显示自定义对话框的唯一方法是,如果您在应用程序处于前台时收到通知,因为这样操作系统不会显示通知,它只会通知您的应用程序,然后您可以决定显示任何内容用户界面适合你。但这种做法违背了通知的想法,通知可以随时出现,尤其是在您的应用程序未运行时。

关于ios - 在带有消息的远程通知中显示超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59825471/

相关文章:

ios - 应用程序图标没有刷新

ios - 为什么 AUNetSend 在 iOS 上不可用? (或任何替代建议)

ios - 仅当应用程序处于事件状态时,如何在 performFetchWithCompletionHandler 中执行代码?

ios - 如何在不先触摸的情况下显示刷新的 View ?

ios - 无法从服务器 api 解析 JSON

ios - 为什么 SpriteKit 不显示任何内容?

swift - 在 UIBezierPath 图形上应用渐变层

ios - 查看 Controller 和自身

ios - 从 didFinishLaunchingWithOptions 打开 ViewController

swift - ARKit 拖动对象改变比例