如何在设定的时间获得推送通知? (Swift 3)

How to get a push notification at a set time? (Swift 3)

我正在制作一个应用程序,该应用程序假定用户每天在设定的时间了解新闻。它通过从数组调用它的函数获取新闻文本。我的问题是:如何让我的应用程序调用该函数,然后每天凌晨 4 点向我发送带有信息文本的推送通知?

感谢大家的回答!祝你有美好的一天!

这是我以前用过的一些代码,不是你要找的百分百,但我希望对你有用 您需要将其修改为每天发送

import UIKit
import UserNotifications

class ViewController: UIViewController, UNUserNotificationCenterDelegate {
    var isGrantedNotificationAccess:Bool = false
    @IBAction func send10SecNotification(_ sender: UIButton) {
        if isGrantedNotificationAccess{
            //add notification code here

        //Set the content of the notification
        let content = UNMutableNotificationContent()
        content.title = "10 Second Notification Demo"
        content.subtitle = "From MakeAppPie.com"
        content.body = "Notification after 10 seconds - Your pizza is Ready!!"

        //Set the trigger of the notification -- here a timer. 
        let trigger = UNTimeIntervalNotificationTrigger(
            timeInterval: 10.0,
            repeats: true)

        //Set the request for the notification from the above
        let request = UNNotificationRequest(
            identifier: "10.second.message",
            content: content,
            trigger: trigger
        )

        //Add the notification to the currnet notification center
        UNUserNotificationCenter.current().add(
            request, withCompletionHandler: nil)

    }
}

override func viewDidLoad() {
    super.viewDidLoad()
    UNUserNotificationCenter.current().requestAuthorization(
        options: [.alert,.sound,.badge],
        completionHandler: { (granted,error) in
            self.isGrantedNotificationAccess = granted
        }
    )
}}