Still have the same issue
Post
Replies
Boosts
Views
Activity
as an addition to @jakajancar's answer let me introduce an example code ;
Send a message to the connection you want to cancel; set contentContext: parameter to NWConnection.ContentContext.finalMessage, then cancel the connection:
connectionYouWantToCancel.send(content: nil, contentContext: .finalMessage, isComplete: true, completion: .idempotent)
connectionYouWantToCancel.cancel()
And read the message on the other device; check if the context is final
connectionOnTheOtherDevice.receiveMessage { (content, context, isComplete, error) in
if let context = context, context.isFinal {
connectionOnTheOtherDevice.cancel()
// any other logic if needed.
return
}
// other logic
}
At least I'm handling the problem this way without any delay or any unexpected behaviour.