gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:55:00 27 4
gpt4 key购买 nike

我正在制作一个应用程序,该应用程序假定用户每天在设定的时间了解新闻。它通过从数组调用它的函数获取新闻文本。我的问题是:如何让我的应用程序调用该函数,然后每天凌晨 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]) { (granted, error) in
self.isGrantedNotificationAccess = granted
}
}
}

关于ios - 如何在设定的时间获得推送通知? ( swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43148864/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com