美文网首页
RN:react-native-wechat-lib

RN:react-native-wechat-lib

作者: 春暖花已开 | 来源:发表于2023-06-13 10:58 被阅读0次

    准备工作:
    假设公司域名为https://www.abc.com

    1、在服务器根目录添加文件 apple-app-site-association,其 appID 的规则为teamId.bundleId,示例如下:

    {
      "applinks": {
        "apps": [],
        "details": [
          {
            "appID": "277J975988.org.reactjs.native.example.zxmall",
            "paths": ["/app/*"]
          }
        ]
      }
    }
    

    注意:在微信开放平台创建应用,universal link应为 服务器域名+paths里的路径,则universal link为 https://www.abc.com/app/

    2、配置Xcode:

    a. 配置Info.plist:(如果不配置,系统会因为安全机制的问题,阻止跳转到微信)

    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>weixin</string>
      <string>wechat</string>
      <string>weixinULAPI</string>
    </array>
    

    b. 配置URL Types:(首先需要在微信开放平台创建应用,之后拿到18位的AppId,填到下面)

    url_types.png

    c. 配置 Associated Domains,格式为 applinks:域名

    示例:applinks:www.zhuoxunhulian.com

    d. 代码配置:

    // AppDelegate.h
    #import <React/RCTBridgeDelegate.h>
    #import <UIKit/UIKit.h>
    #import "WXApi.h"
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, WXApiDelegate>
    
    @property (nonatomic, strong) UIWindow *window;
    
    @end
    
    // AppDelegate.m
    - (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
      [RCTLinkingManager application:application openURL:url options:options];
      return [WXApi handleOpenURL:url delegate:self];
    }
    
    - (BOOL)application:(UIApplication *)application
      continueUserActivity:(NSUserActivity *)userActivity
      restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable
      restorableObjects))restorationHandler {
      [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
      return [WXApi handleOpenUniversalLink:userActivity
      delegate:self];
    }
    

    相关文章

      网友评论

          本文标题:RN:react-native-wechat-lib

          本文链接:https://www.haomeiwen.com/subject/fmjcydtx.html