Been battling with this for hours how - I have an existing Objective C application and I’m trying to add an iWatch application in Swift. I only have the simulator available - and I can’t get even a simple data transfer to work.
Does anyone have any experience with Phone Objective C to Watch Swift Connectivity working - ideally an example?
Head is being to hurt from hitting it against a brick wall.
Thanks.
Hi @alexonit
There shouldn’t be any problems between connecting the obj c and swift code. Can you please specify what exactly are your struggling with? Are there compile errors, crashes?
Here is a link to a related question, maybe it will be useful - I have an Objective-C application on iOS, how do I build a Swift Watch extension? - Stack Overflow
Nikita
iPhone Objective-C in AppDelegate :
NSError *error;
if ( [WCSession isSupported])
{
NSDictionary *movies = @{@"key1":@"Eezy"};
wcSession = [WCSession defaultSession];
if ([wcSession isWatchAppInstalled])
{
[wcSession updateApplicationContext:movies error:&error];
iWatch Swift - In ExtensionDelegate
extension ExtensionDelegate: WCSessionDelegate {
…
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
print("ExtensionDelegate:didReceiveApplicationContext got here")
Some Debugging shows
ExtensionDelegate:setupWatchConnectivity:WCSession.isSupported
WC Session activated with state: activated
No error messages.
iOS says
AppDelegate:sendDataToWatch:isPaired
AppDelegate:sendDataToWatch:isReachable
AppDelegate:sendDataToWatch:isSupported
AppDelegate:sendDataToWatch:isWatchAppInstalled
iWatch says
ExtensionDelegate:setupWatchConnectivity:WCSession.isSupported
WC Session activated with state: activated
ExtensionDelegate:IsReachable:true
Nothing is being triggered on the iWatch to say data is being received.
Changed it to [wcSession transferUserInfo:xyz]; and it all started working.