1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-16 12:11:39 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Add set local hash info for ios

This commit is contained in:
sunnylqm
2021-10-05 14:08:56 +08:00
parent 775e567062
commit 94d52bb415
8 changed files with 33 additions and 55 deletions

View File

@@ -147,7 +147,7 @@ public class UpdateContext {
String lastVersion = getCurrentVersion(); String lastVersion = getCurrentVersion();
SharedPreferences.Editor editor = sp.edit(); SharedPreferences.Editor editor = sp.edit();
editor.putString("currentVersion", hash); editor.putString("currentVersion", hash);
if (lastVersion != null && lastVersion != hash) { if (lastVersion != null && !lastVersion.equals(hash)) {
editor.putString("lastVersion", lastVersion); editor.putString("lastVersion", lastVersion);
} }
editor.putBoolean("firstTime", true); editor.putBoolean("firstTime", true);
@@ -189,7 +189,8 @@ public class UpdateContext {
SharedPreferences.Editor editor = sp.edit(); SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("firstTimeOk", true); editor.putBoolean("firstTimeOk", true);
String lastVersion = sp.getString("lastVersion", null); String lastVersion = sp.getString("lastVersion", null);
if (lastVersion != null) { String curVersion = sp.getString("currentVersion", null);
if (lastVersion != null && !lastVersion.equals(curVersion)) {
editor.remove("lastVersion"); editor.remove("lastVersion");
editor.remove("hash_" + lastVersion); editor.remove("hash_" + lastVersion);
} }

View File

@@ -1,11 +1,3 @@
//
// RCTPushy.h
// RCTPushy
//
// Created by LvBingru on 2/19/16.
// Copyright © 2016 erica. All rights reserved.
//
#import <React/RCTBridgeModule.h> #import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h> #import <React/RCTEventEmitter.h>

View File

@@ -1,11 +1,3 @@
//
// RCTPushy.m
// RCTPushy
//
// Created by LvBingru on 2/19/16.
// Copyright © 2016 erica. All rights reserved.
//
#import "RCTPushy.h" #import "RCTPushy.h"
#import "RCTPushyDownloader.h" #import "RCTPushyDownloader.h"
#import "RCTPushyManager.h" #import "RCTPushyManager.h"
@@ -23,6 +15,7 @@ static NSString *const paramIsFirstTime = @"isFirstTime";
static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK"; static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK";
static NSString *const keyBlockUpdate = @"REACTNATIVECN_PUSHY_BLOCKUPDATE"; static NSString *const keyBlockUpdate = @"REACTNATIVECN_PUSHY_BLOCKUPDATE";
static NSString *const keyUuid = @"REACTNATIVECN_PUSHY_UUID"; static NSString *const keyUuid = @"REACTNATIVECN_PUSHY_UUID";
static NSString *const keyHashInfo = @"REACTNATIVECN_PUSHY_HASH_";
static NSString *const keyFirstLoadMarked = @"REACTNATIVECN_PUSHY_FIRSTLOADMARKED_KEY"; static NSString *const keyFirstLoadMarked = @"REACTNATIVECN_PUSHY_FIRSTLOADMARKED_KEY";
static NSString *const keyRolledBackMarked = @"REACTNATIVECN_PUSHY_ROLLEDBACKMARKED_KEY"; static NSString *const keyRolledBackMarked = @"REACTNATIVECN_PUSHY_ROLLEDBACKMARKED_KEY";
static NSString *const KeyPackageUpdatedMarked = @"REACTNATIVECN_PUSHY_ISPACKAGEUPDATEDMARKED_KEY"; static NSString *const KeyPackageUpdatedMarked = @"REACTNATIVECN_PUSHY_ISPACKAGEUPDATEDMARKED_KEY";
@@ -212,6 +205,24 @@ RCT_EXPORT_METHOD(setUuid:(NSString *)uuid)
[defaults synchronize]; [defaults synchronize];
} }
RCT_EXPORT_METHOD(setLocalHashInfo:(NSString *)hash
value:(NSString *)value)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:value forKey:[keyHashInfo stringByAppendingString:hash]];
[defaults synchronize];
}
RCT_EXPORT_METHOD(getLocalHashInfo:(NSString *)hash
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
resolve([defaults stringForKey:[keyHashInfo stringByAppendingString:hash]]);
}
RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary *)options RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) rejecter:(RCTPromiseRejectBlock)reject)
@@ -304,10 +315,16 @@ RCT_EXPORT_METHOD(markSuccess)
{ {
// up package info // up package info
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *packageInfo = [[NSMutableDictionary alloc] initWithDictionary:[defaults objectForKey:keyPushyInfo]]; NSMutableDictionary *pushyInfo = [[NSMutableDictionary alloc] initWithDictionary:[defaults objectForKey:keyPushyInfo]];
[packageInfo setObject:@(NO) forKey:paramIsFirstTime]; [pushyInfo setObject:@(NO) forKey:paramIsFirstTime];
[packageInfo setObject:@(YES) forKey:paramIsFirstLoadOk]; [pushyInfo setObject:@(YES) forKey:paramIsFirstLoadOk];
[defaults setObject:packageInfo forKey:keyPushyInfo];
NSString *lastVersion = pushyInfo[paramLastVersion];
NSString *curVersion = pushyInfo[paramCurrentVersion];
if (lastVersion != nil && ![lastVersion isEqualToString:curVersion]) {
[pushyInfo removeObjectForKey:[keyHashInfo stringByAppendingString:lastVersion]];
}
[defaults setObject:pushyInfo forKey:keyPushyInfo];
[defaults synchronize]; [defaults synchronize];
// clear other package dir // clear other package dir

View File

@@ -1,11 +1,3 @@
//
// RCTPushyDownloader.h
// RCTPushy
//
// Created by lvbingru on 16/2/23.
// Copyright © 2016年 erica. All rights reserved.
//
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@interface RCTPushyDownloader : NSObject @interface RCTPushyDownloader : NSObject

View File

@@ -1,11 +1,3 @@
//
// RCTPushyDownloader.m
// RCTPushy
//
// Created by lvbingru on 16/2/23.
// Copyright © 2016 erica. All rights reserved.
//
#import "RCTPushyDownloader.h" #import "RCTPushyDownloader.h"
@interface RCTPushyDownloader()<NSURLSessionDelegate> @interface RCTPushyDownloader()<NSURLSessionDelegate>

View File

@@ -1,11 +1,3 @@
//
// RCTPushyManager.h
// RCTPushy
//
// Created by lvbingru on 16/4/1.
// Copyright © 2016年 erica. All rights reserved.
//
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@interface RCTPushyManager : NSObject @interface RCTPushyManager : NSObject

View File

@@ -1,11 +1,3 @@
//
// RCTPushyManager.m
// RCTPushy
//
// Created by lvbingru on 16/4/1.
// Copyright © 2016 erica. All rights reserved.
//
#import "RCTPushyManager.h" #import "RCTPushyManager.h"
#import "ZipArchive.h" #import "ZipArchive.h"
#import "HDiffPatch.h" #import "HDiffPatch.h"

View File

@@ -51,7 +51,7 @@ export async function getCurrentVersionInfo() {
const eventEmitter = new NativeEventEmitter(Pushy); const eventEmitter = new NativeEventEmitter(Pushy);
if (!uuid) { if (!uuid) {
uuid = require('nanoid/non-secure')(); uuid = require('nanoid/non-secure').nanoid();
Pushy.setUuid(uuid); Pushy.setUuid(uuid);
} }