mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	Add client info and uuid
This commit is contained in:
		| @@ -22,12 +22,14 @@ | ||||
|  | ||||
| // | ||||
| static NSString *const keyPushyInfo = @"REACTNATIVECN_PUSHY_INFO_KEY"; | ||||
| static NSString *const keyPushyInfo = @"REACTNATIVECN_PUSHY_INFO_KEY"; | ||||
| static NSString *const paramPackageVersion = @"packageVersion"; | ||||
| static NSString *const paramLastVersion = @"lastVersion"; | ||||
| static NSString *const paramCurrentVersion = @"currentVersion"; | ||||
| static NSString *const paramIsFirstTime = @"isFirstTime"; | ||||
| static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK"; | ||||
| static NSString *const keyBlockUpdate = @"blockUpdate" | ||||
| static NSString *const keyBlockUpdate = @"REACTNATIVECN_PUSHY_BLOCKUPDATE"; | ||||
| static NSString *const keyUuid = @"REACTNATIVECN_PUSHY_UUID"; | ||||
| static NSString *const keyFirstLoadMarked = @"REACTNATIVECN_PUSHY_FIRSTLOADMARKED_KEY"; | ||||
| static NSString *const keyRolledBackMarked = @"REACTNATIVECN_PUSHY_ROLLEDBACKMARKED_KEY"; | ||||
| static NSString *const KeyPackageUpdatedMarked = @"REACTNATIVECN_PUSHY_ISPACKAGEUPDATEDMARKED_KEY"; | ||||
| @@ -157,6 +159,7 @@ RCT_EXPORT_MODULE(RCTPushy); | ||||
|     ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked]; | ||||
|     ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked]; | ||||
|     ret[@"blockUpdate"] = [defaults objectForKey:keyBlockUpdate]; | ||||
|     ret[@"uuid"] = [defaults objectForKey:keyUuid]; | ||||
|     NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo]; | ||||
|     ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion]; | ||||
|      | ||||
| @@ -200,6 +203,13 @@ RCT_EXPORT_METHOD(setBlockUpdate:(NSDictionary *)options) | ||||
|     [defaults synchronize]; | ||||
| } | ||||
|  | ||||
| RCT_EXPORT_METHOD(setUuid:(NSString *)uuid) | ||||
| { | ||||
|     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | ||||
|     [defaults setObject:uuid forKey:keyUuid]; | ||||
|     [defaults synchronize]; | ||||
| } | ||||
|  | ||||
| RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary *)options | ||||
|                   resolver:(RCTPromiseResolveBlock)resolve | ||||
|                   rejecter:(RCTPromiseRejectBlock)reject) | ||||
|   | ||||
							
								
								
									
										19
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								lib/index.js
									
									
									
									
									
								
							| @@ -5,6 +5,11 @@ import { | ||||
| } from './endpoint'; | ||||
| import { NativeAppEventEmitter, NativeModules, Platform } from 'react-native'; | ||||
| export { setCustomEndpoints }; | ||||
| const { | ||||
|   version: v, | ||||
| } = require('react-native/Libraries/Core/ReactNativeVersion'); | ||||
| const RNVersion = `${v.major}.${v.minor}.${v.patch}`; | ||||
| import { v4 as uuidv4 } from 'uuid'; | ||||
|  | ||||
| let Pushy = NativeModules.Pushy; | ||||
|  | ||||
| @@ -19,6 +24,7 @@ export const isFirstTime = Pushy.isFirstTime; | ||||
| export const isRolledBack = Pushy.isRolledBack; | ||||
| export const buildTime = Pushy.buildTime; | ||||
| let blockUpdate = Pushy.blockUpdate; | ||||
| let uuid = Pushy.uuid; | ||||
|  | ||||
| if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) { | ||||
|   throw new Error( | ||||
| @@ -26,6 +32,13 @@ if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) { | ||||
|   ); | ||||
| } | ||||
|  | ||||
| if (!uuid) { | ||||
|   uuid = uuidv4(); | ||||
|   Pushy.setUuid(uuid); | ||||
| } | ||||
|  | ||||
| console.log('Pushy uuid: ' + uuid); | ||||
|  | ||||
| /* | ||||
| Return json: | ||||
| Package expired: | ||||
| @@ -77,6 +90,12 @@ export async function checkUpdate(APPKEY, isRetry) { | ||||
|         packageVersion, | ||||
|         hash: currentVersion, | ||||
|         buildTime, | ||||
|         cInfo: { | ||||
|           pushy: require('../package.json').version, | ||||
|           rn: RNVersion, | ||||
|           os: Platform.OS + ' ' + Platform.Version, | ||||
|           uuid, | ||||
|         }, | ||||
|       }), | ||||
|     }); | ||||
|   } catch (e) { | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "react-native-update", | ||||
|   "version": "5.7.0", | ||||
|   "version": "5.7.1", | ||||
|   "description": "react-native hot update", | ||||
|   "main": "lib/index.js", | ||||
|   "scripts": { | ||||
| @@ -26,5 +26,7 @@ | ||||
|     "react-native": ">=0.27.0" | ||||
|   }, | ||||
|   "homepage": "https://github.com/reactnativecn/react-native-pushy#readme", | ||||
|   "dependencies": {} | ||||
|   "dependencies": { | ||||
|     "uuid": "^8.3.0" | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm