j'ai des notifications de premier plan sur la montre de travail avec:Notifications d'arrière-plan sur watchos 3 (XCode 8B6)
class WorkoutInterfaceController: WKInterfaceController,
UNUserNotificationCenterDelegate
délégué set:
UNUserNotificationCenter.current().delegate = self
recevoir une notification de premier plan:
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)
}
add une notification:
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 // ...
}
J'ai essayé à la fois sur le sim et l'appareil sans chance d'obtenir une notification lorsque la carte SIM est verrouillée ou sur l'écran d'accueil ou de surveillance lorsque l'écran devient noir si vous ne bougez pas votre bras. Tout ce que je cherche est un bip simple Je n'ai même pas besoin de l'écran d'alerte de notification.
S'il vous plaît code postal si vous avez quelque chose qui fonctionne pour cela ou confirmer que cette fonction ne fonctionne pas sur la montre.
Merci
Greg