Gabe
Gabe

Reputation: 31

Companion Apple Watch App local notifications delayed?

I have an app for Apple Watch as a companion app for an iPhone app. The local notifications on Apple Watch App are delayed. I scheduled a local notification to be fired after 10 seconds. When I press the button on the watch that creates the notification and I exit the app, it doesn't take 10 seconds to display the notification but about 23 seconds.

I created a test stand alone/independent Apple Watch App with the same local notification code, and in this scenario, the local notification fires at the correct time.

I am on watchOS 8.1. Is this a new feature on Apple Watch or a bug? Because on iPhone it works without any delay. Thank you in advance :)

// Configure the notification's payload. 
let content = UNMutableNotificationContent()
    content.title = "Drink some milk!"
    content.subtitle = "you have 10 sec"
    content.sound = .default
    content.categoryIdentifier = "myCategory"
    let category = UNNotificationCategory(identifier: "myCategory", actions: [], intentIdentifiers: [], options: [])
    UNUserNotificationCenter.current().setNotificationCategories([category])
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
    let request = UNNotificationRequest(identifier: "milk", content: content, trigger: trigger)
     
    UNUserNotificationCenter.current().add(request) { (error) in
      if let error = error{
        print(error.localizedDescription)
      }else{
        print("scheduled successfully")
      }
    }

Upvotes: 3

Views: 296

Answers (1)

wlixcc
wlixcc

Reputation: 1492

There is a feedback here: https://developer.apple.com/forums/thread/696280

This is correct behaviour.

If you have both a phone and watch app installed we’ll try to coordinate between phone and watch notifications if the phone is unlocked. If the app developer doesn’t send a notification on the phone the watch will timeout after 13 seconds and alert anyway.

The best solution to this would be to send the same notification on both devices ensuring the UNNotificationRequest.identifier matches on a per-instance basis.

This will let us alert and deduce correctly.

If watch app send local notification , I'll send the notification 13 seconds ahead of time. This way the notification appears to be on time

Hope to have a better solution in the future

Upvotes: 4

Related Questions