WCSession transferFile and transferUserInfo problem

The two background delivery methods (transferFile, transferUserInfo) usually stop working on watchOS 2.2 and only a watch restart helps to get them work again. After restarting, they work for a while the way they always should, then stop working again... Other methods (sendMessage, sendMessageData) are ok.

There was not any problems like this on watchOS 2.1.


Has anyone experienced this? Any workoaround?

Replies

I had a problem like this, and solved it by putting all my sending and receiving code in a block like this:


dispatch_async(dispatch_get_main_queue(), {
     //RECEIVING CODE OR SENDING CODE IN HERE
})


This seemed to resolve all my issues, and data appears on my watch near instantly.

FYI My bug report was marked as Duplicate of 25065800 (Open)

Hello everyone, watchOS 2.2.1 beta 2 contains several important fixes in WatchConnectivity. Please see the release notes for details. I urge you to test your apps with this new beta, in conjunction with the iOS 9.3.2 beta 2. If you are still finding issues, please update your existing bug report, or file a new bug. If you post your bug numbers here, I will make sure to forward them to engineering.


Thank you.

-zk

Hello, unfortunately the issue is still present.. I was able to reproduce the issue twice today after updating to beta 2. I have sent continuity logs to the bug number: 25376759

Hello Musashi,


I'm very happy with beta 2 of watchOS 2.2.1.

I have tested it with beta 2 of iOS 9.3.2 and finally delegate method 'session:didReceiveFile:' on the Watch app is always being called after using 'transferFile:' on the iOS app.


Can you please answer the questions from my post above about how the 2 new delegate methods should be used:


- (void)sessionDidBecomeInactive:(WCSession *)session{
    CLS_LOG(@"AppDelegate: sessionDidBecomeInactive:");
}

- (void)sessionDidDeactivate:(WCSession *)session {
    CLS_LOG(@"AppDelegate: sessionDidDeactivate");
    [_watchSession activateSession];
}


Thanks.

Hi Martijn,


I am glad that you found the updates in watchOS 2.2.1 and iOS 9.3.2 beta 2 to be helpful.


Regarding your question about how to use the delegate methods that tell your app how the session activation state has changed, I would like to point you to the WCSession documentation, and the section on "Supporting Communication with Multiple Apple Watches":

https://developer.apple.com/library/ios/documentation/WatchConnectivity/Reference/WCSession_class/


There is also useful information in the reference for sessionDidBecomeActive(_:)

https://developer.apple.com/library/ios/documentation/WatchConnectivity/Reference/WCSessionDelegate_protocol/index.html#//apple_ref/occ/intfm/WCSessionDelegate/sessionDidBecomeInactive:


As mentioned, this callback gives your app a chance to clean up any state information or tasks that might be tied to the activation state of the session, and lets your app know not to start any more data transfers or messages until the session becomes active again.

For example, if you have a long-running task, such as a network fetch, after which you would send data to the watch, this delagate method might be called after you started that long running task, but before you initiated communicating the fetched information to the watch. In this case, you might chose to cancel the long running task.


And sessionDidDeactivate(_:)

https://developer.apple.com/library/ios/documentation/WatchConnectivity/Reference/WCSessionDelegate_protocol/index.html#//apple_ref/occ/intfm/WCSessionDelegate/sessionDidDeactivate:

This callback tells your app that a watch is not present anymore, and your app should not try to communicate with its watchOS counterpart.


If you still have questions after reviewing the documentation I have referenced, please let me know.

-zk


Update: I'd also like to call your attention to the QuickSwitch sample that demonstrates how this API is used with multiple watches:

https://developer.apple.com/library/ios/samplecode/QuickSwitch/Introduction/Intro.html#//apple_ref/doc/uid/TP40016647

My first implementation was,

Calling transferFile method when session became active... which was inside this delegate method:

func session(session: WCSession, activationDidCompleteWithState activationState: WCSessionActivationState, error: NSError?)


Because this delegate is called in background thread, I have actually commenced the file transfer in the background thread.

When I did, the file transferring process stuck somewhere between iPhone and AppleWatch, and it never response. It caused no error nor any responses.

Thanks LucasFray99🙂



Do not start file transferring in background thread. Make sure you start it from the main thread.

Could you explain the situation on the Apple Watch where you can get a WCSessionActivation state of Inactive? I did some testing yesterday, and only got Not Activated (before calling the WCSession activateSession) and Activated (once the delegate activationStateDidChange method is called)? Is this the expected behavior, or are there situations where I should expect to see the Inactive state?

That is expected behavior. Also take note that both:

- (void)sessionDidBecomeInactive:(WCSession *)session __IOS_AVAILABLE(9.3) __WATCHOS_UNAVAILABLE;
- (void)sessionDidDeactivate:(WCSession *)session __IOS_AVAILABLE(9.3) __WATCHOS_UNAVAILABLE;

are marked as unavailable on watchOS, so the session will never transition from any other state to neither WCSessionActivationStateInactive nor WCSessionActivationStateNotActivated.

Just installed iOS 9.3.2 Beta 4 and unfortunately issue is still prestent. Same scenario, session works fine for a while, after couple minutes or hours it stops working. Only restarting the device resumes proper operation between the Apple Watch and iPhone app. 😟

Anybody else having this issue?? Please advise..

I also see all forms of Watch -> iPhone communication stall at some point. Works fine for a good while then stops completely. Sending User Info, Messages and Context updates all fail. I see timeout errors on the Watch even though they are paired at the time when trying to send an instant message.


As well as the timeout error returned directly when I try to message the companion iPhone App, which I only do when it's reachable, I also see these errors in the Watch's log:


May 5 13:28:44 Alexs-AppleWatch Carousel[30] <Notice>: (Error) WatchKit: __43-[SPCompanionConnection receiveData:reply:]_block_invoke failed to initialize protoMessage, data=0x191f5558, len=12


The only way to fix this issue is to restart my iPhone. As soon as I do this all the user info and context updates are sent to the iPhone and conectivity works correctly again.


I'm using iOS 9.3.2 Beta 3 , watchOS 2.2.1 Beta 2

We have experienced the exact same behavior and we have received a number of reports from our users that are affected because data won't get passed between iPhone and Apple Watch. I don't know if it is related to same issue(s) that also affect transferUserInfo: or whether this is a different bug. It is massively frustrating to not be able to consistently reproduce this issue so that I could report it to Apple. It sometimes just occurs and then rebooting the devices usually reset the situation and everything works in a normal fashion.


I have also noticed the same thing with WCSession's reachability flag. It is marked as being 'true' by the framework (indicating that a message can be delivered from Apple Watch to iPhone) eventhough all communications have been stalled and iPhone isn't for some reason able to receive the message.

Just a short update. Unfortunately issue is still present in todays iOS final update of iOS 9.3.2

Another update from my tests. WatchOS 2.2.2 beta 2 seemed to fix this issue! After testing it for couple days, all of our functions to transfer data between devices worked very well.


Yesterday I have installed watchOS 3 beta 1 and the app works great as well!


Anybody can confirm too?

Hi!

Thank you!

I created a bug report with number 27107072 and added it to open radar: https://openradar.appspot.com/radar?id=6162639696691200

Im having issues with my watchOS 2.2.1