Skip to content

Commit

Permalink
chore: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroenzo committed Nov 28, 2024
1 parent a552d90 commit 5d6c8be
Showing 1 changed file with 63 additions and 42 deletions.
105 changes: 63 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# react-native-unimp

集成uni小程序SDK,支持**Android****iOS**
> 集成uni小程序SDK,支持**Android****iOS**,目前只集成了基础模块,其他原生功能依赖库需要自行集成。
## SDK 版本
当前已更新至2024年10月08日发布的 **SDK 4.29 版本**

## 示例

完整示例可以查看 [react-native-unimp-example](https://github.com/Hiroenzo/react-native-unimp-example)

## 安装

Expand Down Expand Up @@ -30,7 +37,7 @@ Unimp.initialize(
## 配置
### Android配置

1、添加资源文件
#### 1. 添加资源文件

uni小程序SDK包文件夹目录结构说明:

Expand All @@ -50,28 +57,40 @@ uni小程序SDK包文件夹目录结构说明:

SDK包中的**assets**需要拷贝到项目中,目录一般在**app/src/main/assets**下.


2、导入小程序应用资源
#### 2. 导入小程序应用资源

打开android原生项目。在主Module模块的assets路径下创建apps/(内置uni小程序的appid)/www 路径,例如**apps/__UNI__04E3A11/www**,将之前导出的应用资源包解压释放到apps/__UNI__04E3A11/www路径下(解压方法将资源包的扩展 .wgt 重命名为 .zip 然后使用解压软件打开)

3、修改gradle配置
#### 3. 修改gradle配置

**android/app/build.gradle**中,添加以下配置,否则可能会出现无法开启小程序,并提示 **运行路径中无 uni 小程序(\_\_UNI\_\_XXXXXXXX)应用资源,请检查应用资源是否正常部署**的问题:

```
android {
//此处配置必须添加 否则无法正确运行
aaptOptions {
additionalParameters '--auto-add-overlay'
//noCompress 'foo', 'bar'
ignoreAssetsPattern "!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"
}
//此处配置必须添加 否则无法正确运行
aaptOptions {
additionalParameters '--auto-add-overlay'
//noCompress 'foo', 'bar'
ignoreAssetsPattern "!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"
}
}
```

#### 4. 异常情况

如果出现打开小程序后界面空白,**Logcat**显示以下日志,需要将**android/build.gradle****targetSdkVersion**改为**28**即可。

```azure
2024-11-28 16:10:12.573 6748-7055 WXParams com.unimpexample E setCrashFilePath: /data/user/0/com.unimpexample/app_crash
2024-11-28 16:10:12.573 6748-7055 weex com.unimpexample E getUseSingleProcess is running false
2024-11-28 16:10:12.573 6748-7055 weex com.unimpexample E getReleaseMap:true
2024-11-28 16:10:12.573 6748-7055 weex com.unimpexample E getLibJsbPath is running /data/user/0/com.unimpexample/cache/cache/weex/libs/weexjsb/arm64-v8a/libweexjsb.so
2024-11-28 16:10:12.573 6748-7055 weex com.unimpexample E getLibLdPath is running /data/app/com.unimpexample-_xag59cq6fFJxVJuCI463A==/lib/arm64:/data/app/com.unimpexample-_xag59cq6fFJxVJuCI463A==/base.apk!/lib/arm64-v8a
```

### iOS配置

1、初始化 sdk engine
#### 1. 初始化 sdk engine

**AppDelegate.m**中:

Expand All @@ -81,75 +100,77 @@ android {
...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 配置参数
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithDictionary:launchOptions];
// 设置 debug YES 会在控制台输出 js log,默认不输出 log,注:需要引入 liblibLog.a 库
[options setObject:[NSNumber numberWithBool:YES] forKey:@"debug"];
// 初始化引擎
[DCUniMPSDKEngine initSDKEnvironmentWithLaunchOptions:options];
return YES;
// Override point for customization after application launch.

// 配置参数
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithDictionary:launchOptions];
// 设置 debug YES 会在控制台输出 js log,默认不输出 log,注:需要引入 liblibLog.a 库
[options setObject:[NSNumber numberWithBool:YES] forKey:@"debug"];
// 初始化引擎
[DCUniMPSDKEngine initSDKEnvironmentWithLaunchOptions:options];

return YES;
}

...

#pragma mark - App 生命周期方法
- (void)applicationDidBecomeActive:(UIApplication *)application {
[DCUniMPSDKEngine applicationDidBecomeActive:application];
[DCUniMPSDKEngine applicationDidBecomeActive:application];
}

- (void)applicationWillResignActive:(UIApplication *)application {
[DCUniMPSDKEngine applicationWillResignActive:application];
[DCUniMPSDKEngine applicationWillResignActive:application];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
[DCUniMPSDKEngine applicationDidEnterBackground:application];
[DCUniMPSDKEngine applicationDidEnterBackground:application];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
[DCUniMPSDKEngine applicationWillEnterForeground:application];
[DCUniMPSDKEngine applicationWillEnterForeground:application];
}

- (void)applicationWillTerminate:(UIApplication *)application {
[DCUniMPSDKEngine destory];
[DCUniMPSDKEngine destory];
}

...

#pragma mark - 如果需要使用 URL Scheme 或 通用链接相关功能,请实现以下方法
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
// 通过 url scheme 唤起 App
[DCUniMPSDKEngine application:app openURL:url options:options];
return YES;
// 通过 url scheme 唤起 App
[DCUniMPSDKEngine application:app openURL:url options:options];
return YES;
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
// 通过通用链接唤起 App
[DCUniMPSDKEngine application:application continueUserActivity:userActivity];
return YES;
// 通过通用链接唤起 App
[DCUniMPSDKEngine application:application continueUserActivity:userActivity];
return YES;
}

```

2、导入小程序应用资源
#### 2. 导入小程序应用资源

打开原生工程目录,在iOS项目路径中创建名称为Apps的文件夹,将之前导出的wgt包拷贝到Apps文件夹中,再右键菜单中选择Add Files to “工程名...”,然后打开工程目录,选择 Apps 文件夹,然后点击“Add”,将应用资源包添加到工程中。

3、配置CocoaPods
> iOS已改用Pod方式集成,以下配置可以跳过
打开**podfile**文件,添加以下内容:
#### ~~3. 配置CocoaPods~~

```
target 'XXX' do
pod 'SSZipArchive'
~~打开**podfile**文件,添加以下内容:~~

...
end
```
# target 'XXX' do
# pod 'SSZipArchive'
#
# ...
# end
```

在工程的**Build Settings -> Preprocessor Macros -> Debug****Release**中分别添加**HAVE_INTTYPES_H****HAVE_PKCRYPT****HAVE_STDINT_H****HAVE_WZAES****HAVE_ZLIB** 这 5 个宏定义(注意:原有的配置项下不要删除,点击+号添加))
~~在工程的**Build Settings -> Preprocessor Macros -> Debug****Release**中分别添加**HAVE_INTTYPES_H****HAVE_PKCRYPT****HAVE_STDINT_H****HAVE_WZAES****HAVE_ZLIB** 这 5 个宏定义(注意:原有的配置项下不要删除,点击+号添加))~~


## 支持的接口
Expand Down

0 comments on commit 5d6c8be

Please sign in to comment.