Я на переднем плане уведомления о часах работы с:Фоновые Уведомления о WatchOS 3 (XCode 8b6)
class WorkoutInterfaceController: WKInterfaceController,
UNUserNotificationCenterDelegate
набора делегата:
UNUserNotificationCenter.current().delegate = self
получить переднего плана уведомления:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void)
{
print("Received Notification .....")
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
let completionSound: UNNotificationPresentationOptions = [.sound, .alert]
completionHandler(completionSound)
}
добавить уведомление:
let content: UNMutableNotificationContent = UNMutableNotificationContent()
content.title = "TITLE"
content.subtitle = "sub title"
content.body = "message body"
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: duration, repeats: false)
let request = UNNotificationRequest(identifier: restOverIdentifier,
content: content,
trigger: trigger)
UNUserNotificationCenter.current().add(request)
{
(error) in // ...
}
Я пробовал как симулятор, так и устройство без ведома получать уведомление, когда сим заблокирован или на главном экране или на часах, когда экран становится черным, если вы не двигаете рукой.
Все, что я ищу, это простой звуковой сигнал. Мне даже не нужен экран оповещений.
Пожалуйста, отправьте код, если у вас есть что-то для этого или подтвердите, что эта функция не работает на часах.
Благодаря
Грег