Skip to content

Commit d587174

Browse files
committed
【无API变动】修复iCloud云存档写入新的key之后再读取获得空字符串的问题;规范函数命名
1 parent e9f4ced commit d587174

3 files changed

Lines changed: 12 additions & 17 deletions

File tree

Plugins/iOS/Native/ExternC.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ bool _IsICloudAvailable(){
234234
return [iCloudKeyValueStore IsICloudAvailable];
235235
}
236236
bool _ICloudKeyExists(const char *key){
237-
return [iCloudKeyValueStore KeyExists:[NSString stringWithUTF8String:key ?: ""]];
237+
return [iCloudKeyValueStore IsKeyExists:[NSString stringWithUTF8String:key ?: ""]];
238238
}
239239
bool _ClearICloudSave(){
240240
return [iCloudKeyValueStore ClearICloudSave];

Plugins/iOS/Native/iCloudKeyValueStore.mm

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
@implementation iCloudKeyValueStore
77

88
static NSUbiquitousKeyValueStore *keyValueStore;
9-
static NSDictionary *cloudDictionary;
109
static BOOL inited;
1110

1211
+(BOOL)IsUserLoggedIn
@@ -19,7 +18,6 @@ +(void) InitICloud
1918
if(!inited && [iCloudKeyValueStore IsUserLoggedIn])
2019
{
2120
keyValueStore = [NSUbiquitousKeyValueStore defaultStore];
22-
cloudDictionary = [keyValueStore dictionaryRepresentation];
2321
inited = YES;
2422
}
2523
}
@@ -53,26 +51,24 @@ +(BOOL) Synchronize
5351
return [keyValueStore synchronize];
5452
}
5553

56-
+(BOOL)KeyExists:(NSString *)key
54+
+(BOOL)IsKeyExists:(NSString *)key
5755
{
5856
if([iCloudKeyValueStore IsICloudAvailable]){
5957

60-
return [cloudDictionary objectForKey:key] != nil ;
58+
return [[keyValueStore dictionaryRepresentation] objectForKey:key] != nil ;
6159
}
6260
return NO;
6361
}
6462

6563
+(BOOL)ClearICloudSave{
66-
if([iCloudKeyValueStore IsICloudAvailable]){
67-
@autoreleasepool {
68-
NSLog(@"Clearing iCloud Saves");
69-
}
70-
NSArray *keyArray = [cloudDictionary allKeys];
64+
if([iCloudKeyValueStore IsICloudAvailable])
65+
{
66+
NSArray *keyArray = [[keyValueStore dictionaryRepresentation] allKeys];
7167

7268
for(int i = 0; i < keyArray.count; i++){
7369
@autoreleasepool {
7470
NSString *key = [keyArray objectAtIndex:i];
75-
if(key != NULL){
71+
if(key != nil){
7672
[keyValueStore removeObjectForKey:key];
7773
}
7874
}
@@ -87,7 +83,7 @@ +(double)GetFloat:(NSString *)key defaultValue:(double)defaultValue
8783
{
8884
if([iCloudKeyValueStore IsICloudAvailable]){
8985

90-
if ([iCloudKeyValueStore KeyExists:key]){
86+
if ([iCloudKeyValueStore IsKeyExists:key]){
9187
return [keyValueStore doubleForKey:key];
9288
}
9389
//[iCloudKeyValueStore iCloudSaveFloat:key setValue:defaultValue];
@@ -114,7 +110,7 @@ +(int)GetInt:(NSString *)key defaultValue:(int)defaultValue
114110
{
115111
if([iCloudKeyValueStore IsICloudAvailable]){
116112

117-
if ([iCloudKeyValueStore KeyExists:key]){
113+
if ([iCloudKeyValueStore IsKeyExists:key]){
118114
return [[keyValueStore objectForKey:key] intValue];
119115
}
120116
//[iCloudKeyValueStore iCloudSaveInt:key setValue:defaultValue];
@@ -140,7 +136,7 @@ +(BOOL)GetBool:(NSString *)key defaultValue:(BOOL)defaultValue
140136
{
141137
if([iCloudKeyValueStore IsICloudAvailable]){
142138

143-
if ([iCloudKeyValueStore KeyExists:key]){
139+
if ([iCloudKeyValueStore IsKeyExists:key]){
144140
return [keyValueStore boolForKey:key];
145141
}
146142
//[iCloudKeyValueStore iCloudSaveBool:key setValue:defaultValue];
@@ -166,7 +162,7 @@ +(NSString *)GetString:(NSString *)key defaultValue:(NSString *)defaultValue
166162
{
167163
if([iCloudKeyValueStore IsICloudAvailable]){
168164

169-
if ([iCloudKeyValueStore KeyExists:key]){
165+
if ([iCloudKeyValueStore IsKeyExists:key]){
170166
return [keyValueStore stringForKey:key];
171167
}
172168
//[iCloudKeyValueStore iCloudSaveString:key setValue:defaultValue];

Plugins/iOS/Native/iOSNative.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
extern UIViewController *UnityGetGLViewController();
88

9-
109
//GKGameCenterControllerDelegate 实现GameCenterView回调协议
1110
@interface iOSGameKit : NSObject <GKGameCenterControllerDelegate>
1211
+(void)ShowGameCenterView:(CompletionCallback)callback;
@@ -56,7 +55,7 @@ extern UIViewController *UnityGetGLViewController();
5655
@interface iCloudKeyValueStore : NSObject
5756
+(void)InitICloud;
5857
+(BOOL)IsICloudAvailable;
59-
+(BOOL)KeyExists:(NSString *)key;
58+
+(BOOL)IsKeyExists:(NSString *)key;
6059
+(BOOL)ClearICloudSave;
6160
+(double)GetFloat:(NSString *)key defaultValue:(double)defaultValue;
6261
+(BOOL)SetFloat:(NSString *)key setValue:(double)value;

0 commit comments

Comments
 (0)