iOS:Native plugin use safe method to get from dictionary,avoid type error

This commit is contained in:
pengfeizhou
2021-02-01 18:10:11 +08:00
committed by osborn
parent 156f70bb97
commit fe4e90ec53
11 changed files with 91 additions and 88 deletions

View File

@@ -22,6 +22,8 @@
#if __has_include(<PINCache/PINCache.h>)
#import <PINCache/PINCache.h>
#import <DoricCore/Doric.h>
#import <DoricCore/DoricCore-umbrella.h>
#define DoricCache PINCache
@@ -161,9 +163,9 @@ - (DoricCache *)getDiskCache:(NSString *)zone {
}
- (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
NSString *zone = argument[@"zone"];
NSString *key = argument[@"key"];
NSString *value = argument[@"value"];
NSString *zone = [argument optString:@"zone"];
NSString *key = [argument optString:@"key"];
NSString *value = [argument optString:@"value"];
DoricCache *diskCache = [self getDiskCache:zone];
[diskCache setObject:value forKey:key withBlock:^{
[promise resolve:nil];
@@ -171,8 +173,8 @@ - (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
}
- (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
NSString *zone = argument[@"zone"];
NSString *key = argument[@"key"];
NSString *zone = [argument optString:@"zone"];
NSString *key = [argument optString:@"key"];
DoricCache *diskCache = [self getDiskCache:zone];
[diskCache objectForKey:key withBlock:^(NSString *_Nonnull key, id <NSCoding> _Nullable object) {
[promise resolve:object];
@@ -180,8 +182,8 @@ - (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
}
- (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
NSString *zone = argument[@"zone"];
NSString *key = argument[@"key"];
NSString *zone = [argument optString:@"zone"];
NSString *key = [argument optString:@"key"];
DoricCache *diskCache = [self getDiskCache:zone];
[diskCache removeObjectForKey:key withBlock:^(NSString *key) {
[promise resolve:nil];
@@ -189,7 +191,7 @@ - (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
}
- (void)clear:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
NSString *zone = argument[@"zone"];
NSString *zone = [argument optString:@"zone"];
DoricCache *diskCache = [self getDiskCache:zone];
[diskCache removeAllObjectsWithBlock:^{
[promise resolve:nil];