Search code examples
iosswiftwatchkitwatchconnectivitywcsession

WCSession: is it possible to cancel queued message?


Is there any way to cancel messages sent by the sendMessage(_:replyHandler:errorHandler:) method of WCSession?

From the documentation:

Messages are queued serially and delivered in the order in which you sent them.


Solution

  • No. That type of transfer is not cancellable, as

    • the OS would have immediately sent any sendMessage data to a reachable counterpart

      Use the [sendMessage] method to transfer data to a reachable counterpart. These methods are intended for immediate communication between your iOS app and WatchKit extension.

      Data sent using the [sendMessage], and transferCurrentComplicationUserInfo: methods has a higher priority and is transmitted right away.

    • the OS provides no mechanism to specifically cancel a message

      The only WCSession objects that have a cancel method are WCSessionUserInfoTransfer, and WCSessionFileTransfer, since lower-priority transferUserInfo or transferFile data is not sent immediately, but at an optimum time determined by the OS.