首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用消息在远程通知中显示超链接

用消息在远程通知中显示超链接
EN

Stack Overflow用户
提问于 2020-01-20 14:36:25
回答 1查看 389关注 0票数 7

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

代码语言:javascript
运行
复制
@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显示为超链接。

请帮帮我。

EN

回答 1

Stack Overflow用户

发布于 2020-02-10 20:45:17

不能控制iOS显示通知的方式,但可以为通知声明特定的操作。见此处:https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types

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

在通知之后显示自定义对话框的唯一方法是,如果在应用程序处于前台时收到通知,因为操作系统不会显示通知,它只会通知应用程序,然后您可以决定显示适合您的任何UI。但这种做法与通知的想法背道而驰,通知可以随时出现,特别是当应用程序没有运行时。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59825471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档