WCSession has not been activated
I figured out the problem I had, and I think yours is similar. I was trying to send a message immediately after calling activate()
, which worked in the past, but since the introduction of the session(activationDidCompleteWith:)
function I needed to send my messages from there.
So I think your solution is one of these:
- Make your InterfaceController be the
WCSessionDelegate
, move allWCSession
activation calls there, and send the message fromsession(activationDidCompleteWith:)
- Send the message from
session(activationDidCompleteWith:)
in theExtensionDelegate
(in my
app I handle all communication in theExtensionDelegate
) - Post a notification from
session(activationDidCompleteWith:)
in theExtensionDelegate
and add an observer to handle it inInterfaceController
Aside from this, I think you may also have a problem because the declaration of session(didReceiveMessage:)
is wrong in your AppDelegate (or at least I had a problem when I tried your code.)
The new declaration is:
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void)
watchOS, WCSession activationDidCompleteWith activated , yet is not reachable
For those in a similar boat, I never ended up finding the cause of this problem. However, as a bit of a workaround, I looped up my start session function, to attempt a new connection every couple of seconds when a connection has failed, and it needs to send/receive data. The second connection attempt was basically successful every time.
Unable to activate WCSession
Implement the new WCSessionDelegate callback so you can receive any errors / tell when the session activates.
optional func session(_ session: WCSession,
activationDidCompleteWithState activationState: WCSessionActivationState,
error error: NSError?)
or
- (void)session:(WCSession *)session
activationDidCompleteWithState:(WCSessionActivationState)activationState
error:(NSError *)error
How to fix [WC] denying activation due to missing delegate Swift
These two lines make no sense
session?.delegate = self // session is still nil here, delegate won't be set
session = WCSession.default
change the order to
session = WCSession.default
session?.delegate = self
Related Topics
Get Rawvalue from Enum in a Generic Function
Swift Struct Doesn't Conform to Protocol Equatable
Difference Between Packed VS Normal Data Type
Disable Audio (And Interruption) with Mpmovieplayercontroller Using Swift
Checking If a Swift Class Conforms to a Protocol and Implements an Optional Function
Uicollectionviewcell Register Class Fails, But Register Nib Works
Making Cocoa Application Scriptable Swift
Cannot Assign to Property: 'Self' Is Immutable, I Know How to Fix But Needs Understanding
Initialization of 'Unsafemutablerawpointer' Results in a Dangling Pointer
Swift Await/Async - How to Wait Synchronously for an Async Task to Complete
Unsafemutablepointer<Uint8> to [Uint8] Without Memory Copy
In Swift, When Using "[Weak Self] In", Should I Double Up on It When Nested Inside Another Closure
Delegate Using Container View in Swift
Apple MACh-O Linker Error, After Changing Project Name
An Nsmanagedobject of Class 'Classname' Must Have a Valid Nsentitydescription.' Error