iOS invokes WeChat applet

Recently made a new feature. Click the button in the App to evoke the WeChat applet.

App configuration

insert image description here
Let's talk about the configuration steps of applink later.
The above applink is not filled in casually, it needs to be consistent with the WeChat developer platform.
insert image description here
All the above configuration data need to be obtained from the WeChat developer platform.

WeChat developer platform configuration

Scheme 1 sharesdk:

The project has already used the shareSDK (v 4.4.9 version) and contains the WeChat SDK, so you can directly use the shareSDK package method call.
insert image description here

.h file

// 引入头文件
#import <WechatConnector/WechatConnector.h>

Use below code where button click is required

// 点击按钮 唤起微信小程序
 [WeChatConnector openMiniProgramWithUserName:@"需要跳转的小程序的原始名称" path:@"需要跳转的小程序的页面地址" miniProgramType:0 extMsg:@"" extDic:@{
    
    } complete:^(BOOL success) {
    
    
        if (success) {
    
    
            NSLog(@"ok===");
       }else{
    
    
            NSLog(@"no");
      }
 }];

Problem: The clipboard function cannot be used when using the above method.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = [NSString stringWithFormat:@“%@”,self.car.VINCode];
// If you need to use this function, it is not recommended to use the shareSDK encapsulation method.

Solution 2: WechatOpenSDK (recommended)

1. Configuration:
insert image description here
2. Register WeChat in Appdelegate
insert image description here
3. Use the following code where you need to use the evoked applet

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
 pasteboard.string = [NSString stringWithFormat:@"需要复制的内容"];
        
 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"即将打开  ”助手“ 小程序" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"允许" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    
    
 // 拉起微信小程序
 WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
launchMiniProgramReq.userName = @"gh_123456789";  //拉起的小程序的username
launchMiniProgramReq.path = @"pages/index/index";    //拉起小程序页面的可带参路径,不填默认拉起小程序首页
 launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
 [WXApi sendReq:launchMiniProgramReq completion:nil];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];

[self presentViewController:alertController animated:YES completion:nil];

Guess you like

Origin blog.csdn.net/c1o2c3o4/article/details/128345533