1

I am working on sample watch kit app (Apple Watch + iPhone). Here my app is syncing fine. And also I worked on WCSession using data transferring (iPhone to apple watch). It is working fine when both are in active state. But I couldn't transfer data to Applewatch if it is inactive state (background state, sleep mode or foreground state). delegate method not calling.

- (void)applicationDidBecomeActive {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
if ([WCSession isSupported]) {
    WCSession *session = [WCSession defaultSession];
    session.delegate = self;
    [session activateSession];
}
}

Here is my delegate method.

 - (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message replyHandler:(nonnull void (^)(NSDictionary<NSString *,id> * __nonnull))replyHandler {}

Please help me.

udaysagar
  • 3
  • 5
narendrakumar b
  • 115
  • 1
  • 12
  • iWatch suppose to work that way only. You shouldn't expect it to open by the iPhone immediately but the reverse because they run only while the user interacts with one of their interfaces. There are some exceptions but those exceptions do not cover waking up from iPhone. You have to find other way around to interact with the iWatch or slightly tweak the app feature. – Tushar Dec 19 '16 at 13:39

2 Answers2

1

If iOS device and Apple watch are paired. Then when sending message through using WCSession, it will automatically wake the app.

Arasuvel
  • 2,971
  • 1
  • 25
  • 40
1

By using the follwing code i solved my problem.

In Viewcontroller :

// Sending data to iphone to applewatch
WCSession *session = [WCSession defaultSession];
    NSError *error;
    [session updateApplicationContext:@{@"counterValue":@"counter", @"userId":@"id"} error:&error];

Applewatch : (Interfacecontroller)

//Receiving data in applewatch from iphone
- (void) session:(nonnull WCSession* )session didReceiveApplicationContext:(nonnull NSDictionary<NSString * ,id> *)applicationContext {
}
narendrakumar b
  • 115
  • 1
  • 12