Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何将本地通知内容设置为与打开时主屏幕中显示的内容相同?[快速]_Swift_Uicollectionview_Uilocalnotification - Fatal编程技术网

Swift 如何将本地通知内容设置为与打开时主屏幕中显示的内容相同?[快速]

Swift 如何将本地通知内容设置为与打开时主屏幕中显示的内容相同?[快速],swift,uicollectionview,uilocalnotification,Swift,Uicollectionview,Uilocalnotification,我正在尝试重新创建一个现有的激励报价应用程序作为练习 在这个应用程序上,你会收到一个显示内容的通知,如果你点击它,主页会为你提供报价的其余部分(下面的屏幕截图)。我经常看到这种类型的应用程序——它们都使用集合视图,通知和主页内容总是匹配的 我已经尝试模仿这一点,在接下来的7天内设置本地通知,向用户提供来自我的阵列的随机报价: func configureNotifications() { let shuffled = quotes.shuffled() for i in 1...

我正在尝试重新创建一个现有的激励报价应用程序作为练习

在这个应用程序上,你会收到一个显示内容的通知,如果你点击它,主页会为你提供报价的其余部分(下面的屏幕截图)。我经常看到这种类型的应用程序——它们都使用集合视图,通知和主页内容总是匹配的

我已经尝试模仿这一点,在接下来的7天内设置本地通知,向用户提供来自我的阵列的随机报价:

func configureNotifications() {
    let shuffled = quotes.shuffled()
    for i in 1...7 {
        let content = UNMutableNotificationContent()
        content.title = “Daily quotes”
        content.body = shuffled[i].text

        let alertDate = Date().byAdding(days: i) // scheduled for next 7 days added
        
        var alertComponents = Calendar.current.dateComponents([.day, .month, .year], from: alertDate)
        alertComponents.hour = 10
Etc
}

func updateQuoteHome() {

    guard let selectedQuote = quotes.randomElement() else {
        fatalError("Unable to read a quote.")
    }

    updateLabels(with: selectedQuote)
}
然而,一旦点击通知,或者用户只是随机打开应用程序,显示的内容显然完全不同

将这两者链接在一起的方法是什么?是否可以使用本地通知,或者这些应用程序是否使用推送通知

文档中有关于这方面的内容吗

多谢各位~


此功能应使用推送通知。如果您很少或没有后端经验,您可以使用并实现这一点。

嘿!谢谢你的回答。但这是实现这一目标的唯一途径吗?推送通知如何允许通知与主屏幕上的内容匹配?当用户使用UNUserNotificationCenterDelegate点击通知内容时,您可以检索通知内容,但我仍然会使用推送通知,因为它们是动态的。您不能更改计划的本地通知,但推送通知内容是完全动态的。资料来源: