Gaurav Parvadiya
Gaurav Parvadiya

Reputation: 149

WCSession activate session not calling delegate method

I have this code written in my Manager class init method.

if([WCSession isSupported]) {
   WCSession *session = [WCSession defaultSession];
   session.delegate = self;
   [session activateSession];
}

Also, implemented these delegate methods in manager class.

- (void)session:(WCSession *)session activationDidCompleteWithState:(WCSessionActivationState)activationState error:(NSError *)error {
    if(error) {
        NSLog(@"%@", error.description);
    }

    NSLog(@"iOS App Session activated.");
}

- (void)sessionDidBecomeInactive:(nonnull WCSession *)session {
    //
}


- (void)sessionDidDeactivate:(nonnull WCSession *)session {
    //
}

- (void)sessionReachabilityDidChange:(WCSession *)session {
    //
}

Watch app InterfaceController delegate method:

- (void)session:(WCSession *)session didReceiveApplicationContext:(NSDictionary<NSString *,id> *)applicationContext {
    //
}

My problems are:

  1. activationDidCompleteWithState is never being called.
  2. I am calling updateContext method to send data to watch app but didReceiveApplicationContext method never being called in InterfaceController.

Upvotes: 1

Views: 334

Answers (2)

Gaurav Parvadiya
Gaurav Parvadiya

Reputation: 149

I got the solution for above issue. It is the problem with simulators. So I would prefer to test Watch app with real device. My same code is working fine when tested with real device.

Upvotes: 0

stipus
stipus

Reputation: 46

You have to retain the WCSession object in a member variable.

@property (nonatomic, strong) WCSession* wcSession;
...

if ([WCSession isSupported])
{
    self.wcSession = [WCSession defaultSession];
    self.wcSession.delegate = self;
    [self.wcSession activateSession];
}

Upvotes: 0

Related Questions