mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-17 18:56:09 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4099986a9c | ||
![]() |
48101bbd51 | ||
![]() |
1c2507e631 | ||
![]() |
b5e273deef | ||
![]() |
b55a40c92c | ||
![]() |
d23178a851 |
@@ -15,10 +15,13 @@
|
||||
```bash
|
||||
npm i -g react-native-update-cli
|
||||
npm i react-native-update@具体版本请看下面的表格
|
||||
react-native link react-native-update
|
||||
```
|
||||
|
||||
`npm install -g react-native-update-cli`这一句在每一台电脑上仅需运行一次。
|
||||
如果你的RN版本 < 0.60,那么还需要运行
|
||||
|
||||
```bash
|
||||
react-native link react-native-update
|
||||
```
|
||||
|
||||
* 注意 *
|
||||
|
||||
@@ -41,7 +44,6 @@ nrm use taobao
|
||||
| 0.46及以上 | 5.x |
|
||||
|
||||
|
||||
|
||||
安装命令示例:
|
||||
```
|
||||
npm i react-native-update@5.x
|
||||
@@ -49,7 +51,7 @@ npm i react-native-update@5.x
|
||||
|
||||
## 一、手动link
|
||||
|
||||
如果第一步的`react-native link`已成功(iOS工程和安卓工程均能看到依赖),可以跳过此步骤
|
||||
如果RN版本 >= 0.60,或是`react-native link`执行成功(iOS工程和安卓工程均能看到依赖),则可以跳过此步骤
|
||||
|
||||
### iOS
|
||||
|
||||
@@ -69,43 +71,57 @@ npm i react-native-update@5.x
|
||||
|
||||
2. 在`android/app/build.gradle`的 dependencies 部分增加如下代码:
|
||||
```
|
||||
compile project(':react-native-update')
|
||||
implementation project(':react-native-update')
|
||||
```
|
||||
|
||||
3. 检查你的RN版本,如果是0.29及以上, 打开`android/app/src/main/java/[...]/MainApplication.java`,否则打开`android/app/src/main/java/[...]/MainActivity.java`
|
||||
3. 打开`android/app/src/main/java/[...]/MainApplication.java`,
|
||||
- 在文件开头增加 `import cn.reactnative.modules.update.UpdatePackage;`
|
||||
- 在`getPackages()` 方法中增加 `new UpdatePackage()`(注意上一行可能要增加一个逗号)
|
||||
|
||||
## 二、配置Bundle URL
|
||||
|
||||
注意此步骤无论任何版本,目前都需要手动配置。
|
||||
|
||||
### iOS
|
||||
|
||||
首先在工程target的Build Phases->Link Binary with Libraries中加入`libz.tbd`、`libbz2.1.0.tbd`
|
||||
1. (RN >= 0.60或者使用CocoaPods集成此步可跳过)在工程target的Build Phases->Link Binary with Libraries中加入`libz.tbd`、`libbz2.1.0.tbd`
|
||||
|
||||
|
||||
然后在你的AppDelegate.m文件中增加如下代码:
|
||||
2. 在你的AppDelegate.m文件中增加如下代码:
|
||||
|
||||
```objective-c
|
||||
// ... 其它代码
|
||||
|
||||
#import "RCTHotUpdate.h"
|
||||
|
||||
// 如果RN版本 >= 0.59,修改sourceURLForBridge
|
||||
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
||||
{
|
||||
#if DEBUG
|
||||
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
|
||||
#else
|
||||
// 非DEBUG情况下替换为热更新bundle
|
||||
return [RCTHotUpdate bundleURL];
|
||||
#endif
|
||||
}
|
||||
|
||||
// 如果RN版本 < 0.59,修改didFinishLaunchingWithOptions
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
#if DEBUG
|
||||
// 原来的jsCodeLocation保留在这里
|
||||
jsCodeLocation = ..........
|
||||
#else
|
||||
// 非DEBUG情况下启用热更新
|
||||
// 非DEBUG情况下替换为热更新bundle
|
||||
jsCodeLocation = [RCTHotUpdate bundleURL];
|
||||
#endif
|
||||
// ... 其它代码
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Android
|
||||
|
||||
`0.29及以后版本`:在你的MainApplication中增加如下代码:
|
||||
在MainApplication中增加如下代码:
|
||||
|
||||
```java
|
||||
// ... 其它代码
|
||||
@@ -124,24 +140,6 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
}
|
||||
```
|
||||
|
||||
`0.28及以前版本`:在你的MainActivity中增加如下代码:
|
||||
|
||||
```java
|
||||
// ... 其它代码
|
||||
|
||||
// 请注意不要少了这句import
|
||||
import cn.reactnative.modules.update.UpdateContext;
|
||||
|
||||
public class MainActivity extends ReactActivity {
|
||||
|
||||
@Override
|
||||
protected String getJSBundleFile() {
|
||||
return UpdateContext.getBundleUrl(this);
|
||||
}
|
||||
// ... 其它代码
|
||||
}
|
||||
```
|
||||
|
||||
## 三、登录与创建应用
|
||||
|
||||
首先请在<https://update.reactnative.cn>注册帐号,然后在你的项目根目录下运行以下命令:
|
||||
@@ -170,7 +168,7 @@ App Name: <输入应用名字>
|
||||
```bash
|
||||
$ pushy selectApp --platform ios
|
||||
1) 鱼多多(ios)
|
||||
3) 招财旺(ios)
|
||||
2) 招财旺(ios)
|
||||
|
||||
Total 2 ios apps
|
||||
Enter appId: <输入应用前面的编号>
|
||||
|
37
index.d.ts
vendored
Normal file
37
index.d.ts
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
export const downloadRootDir: string;
|
||||
export const packageVersion: string;
|
||||
export const currentVersion: string;
|
||||
export const isFirstTime: boolean;
|
||||
export const isRolledBack: boolean;
|
||||
|
||||
export interface ExpiredResult {
|
||||
expired: true;
|
||||
downloadUrl: string;
|
||||
}
|
||||
|
||||
export interface UpTodateResult {
|
||||
upToDate: true;
|
||||
}
|
||||
|
||||
export interface UpdateAvailableResult {
|
||||
update: true;
|
||||
name: string; // version name
|
||||
hash: string;
|
||||
description: string;
|
||||
metaInfo: string;
|
||||
updateUrl: string;
|
||||
pdiffUrl: string;
|
||||
diffUrl: string;
|
||||
}
|
||||
|
||||
export type CheckResult = Partial<ExpiredResult & UpTodateResult & UpdateAvailableResult>;
|
||||
|
||||
export function checkUpdate(appkey: string): Promise<CheckResult>;
|
||||
|
||||
export function downloadUpdate(options: UpdateAvailableResult): Promise<undefined | string>;
|
||||
|
||||
export function switchVersion(hash: string): void;
|
||||
|
||||
export function switchVersionLater(hash: string): void;
|
||||
|
||||
export function markSuccess(): void;
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "5.1.9",
|
||||
"version": "5.2.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
|
36
react-native-update.podspec
Normal file
36
react-native-update.podspec
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'json'
|
||||
|
||||
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = package['name']
|
||||
s.version = package['version']
|
||||
s.summary = package['description']
|
||||
s.license = package['license']
|
||||
|
||||
s.authors = package['author']
|
||||
s.homepage = package['homepage']
|
||||
|
||||
s.platform = :ios, "7.0"
|
||||
s.source = { :git => 'https://github.com/reactnativecn/react-native-pushy.git', :tag => '#{s.version}' }
|
||||
s.libraries = 'bz2', 'z'
|
||||
s.vendored_libraries = 'RCTHotUpdate/libRCTHotUpdate.a'
|
||||
s.pod_target_xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"$(SRCROOT)/../node_modules/react-native-update/ios"' }
|
||||
|
||||
s.dependency 'React'
|
||||
|
||||
s.subspec 'RCTHotUpdate' do |ss|
|
||||
ss.source_files = 'ios/RCTHotUpdate/*.{h,m}'
|
||||
ss.public_header_files = ['ios/RCTHotUpdate/RCTHotUpdate.h']
|
||||
end
|
||||
|
||||
s.subspec 'SSZipArchive' do |ss|
|
||||
ss.source_files = 'ios/RCTHotUpdate/SSZipArchive/**/*.{h,m,c}'
|
||||
ss.private_header_files = 'ios/RCTHotUpdate/SSZipArchive/**/*.h'
|
||||
end
|
||||
|
||||
s.subspec 'BSDiff' do |ss|
|
||||
ss.source_files = 'ios/RCTHotUpdate/BSDiff/**/*.{h,m,c}'
|
||||
ss.private_header_files = 'ios/RCTHotUpdate/BSDiff/**/*.h'
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user