【发布时间】:2018-05-31 16:28:02
【问题描述】:
即使我的应用没有运行,我也想使用 iOS 本地 UNNotifications。就像我们在时钟应用程序中使用闹钟一样。我们可以设置闹钟,然后退出我们的时钟应用程序,但是......声音和通知将按时运行。我需要相同类型的行为。
有可能吗?
我的代码摘录:
import UIKit
import UserNotifications
class ViewController: UIViewController, UNUserNotificationCenterDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let content = UNMutableNotificationContent()
content.title = "Our title"
content.body = "A body of message"
UNUserNotificationCenter.current().delegate = self
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: false)
let request = UNNotificationRequest(identifier: "testID", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
}
【问题讨论】:
-
闹钟应用程序使用私有API,您可以做的就是在特定日期触发通知以仅播放30秒的声音,但内置的IOS闹钟应用程序有Apple的特殊处理
-
你能回答我的问题并给我所有的苹果链接(如果有的话)吗?
标签: notifications swift4 ios11 unusernotificationcenter unnotificationrequest