最近,我开始使用iOS开发,目前我正在为现有的应用程序添加新功能。对于当前的特性,我需要在预定义的时间间隔内按一定的时间间隔推送通知;比方说,在8:00到20:00之间,每2小时一次。此外,我想在通知被点击时定义自定义行为(打开一个特定的视图)。
我目前能够使用现有的通知服务按需发送基于文本的推送通知,但我还不能定义这种自定义的间隔/行为
处理此场景的最佳方法是什么?
private func sendLocalNotification() {
let content = UNMutableNotificationContent()
content.title = "Title"
content.body = "Body"
// defining a trigger for custom behaviour
// var trigger: UNNotificationTrigger?
let request = UNNotificationRequest(identifier: TestNotification.identifier, content: content, trigger: .none)
userNotificationCenter.add(request, withCompletionHandler: nil)
}发布于 2021-11-30 00:03:12
UILocalNotification* localNotification = [[UILocalNotificationalloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7200];
localNotification.alertBody = @"Your alert message";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];尝尝这个
https://stackoverflow.com/questions/70157028
复制相似问题