feat:add storage plugin for iOS
This commit is contained in:
parent
06c6b5f5a5
commit
3b7c4a97da
@ -43,4 +43,5 @@ TODO: Add long description of the pod here.
|
||||
s.dependency 'SDWebImage/WebP'
|
||||
s.dependency 'SocketRocket', '~> 0.5.1'
|
||||
s.dependency 'GCDWebServer', '~> 3.0'
|
||||
s.dependency 'YYCache', '~> 1.0.4'
|
||||
end
|
||||
|
@ -4,6 +4,7 @@ PODS:
|
||||
- SDWebImage (~> 4.4.7)
|
||||
- SDWebImage/WebP
|
||||
- SocketRocket (~> 0.5.1)
|
||||
- YYCache (~> 1.0.4)
|
||||
- GCDWebServer (3.5.3):
|
||||
- GCDWebServer/Core (= 3.5.3)
|
||||
- GCDWebServer/Core (3.5.3)
|
||||
@ -23,6 +24,7 @@ PODS:
|
||||
- libwebp (< 2.0, >= 0.5)
|
||||
- SDWebImage/Core
|
||||
- SocketRocket (0.5.1)
|
||||
- YYCache (1.0.4)
|
||||
|
||||
DEPENDENCIES:
|
||||
- Doric (from `../`)
|
||||
@ -33,17 +35,19 @@ SPEC REPOS:
|
||||
- libwebp
|
||||
- SDWebImage
|
||||
- SocketRocket
|
||||
- YYCache
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Doric:
|
||||
:path: "../"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Doric: 4632b549eb47400496b4aa3307234b883092a77d
|
||||
Doric: c71287d68afeeb79bfd3c680ed2dd3b90d515c12
|
||||
GCDWebServer: c0ab22c73e1b84f358d1e2f74bf6afd1c60829f2
|
||||
libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e
|
||||
SDWebImage: c10d14a8883ebd89664f02a422006f66a85c0c5d
|
||||
SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531
|
||||
YYCache: 8105b6638f5e849296c71f331ff83891a4942952
|
||||
|
||||
PODFILE CHECKSUM: 012563d71439e7e33e976dca3b59664ed56cee39
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#import "DoricScrollerNode.h"
|
||||
#import "DoricSliderNode.h"
|
||||
#import "DoricSlideItemNode.h"
|
||||
#import "DoricStoragePlugin.h"
|
||||
|
||||
@interface DoricRegistry ()
|
||||
|
||||
@ -56,9 +57,10 @@ - (instancetype)init {
|
||||
}
|
||||
|
||||
- (void)innerRegister {
|
||||
[self registerNativePlugin:DoricShaderPlugin.class withName:@"shader"];
|
||||
[self registerNativePlugin:DoricModalPlugin.class withName:@"modal"];
|
||||
[self registerNativePlugin:DoricNetworkPlugin.class withName:@"network"];
|
||||
[self registerNativePlugin:DoricShaderPlugin.class withName:@"shader"];
|
||||
[self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"];
|
||||
|
||||
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
||||
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
||||
|
24
iOS/Pod/Classes/Plugin/DoricStoragePlugin.h
Normal file
24
iOS/Pod/Classes/Plugin/DoricStoragePlugin.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/22.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricStoragePlugin : DoricNativePlugin
|
||||
@end
|
87
iOS/Pod/Classes/Plugin/DoricStoragePlugin.m
Normal file
87
iOS/Pod/Classes/Plugin/DoricStoragePlugin.m
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/22.
|
||||
//
|
||||
|
||||
#import "DoricStoragePlugin.h"
|
||||
#import "YYDiskCache.h"
|
||||
|
||||
static NSString *doric_prefix = @"pref_doric";
|
||||
|
||||
@interface DoricStoragePlugin ()
|
||||
@property(atomic, strong) NSMutableDictionary <NSString *, YYDiskCache *> *cachedMap;
|
||||
@property(nonatomic, strong) YYDiskCache *defaultCache;
|
||||
@end
|
||||
|
||||
@implementation DoricStoragePlugin
|
||||
- (YYDiskCache *)defaultCache {
|
||||
if (!_defaultCache) {
|
||||
_defaultCache = [[YYDiskCache alloc] initWithPath:doric_prefix];
|
||||
}
|
||||
return _defaultCache;
|
||||
}
|
||||
|
||||
- (YYDiskCache *)getDiskCache:(NSString *)zone {
|
||||
YYDiskCache *diskCache;
|
||||
if (zone) {
|
||||
diskCache = self.cachedMap[zone];
|
||||
if (!diskCache) {
|
||||
diskCache = [[YYDiskCache alloc] initWithPath:[NSString stringWithFormat:@"%@_%@", doric_prefix, zone]];
|
||||
self.cachedMap[zone] = diskCache;
|
||||
}
|
||||
} else {
|
||||
diskCache = self.defaultCache;
|
||||
}
|
||||
return diskCache;
|
||||
}
|
||||
|
||||
- (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
NSString *value = argument[@"value"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache setObject:value forKey:key withBlock:^{
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache objectForKey:key withBlock:^(NSString *key, NSString *value) {
|
||||
[promise resolve:value];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache removeObjectForKey:key withBlock:^(NSString *key) {
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)clear:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache removeAllObjectsWithBlock:^{
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
@end
|
Reference in New Issue
Block a user