WCSession:是否可以取消排队的消息?

WCSession: is it possible to cancel queued message?

有没有办法取消WCSessionsendMessage(_:replyHandler:errorHandler:)方法发送的消息?

来自documentation

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

没有。这种类型的转移是不可取消的,因为

  • OS 会立即将任何 sendMessage 数据发送给 reachable 对方

    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.

  • OS 没有提供专门取消消息的机制

    唯一具有 cancel 方法的 WCSession 对象是 WCSessionUserInfoTransferWCSessionFileTransfer,因为优先级较低的 transferUserInfotransferFile 数据不会立即发送,而是在 OS.

  • 确定的最佳时间发送