サンディープ サンディープ - 2 months ago 53
iOS Question

Watchkit new session does not work

I have two view controllers in my watch extension.Whenever I call

[[WCSession defaultSession] sendMessage:applicationData replyHandler:^(NSDictionary *reply) {}


I get response only for the first view controller, and error in my second viewcontroller

Error Domain=WCErrorDomain Code=7011 "Message reply failed."
UserInfo={NSUnderlyingError=0x79f1f100 {Error Domain=WCErrorDomain Code=7010 "Payload contains unsupported type."
UserInfo={NSLocalizedRecoverySuggestion=Only pass valid types., NSLocalizedDescription=Payload contains unsupported type.}}, NSLocalizedDescription=Message reply failed.}


WCSession is initiated in both app and watch extension.Any suggestions?

Answer

I solved it by sending JSON string in dictionary format directly to the call back method from the iPhone app Appdelegate

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

instead of converting the JSON dictionary to normal dictionary. And converting this JSON dictionary to normal dictionary in the watch viewcontroller call back methods

[[WCSession defaultSession] sendMessage:applicationData
                           replyHandler:^(NSDictionary *reply) {}

Since I was calling this methods from two different viewcontrollers in watch,sending normal dictionary from the iPhone app to watch works fine the first time but for some reasons I was getting the errors in the question if I send the dictionary from the iPhone app to watch for the second view controller of watch.