APP跳转小程序,小程序跳转APP,看我就够了

本文涉及的内容:APP跳转小程序,跳转指定页面,传参。APP分享小程序。小程序跳转APP,传参。默认已集成微信SDK,需要在微信开发平台-管理中心-小程序-绑定小程序。
1,APP跳转小程序,跳转指定页面,传参

        WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
        launchMiniProgramReq.userName = @"gh_1f7e9fe9b357";//填小程序原始id
        launchMiniProgramReq.path = @"pages/index/index?key1=2&key2=3";//拉起小程序页面的可带参路径,不填默认拉起小程序,类似http的url方法来传递参数
        launchMiniProgramReq.miniProgramType = WXMiniProgramTypePreview;
        //WXMiniProgramTypeRelease  正式版  WXMiniProgramTypeTest 开发版 WXMiniProgramTypePreview 体验版 
        [WXApi sendReq:launchMiniProgramReq];

2, APP分享小程序

- (void)shareMiniProgramToPlatformType:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    UMShareMiniProgramObject *shareObject = [UMShareMiniProgramObject shareObjectWithTitle:@"小程序标题" descr:@"小程序内容描述" thumImage:[UIImage imageNamed:@"logo1"]];
    shareObject.webpageUrl = self.shareUrl;//兼容微信低版本网页地址
    shareObject.userName = @"gh_1f7e9fe9b357";
    shareObject.path = @"pages/index/index?key1=2&key2=3";//小程序页面路径,如 pages/page10007/page10007
    messageObject.shareObject = shareObject;
//    shareObject.hdImageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logo" ofType:@"png"]];
    shareObject.miniProgramType = UShareWXMiniProgramTypePreview; // 可选体验版和开发板
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
        [self alertWithError:error];
    }];
}

3,小程序跳转APP,传参
(1)分享完小程序后直接回到APP

-(void)onResp:(BaseResp *)resp 
{
   
}

(2) 从小程序中返回APP

- (void)onReq:(BaseReq *)req{
    if ([req isKindOfClass:[LaunchFromWXReq class]])
    {
        LaunchFromWXReq *smallProgram = (LaunchFromWXReq*)req;
        WXMediaMessage *message = smallProgram.message;
        NSLog(@"%@",message.messageExt);//小程序跳转app传的参数
        return;
    }
}

你可能感兴趣的:(APP跳转小程序,小程序跳转APP,看我就够了)