RN:react-native-wechat-lib
2023-06-13 本文已影响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.pngc. 配置 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];
}