gpt4 book ai didi

ios - 每日同时推送通知,持续 10 天

转载 作者:行者123 更新时间:2023-11-30 12:28:01 26 4
gpt4 key购买 nike

在 iOS 中,有没有一种简单的方法可以在每天的同一时间发送 10 天的推送通知?我不想向所有用户发送推送通知。我的应用程序的工作方式是,用户可以选择连续十天推送通知的时间。您有推荐的 API 吗?或者有没有办法处理本地推送通知(在 Swift 中)?

谢谢!

最佳答案

试试这个

在 Appdelegate 中

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let center = UNUserNotificationCenter.current()
center.requestAuthorization([.alert, .sound]) { (granted, error) in
if granted{
// do you work
}
}
return true
}

通用功能

func scheduleMyNotificationWith(date: Date, body: String) {     
let triggerWeekly = Calendar.current.dateComponents([.weekday,hour,.minute,.second,], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)

let content = UNMutableNotificationContent()
content.title = "your notification title" // it is mendatory
content.body = body
content.sound = UNNotificationSound.default()
//content.categoryIdentifier = "todoList"

let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger)

UNUserNotificationCenter.current().delegate = self
//UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Somethings went to wrong: \(error)")
}
}
}

关于ios - 每日同时推送通知,持续 10 天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43929331/

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