iOS第三方app可以打开小程序,但是不能分享小程序?
发布于 6 年前 作者 cqiao 8385 次浏览 来自 问答

我在从调用iOS打开小程序时,可以打开,但是分享小程序的时候却提示“应用和小程序未绑定在同一微信开放平台账号”

分享的时候,会跳转两次,第一次如图,并且代码success返回也是YES

[WXApi sendReq:req completion:^(BOOL success) {
        completion(success);
    }];

但实际上是已经绑定在同一个账号下了

提示如下图:

背景如下:

  1. app是有关联小程序的,也执行过WXApi 下面这个方法了;

    + (BOOL)registerApp:(NSString *)appid universalLink:(NSString *)universalLink;

  2. 小程序只发布了体验版,正式版尚未发布;

  3. 分享小程序的时候代码如下:


    /// 分享微信小程序
    + (void)shareMiniProgramWithTitle:(NSString *)title
                              hdImage:(UIImage *)hdImage
                             userName:(NSString *)userName
                           webpageUrl:(NSString *)webpageUrl
                                 path:(NSString *)path
                      miniProgramType:(WXMiniProgramType)type
                           completion:(void (^ __nullable)(BOOL success))completion {
        WXMiniProgramObject *object = [WXMiniProgramObject object];
        object.webpageUrl = webpageUrl;
        object.userName = userName;
        object.path = path;
        NSData * imageData = UIImageJPEGRepresentation(hdImage, 0.7);
        object.hdImageData = imageData;
        object.withShareTicket = YES;
        object.miniProgramType = type;
        WXMediaMessage *message = [WXMediaMessage message];
        message.title = title;
        message.description = @"山证工作室";
        message.thumbData = nil;
        //兼容旧版本节点的图片,小于32KB,新版本优先
        //使用WXMiniProgramObject的hdImageData属性
        message.mediaObject = object;
        SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
        req.bText = NO;
        req.message = message;
        req.scene = WXSceneSession;  //目前只支持会话
        [WXApi sendReq:req completion:^(BOOL success) {
            completion(success);
        }];
    }
  4. 打开小程序代码如下:

    /// 打开微信小程序
    + (void)openMiniProgramWithUserName:(NSString *)userName
                                   Path:(NSString *)path
                        miniProgramType:(WXMiniProgramType)type
                             completion:(void (^ __nullable)(BOOL success))completion {
        WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
        launchMiniProgramReq.userName = userName;  //拉起的小程序的username
        launchMiniProgramReq.path = path;    //拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
        launchMiniProgramReq.miniProgramType = type; //拉起小程序的类型
        [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
            completion(success);
        }];
    }
回到顶部