Reputation: 47
I'm trying for 3 days to get this work, but it doesn't :/
I want to send some message to my watch. But the function session doesn't get called.
In my parent I use this code to open the session:
- (void)viewDidLoad {
[super viewDidLoad];
if ([WCSession isSupported]) {
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
}
}
Then I want to send a dictionary to my app if a button is pressed:
-(void)clickBackButton{
NSArray *obj = @[@"Mercedes-Benz SLK250", @"Mercedes-Benz E350"];
NSArray *key = @[[NSNumber numberWithInt:13], [NSNumber numberWithInt:22]];
NSDictionary *applicationDict = [NSDictionary dictionaryWithObject:obj forKey:key];
[[WCSession defaultSession] transferUserInfo:applicationDict];
}
In my watch I use this code for the session:
override func willActivate() {
super.willActivate()
if (WCSession.isSupported()) {
session = WCSession.defaultSession()
session.delegate = self
session.activateSession()
}
}
And this method never gets called:
func session(session: WCSession, didFinishUserInfoTransfer userInfoTransfer: WCSessionUserInfoTransfer, error: NSError?) {
print("session called")
}
Upvotes: 0
Views: 420
Reputation: 4656
The delegate method you are looking for is session:didReceiveUserInfo:
. If you read the comments above the delegate methods you will see that the one you have implemented on the receiving side (in your case the watch) is the one that gets called on the sending side to confirm the transfer completed!
/** Called on the sending side after the user info transfer has successfully completed or failed with an error. Will be called on next launch if the sender was not running when the user info finished. */
- (void)session:(WCSession * __nonnull)session didFinishUserInfoTransfer:(WCSessionUserInfoTransfer *)userInfoTransfer error:(nullable NSError *)error;
/** Called on the delegate of the receiver. Will be called on startup if the user info finished transferring when the receiver was not running. */
- (void)session:(WCSession *)session didReceiveUserInfo:(NSDictionary<NSString *, id> *)userInfo;
Upvotes: 1