小程序打开app分两种情况:
app直接打开微信小程序之后的返回app
WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];launchMiniProgramReq.userName = userName;launchMiniProgramReq.path =path;launchMiniProgramReq.miniProgramType = miniProgramType;[WXApi sendReq:launchMiniProgramReq];复制代码
这种情况下,在微信小程序点击打开app的时候走的函数是:
- (void)onResp:(BaseResp *)resp{ if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) { NSString *errMsg = [NSString stringWithFormat:@"errorcode:%@",((WXLaunchMiniProgramResp*)resp).extMsg]; NSLog(@"errcode:%@",errMsg); }}复制代码
app分享到微信聊天,然后在聊天里面打开小程序,再跳转回app
WXMiniProgramObject *object = [WXMiniProgramObject object];object.webpageUrl = urlobject.userName = username;object.hdImageData = dataobject.path = pathWXMediaMessage *message = [WXMediaMessage message];message.title = title;message.description = descriptionStr;message.thumbData = nil;message.mediaObject = object;SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];req.bText = NO;req.message = message;req.scene = WXSceneSession; //目前只支持会话[WXApi sendReq:req];复制代码
这种情况下打开app传参走的是
- (void)onReq:(BaseReq *)req{ NSLog(@"req is %@",req); if ([req isKindOfClass:[LaunchFromWXReq class]]) { LaunchFromWXReq *wxReq = (LaunchFromWXReq*)req; WXMediaMessage *message = wxReq.message; NSString *messageExt = message.messageExt; NSLog(@"ext message is %@",messageExt); }}复制代码
通常我们走的是第二种方式,这里很坑,微信文档也没有写详细。