Skip to content

Commit

Permalink
complete flutter for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
lingol committed Nov 16, 2020
1 parent a8fad32 commit 4eace78
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
16 changes: 8 additions & 8 deletions flutter/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
PODS:
- Flutter (1.0.0)
- MMKV (1.2.4):
- MMKVCore (~> 1.2.4)
- MMKVCore (1.2.4)
- MMKVFlutter (1.2.4):
- MMKV (1.2.5):
- MMKVCore (~> 1.2.5)
- MMKVCore (1.2.5)
- MMKVFlutter (1.2.5):
- Flutter
- MMKV (= 1.2.4)
- MMKV (= 1.2.5)
- path_provider (0.0.1):
- Flutter

Expand All @@ -29,9 +29,9 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
MMKV: f15696ad598023bf6cbb17eadee13efc185c5028
MMKVCore: 9a9c10e4faf3b3068367fb2efe5419722f3d2e8a
MMKVFlutter: 81de08e262511860cab6b9220895553edad1d108
MMKV: 6c208ddcb4c197e564f72f3f73ef3b0c792e091c
MMKVCore: d9aa23fc6fb698c671c403ec593cdfe7d184e310
MMKVFlutter: 701dbf3076fd21e92e6b44ad08e5eb39bd5d9c33
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c

PODFILE CHECKSUM: 004ec2c8f64c48818df891dd2d2ce417902bd270
Expand Down
28 changes: 10 additions & 18 deletions flutter/ios/Classes/flutter-bridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ MMKV_EXPORT void onExit() {
MMKV_EXPORT int64_t getDefaultMMKV(int32_t mode, const char *cryptKey) {
MMKV *kv = nil;

// TODO: defaultMMKV with cryptKey for iOS
/*if (cryptKey) {
if (cryptKey) {
auto crypt = [NSString stringWithUTF8String:cryptKey];
if (crypt.length > 0) {
kv = [MMKV defaultMMKV];
auto cryptKeyData = [crypt dataUsingEncoding:NSUTF8StringEncoding];
if (cryptKeyData.length > 0) {
kv = [MMKV defaultMMKVWithCryptKey:cryptKeyData];
}
}
if (!kv)*/
{
if (!kv) {
kv = [MMKV defaultMMKV];
}

Expand All @@ -84,8 +83,7 @@ MMKV_EXPORT int64_t getDefaultMMKV(int32_t mode, const char *cryptKey) {
MMKV_EXPORT const char *mmapID(const void *handle) {
MMKV *kv = (__bridge MMKV *) handle;
if (kv) {
// TODO: mmapID property for iOS
// return [kv];
return [[kv mmapID] UTF8String];
}
return nullptr;
}
Expand Down Expand Up @@ -167,7 +165,7 @@ MMKV_EXPORT bool encodeBytes(const void *handle, const char *oKey, void *oValue,
if (kv && oKey) {
auto key = [NSString stringWithUTF8String:oKey];
if (oValue) {
auto value = [NSData dataWithBytesNoCopy:oValue length:length freeWhenDone:NO];
auto value = [NSData dataWithBytesNoCopy:oValue length:static_cast<NSUInteger>(length) freeWhenDone:NO];
return [kv setData:value forKey:key];
} else {
[kv removeValueForKey:key];
Expand Down Expand Up @@ -235,12 +233,8 @@ MMKV_EXPORT uint32_t valueSize(const void *handle, char *oKey, bool actualSize)
MMKV *kv = (__bridge MMKV *) handle;
if (kv && oKey) {
auto key = [NSString stringWithUTF8String:oKey];
if (!actualSize) {
auto ret = [kv getValueSizeForKey:key];
return static_cast<uint32_t>(ret);
} else {
// TODO: get actual size of value for iOS
}
auto ret = [kv getValueSizeForKey:key actualSize:actualSize];
return static_cast<uint32_t>(ret);
}
return 0;
}
Expand Down Expand Up @@ -367,9 +361,7 @@ MMKV_EXPORT void clearMemoryCache(const void *handle) {
}

MMKV_EXPORT int32_t pageSize() {
// TODO: pageSize for iOS
// return static_cast<int32_t>([MMKV pageSize]);
return static_cast<int32_t>(NSPageSize());
return static_cast<int32_t>([MMKV pageSize]);
}

MMKV_EXPORT void trim(const void *handle) {
Expand Down
4 changes: 2 additions & 2 deletions flutter/ios/MMKVFlutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Pod::Spec.new do |s|
s.name = 'MMKVFlutter'
s.version = '1.2.4'
s.version = '1.2.5'
s.summary = 'MMKV is a cross-platform key-value storage framework developed by WeChat.'
s.description = <<-DESC
The MMKV, for Flutter.
Expand All @@ -19,7 +19,7 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'MMKV', '1.2.4'
s.dependency 'MMKV', '1.2.5'
s.platform = :ios, '9.0'

# Flutter.framework does not contain a i386 slice.
Expand Down

0 comments on commit 4eace78

Please sign in to comment.