如果应用不是 运行(如时钟应用),我可以使用 iOS 本地通知吗?
Can I use iOS local notifications if app is not running (like Clock app)?
我想使用 iOS 本地 UNNotifications
即使我的应用不是 运行ning。与我们在时钟应用程序中使用闹钟的方式相同。我们可以设置闹钟,然后退出我们的时钟应用程序,但是...声音和通知会 运行 准时。我需要相同类型的行为。
可能吗?
我的代码摘录:
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)
}
}
检查这个Apple Document大约30秒
Local and remote notifications can specify custom alert sounds to be
played when the notification is delivered. You can package the audio
data in an aiff, wav, or caf file. Because they are played by the
system-sound facility, custom sounds must be in one of the following
audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
Place custom sound files in your app bundle or in the Library/Sounds
folder of your app’s container directory. Custom sounds must be under
30 seconds when played. If a custom sound is over that limit, the
default system sound is played instead.
Apple 开发的内置时钟应用程序。有特殊待遇(没办法)
我想使用 iOS 本地 UNNotifications
即使我的应用不是 运行ning。与我们在时钟应用程序中使用闹钟的方式相同。我们可以设置闹钟,然后退出我们的时钟应用程序,但是...声音和通知会 运行 准时。我需要相同类型的行为。
可能吗?
我的代码摘录:
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)
}
}
检查这个Apple Document大约30秒
Local and remote notifications can specify custom alert sounds to be played when the notification is delivered. You can package the audio data in an aiff, wav, or caf file. Because they are played by the system-sound facility, custom sounds must be in one of the following audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
Place custom sound files in your app bundle or in the Library/Sounds folder of your app’s container directory. Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.
Apple 开发的内置时钟应用程序。有特殊待遇(没办法)