mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	避免在debug模式下调用
This commit is contained in:
		
							
								
								
									
										44
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								lib/index.js
									
									
									
									
									
								
							| @@ -1,11 +1,7 @@ | ||||
| /** | ||||
|  * Created by tdzl2003 on 4/4/16. | ||||
|  */ | ||||
| import { NativeAppEventEmitter, NativeModules } from 'react-native'; | ||||
| const { HotUpdate } = NativeModules; | ||||
|  | ||||
| const HotUpdate = require('react-native').NativeModules.HotUpdate; | ||||
| import {NativeAppEventEmitter} from 'react-native'; | ||||
|  | ||||
| let host = 'https://update.reactnative.cn/api'; | ||||
| const host = 'https://update.reactnative.cn/api'; | ||||
|  | ||||
| export const downloadRootDir = HotUpdate.downloadRootDir; | ||||
| export const packageVersion = HotUpdate.packageVersion; | ||||
| @@ -36,11 +32,20 @@ There is available update: | ||||
|   diffUrl: 'http://update-packages.reactnative.cn/hash', | ||||
| } | ||||
|  */ | ||||
|  | ||||
| function assertRelease() { | ||||
|   if (__DEV__) { | ||||
|     throw new Error('react-native-update can only run on RELEASE version.'); | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| export async function checkUpdate(APPKEY) { | ||||
|   assertRelease(); | ||||
|   const resp = await fetch(`${host}/checkUpdate/${APPKEY}`, { | ||||
|     method: 'POST', | ||||
|     headers: { | ||||
|       'Accept': 'application/json', | ||||
|       Accept: 'application/json', | ||||
|       'Content-Type': 'application/json', | ||||
|     }, | ||||
|     body: JSON.stringify({ | ||||
| @@ -53,10 +58,11 @@ export async function checkUpdate(APPKEY) { | ||||
|     throw new Error((await resp.json()).message); | ||||
|   } | ||||
|  | ||||
|   return await resp.json(); | ||||
|   return resp.json(); | ||||
| } | ||||
|  | ||||
| export async function downloadUpdate(options) { | ||||
|   assertRelease(); | ||||
|   if (!options.update) { | ||||
|     return; | ||||
|   } | ||||
| @@ -81,23 +87,21 @@ export async function downloadUpdate(options) { | ||||
|   return options.hash; | ||||
| } | ||||
|  | ||||
| export async function switchVersion(hash) { | ||||
|   HotUpdate.reloadUpdate({hashName:hash}); | ||||
| export function switchVersion(hash) { | ||||
|   assertRelease(); | ||||
|   HotUpdate.reloadUpdate({ hashName: hash }); | ||||
| } | ||||
|  | ||||
| export async function switchVersionLater(hash) { | ||||
|   HotUpdate.setNeedUpdate({hashName:hash}); | ||||
| export function switchVersionLater(hash) { | ||||
|   assertRelease(); | ||||
|   HotUpdate.setNeedUpdate({ hashName: hash }); | ||||
| } | ||||
|  | ||||
| export function markSuccess() { | ||||
|   assertRelease(); | ||||
|   HotUpdate.markSuccess(); | ||||
| } | ||||
|  | ||||
| NativeAppEventEmitter.addListener('RCTHotUpdateDownloadProgress', params => {}); | ||||
|  | ||||
| NativeAppEventEmitter.addListener('RCTHotUpdateDownloadProgress',(params)=>{ | ||||
|  | ||||
| }) | ||||
|  | ||||
| NativeAppEventEmitter.addListener('RCTHotUpdateUnzipProgress',(params)=>{ | ||||
|  | ||||
| }) | ||||
| NativeAppEventEmitter.addListener('RCTHotUpdateUnzipProgress', params => {}); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm