Reputation: 149
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:
Upvotes: 1
Views: 334
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
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