Skip to content

Commit d1efb7c

Browse files
committed
refactor: public utils
1 parent 586c27f commit d1efb7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+362
-617
lines changed

AVOS/AVOS.xcodeproj/project.pbxproj

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
D30B6A1424A09978006ABE09 /* LeanCloudObjc.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D30B6A0B24A09978006ABE09 /* LeanCloudObjc.framework */; };
1212
D30B6A1B24A09978006ABE09 /* LeanCloudObjc.h in Headers */ = {isa = PBXBuildFile; fileRef = D30B6A0D24A09978006ABE09 /* LeanCloudObjc.h */; settings = {ATTRIBUTES = (Public, ); }; };
1313
D30B6A2224A09B1F006ABE09 /* UserAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AAC1A5A7A0000C5C6C4 /* UserAgent.h */; };
14-
D30B6A2324A09B1F006ABE09 /* LCConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C8419F31A5A79FF00C5C6C4 /* LCConstants.h */; settings = {ATTRIBUTES = (Public, ); }; };
1514
D30B6A2424A09B1F006ABE09 /* LCGlobal.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C8419F41A5A79FF00C5C6C4 /* LCGlobal.h */; };
16-
D30B6A2524A09B1F006ABE09 /* LCAvailability.h in Headers */ = {isa = PBXBuildFile; fileRef = 8311CD841C3D25B9007DEFF8 /* LCAvailability.h */; settings = {ATTRIBUTES = (Public, ); }; };
1715
D30B6A2824A09B1F006ABE09 /* LCApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = D3700B782475345C00678B2B /* LCApplication.h */; settings = {ATTRIBUTES = (Public, ); }; };
1816
D30B6A2924A09B1F006ABE09 /* LCApplication_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = D3596DAC2480EEED002D2D22 /* LCApplication_Internal.h */; };
1917
D30B6A2A24A09B1F006ABE09 /* LCApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = D3700B792475345C00678B2B /* LCApplication.m */; };
@@ -118,7 +116,7 @@
118116
D30B6AA024A09E35006ABE09 /* LCHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AA41A5A7A0000C5C6C4 /* LCHelpers.h */; };
119117
D30B6AA124A09E35006ABE09 /* LCLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AA61A5A7A0000C5C6C4 /* LCLogger.h */; settings = {ATTRIBUTES = (Public, ); }; };
120118
D30B6AA224A09E35006ABE09 /* LCLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C841AA71A5A7A0000C5C6C4 /* LCLogger.m */; };
121-
D30B6AA324A09E35006ABE09 /* LCUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AAA1A5A7A0000C5C6C4 /* LCUtils.h */; };
119+
D30B6AA324A09E35006ABE09 /* LCUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841AAA1A5A7A0000C5C6C4 /* LCUtils.h */; settings = {ATTRIBUTES = (Public, ); }; };
122120
D30B6AA424A09E35006ABE09 /* LCUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C841AAB1A5A7A0000C5C6C4 /* LCUtils.m */; };
123121
D30B6AA524A09E35006ABE09 /* LCDatabaseCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 830E7CFE1B1CB07B005F4B22 /* LCDatabaseCommon.h */; };
124122
D30B6AA624A09E35006ABE09 /* LCDatabaseCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = 830E7CF61B1CA2A2005F4B22 /* LCDatabaseCoordinator.h */; };
@@ -355,7 +353,6 @@
355353
830EB9FE1C44F3D600BA917F /* LCSaveOption_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCSaveOption_internal.h; sourceTree = "<group>"; };
356354
830F159E1F010F260009B4D0 /* LCIMRecalledMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCIMRecalledMessage.h; sourceTree = "<group>"; };
357355
830F159F1F010F260009B4D0 /* LCIMRecalledMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCIMRecalledMessage.m; sourceTree = "<group>"; };
358-
8311CD841C3D25B9007DEFF8 /* LCAvailability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCAvailability.h; sourceTree = "<group>"; };
359356
831E29581D882CBB006E502B /* LCIMMessageOption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCIMMessageOption.h; sourceTree = "<group>"; };
360357
831E29591D882CBB006E502B /* LCIMMessageOption.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCIMMessageOption.m; sourceTree = "<group>"; };
361358
83331D431EB9A25F00CADC9C /* LCCaptcha.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCCaptcha.h; sourceTree = "<group>"; };
@@ -419,7 +416,6 @@
419416
8C8419E01A5A79FF00C5C6C4 /* LCRole.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCRole.h; sourceTree = "<group>"; };
420417
8C8419E11A5A79FF00C5C6C4 /* LCRole.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCRole.m; sourceTree = "<group>"; };
421418
8C8419E21A5A79FF00C5C6C4 /* LCRole_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCRole_Internal.h; sourceTree = "<group>"; };
422-
8C8419F31A5A79FF00C5C6C4 /* LCConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCConstants.h; sourceTree = "<group>"; };
423419
8C8419F41A5A79FF00C5C6C4 /* LCGlobal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCGlobal.h; sourceTree = "<group>"; };
424420
8C8419FA1A5A79FF00C5C6C4 /* LCCacheManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCCacheManager.h; sourceTree = "<group>"; };
425421
8C8419FB1A5A79FF00C5C6C4 /* LCCacheManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCCacheManager.m; sourceTree = "<group>"; };
@@ -826,9 +822,7 @@
826822
isa = PBXGroup;
827823
children = (
828824
8C841AAC1A5A7A0000C5C6C4 /* UserAgent.h */,
829-
8C8419F31A5A79FF00C5C6C4 /* LCConstants.h */,
830825
8C8419F41A5A79FF00C5C6C4 /* LCGlobal.h */,
831-
8311CD841C3D25B9007DEFF8 /* LCAvailability.h */,
832826
D3700B782475345C00678B2B /* LCApplication.h */,
833827
D3596DAC2480EEED002D2D22 /* LCApplication_Internal.h */,
834828
D3700B792475345C00678B2B /* LCApplication.m */,
@@ -1482,14 +1476,12 @@
14821476
D30B6A6524A09D52006ABE09 /* LCPush_Internal.h in Headers */,
14831477
D30B6A6924A09D62006ABE09 /* LCFriendQuery.h in Headers */,
14841478
D30B6A7424A09D87006ABE09 /* LCRouter_Internal.h in Headers */,
1485-
D30B6A2524A09B1F006ABE09 /* LCAvailability.h in Headers */,
14861479
D30B6AAD24A09E35006ABE09 /* NSDictionary+LCHash.h in Headers */,
14871480
D30B6AE724A09F1E006ABE09 /* LCGPBDescriptor_PackagePrivate.h in Headers */,
14881481
D30B6B4524A09F84006ABE09 /* LCIMImageMessage.h in Headers */,
14891482
D30B6AAA24A09E35006ABE09 /* LCKeyValueSQL.h in Headers */,
14901483
D30B6A8224A09DCA006ABE09 /* LCNetworkReachabilityManager.h in Headers */,
14911484
D30B6B3624A09F79006ABE09 /* LCIMCacheStore.h in Headers */,
1492-
D30B6A2324A09B1F006ABE09 /* LCConstants.h in Headers */,
14931485
D30B6AC624A09ED1006ABE09 /* LCIMConversation.h in Headers */,
14941486
D30B6A9924A09DF2006ABE09 /* LCUser.h in Headers */,
14951487
D30B6AD024A09ED2006ABE09 /* LCIMKeyedConversation_internal.h in Headers */,

AVOS/LeanCloudObjc/Foundation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
#import "LCApplication.h"
1313

1414
// Constants
15-
#import "LCAvailability.h"
16-
#import "LCConstants.h"
1715
#import "LCLogger.h"
1816
#import "LCErrorUtils.h"
17+
#import "LCUtils.h"
1918

2019
// Object
2120
#import "LCObject.h"

AVOS/Sources/Foundation/Cache/LCCacheManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <Foundation/Foundation.h>
10-
#import "LCConstants.h"
10+
#import "LCUtils.h"
1111

1212
@interface LCCacheManager : NSObject
1313

AVOS/Sources/Foundation/Cache/LCCacheManager.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ - (NSString *)pathForKey:(NSString *)key {
5353
}
5454

5555
- (BOOL)hasCacheForKey:(NSString *)key {
56-
return [[NSFileManager defaultManager] fileExistsAtPath:[self pathForKey:[key LCMD5String]]];
56+
return [[NSFileManager defaultManager] fileExistsAtPath:[self pathForKey:[key _lc_MD5String]]];
5757
}
5858
- (BOOL)hasCacheForMD5Key:(NSString *)key {
5959
return [[NSFileManager defaultManager] fileExistsAtPath:[self pathForKey:key]];
@@ -67,9 +67,9 @@ - (void)getWithKey:(NSString *)key maxCacheAge:(NSTimeInterval)maxCacheAge block
6767
if (maxCacheAge<=0) {
6868
isTooOld=YES;
6969
} else {
70-
diskResult=[LCPersistenceUtils getJSONFromPath:[self pathForKey:[key LCMD5String]]];
70+
diskResult=[LCPersistenceUtils getJSONFromPath:[self pathForKey:[key _lc_MD5String]]];
7171
if (diskResult && maxCacheAge > 0) {
72-
NSDate *lastModified = [LCPersistenceUtils lastModified:[self pathForKey:[key LCMD5String]]];
72+
NSDate *lastModified = [LCPersistenceUtils lastModified:[self pathForKey:[key _lc_MD5String]]];
7373
if ([[NSDate date] timeIntervalSinceDate:lastModified] > maxCacheAge) {
7474
isTooOld = YES;
7575
}
@@ -88,7 +88,7 @@ - (void)getWithKey:(NSString *)key maxCacheAge:(NSTimeInterval)maxCacheAge block
8888

8989
- (void)saveJSON:(id)JSON forKey:(NSString *)key {
9090
dispatch_async(self.cacheQueue, ^{
91-
[LCPersistenceUtils saveJSON:JSON toPath:[self pathForKey:[key LCMD5String]]];
91+
[LCPersistenceUtils saveJSON:JSON toPath:[self pathForKey:[key _lc_MD5String]]];
9292
});
9393
}
9494

@@ -125,7 +125,7 @@ + (BOOL)clearCacheMoreThanDays:(NSInteger)numberOfDays {
125125

126126
- (void)clearCacheForKey:(NSString *)key {
127127
dispatch_sync(self.cacheQueue, ^{
128-
[[NSFileManager defaultManager] removeItemAtPath:[self pathForKey:[key LCMD5String]] error:NULL];
128+
[[NSFileManager defaultManager] removeItemAtPath:[self pathForKey:[key _lc_MD5String]] error:NULL];
129129
});
130130
}
131131

AVOS/Sources/Foundation/Cache/LCScheduler.m

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,77 @@
77
//
88

99
#import "LCScheduler.h"
10-
#import "LCFile.h"
11-
#import "LCFile_Internal.h"
1210
#import "LCCacheManager.h"
1311
#import "LCPaasClient.h"
14-
#import "LCUtils.h"
1512

16-
static NSUInteger const ExpiredDays = 30;
13+
#if TARGET_OS_IOS || TARGET_OS_TV
14+
#import <UIKit/UIKit.h>
15+
#elif TARGET_OS_OSX
16+
#import <Cocoa/Cocoa.h>
17+
#endif
1718

1819
@implementation LCScheduler
1920

2021
+ (LCScheduler *)sharedInstance {
2122
static dispatch_once_t once;
22-
static LCScheduler *_sharedInstance;
23+
static LCScheduler *instance;
2324
dispatch_once(&once, ^{
24-
_sharedInstance = [[LCScheduler alloc] init];
25-
[_sharedInstance setup];
25+
instance = [[LCScheduler alloc] init];
26+
[instance setup];
2627
});
27-
return _sharedInstance;
28+
return instance;
2829
}
2930

3031
- (void)setup {
31-
self.queryCacheExpiredDays = ExpiredDays;
32-
self.fileCacheExpiredDays = ExpiredDays;
32+
self.queryCacheExpiredDays = 30;
33+
self.fileCacheExpiredDays = 30;
3334

34-
#if !TARGET_OS_WATCH
35-
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
36-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
37-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
38-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];
39-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
40-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willTerminate:) name:UIApplicationWillTerminateNotification object:nil];
41-
#elif defined(__MAX_OS_X_VERSION_MIN_REQUIRED)
42-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground:) name:NSApplicationDidFinishLaunchingNotification object:nil];
43-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:NSApplicationDidBecomeActiveNotification object:nil];
44-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishLaunching:) name:NSApplicationDidFinishLaunchingNotification object:nil];
45-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willTerminate:) name:NSApplicationWillTerminateNotification object:nil];
46-
#endif
35+
#if TARGET_OS_IOS || TARGET_OS_TV
36+
[[NSNotificationCenter defaultCenter] addObserver:self
37+
selector:@selector(didEnterBackground:)
38+
name:UIApplicationDidEnterBackgroundNotification
39+
object:nil];
40+
[[NSNotificationCenter defaultCenter] addObserver:self
41+
selector:@selector(willEnterForeground:)
42+
name:UIApplicationWillEnterForegroundNotification
43+
object:nil];
44+
[[NSNotificationCenter defaultCenter] addObserver:self
45+
selector:@selector(didFinishLaunching:)
46+
name:UIApplicationDidFinishLaunchingNotification
47+
object:nil];
48+
[[NSNotificationCenter defaultCenter] addObserver:self
49+
selector:@selector(didReceiveMemoryWarning:)
50+
name:UIApplicationDidReceiveMemoryWarningNotification
51+
object:nil];
52+
[[NSNotificationCenter defaultCenter] addObserver:self
53+
selector:@selector(willTerminate:)
54+
name:UIApplicationWillTerminateNotification
55+
object:nil];
56+
#elif TARGET_OS_OSX
57+
[[NSNotificationCenter defaultCenter] addObserver:self
58+
selector:@selector(didEnterBackground:)
59+
name:NSApplicationDidFinishLaunchingNotification
60+
object:nil];
61+
[[NSNotificationCenter defaultCenter] addObserver:self
62+
selector:@selector(willEnterForeground:)
63+
name:NSApplicationDidBecomeActiveNotification
64+
object:nil];
65+
[[NSNotificationCenter defaultCenter] addObserver:self
66+
selector:@selector(didFinishLaunching:)
67+
name:NSApplicationDidFinishLaunchingNotification
68+
object:nil];
69+
[[NSNotificationCenter defaultCenter] addObserver:self
70+
selector:@selector(willTerminate:)
71+
name:NSApplicationWillTerminateNotification
72+
object:nil];
4773
#endif
4874
}
4975

5076
- (void)dealloc {
5177
[[NSNotificationCenter defaultCenter] removeObserver:self];
5278
}
5379

54-
#pragma mark - Schedule
55-
56-
#pragma mark Notification
57-
5880
#if !TARGET_OS_WATCH
59-
6081
- (void)didEnterBackground:(NSNotification *)notification {
6182
[self clearCache];
6283
}
@@ -76,7 +97,6 @@ - (void)didReceiveMemoryWarning:(NSNotification *)notification {
7697
- (void)willTerminate:(NSNotification *)notification {
7798
// Stub method
7899
}
79-
80100
#endif
81101

82102
- (void)handleArchivedRequests {

AVOS/Sources/Foundation/CloudCode/LCCloud.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <Foundation/Foundation.h>
10-
#import "LCConstants.h"
10+
#import "LCUtils.h"
1111

1212
NS_ASSUME_NONNULL_BEGIN
1313

AVOS/Sources/Foundation/CloudCode/LCCloud.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import "LCCloud.h"
1010
#import "LCPaasClient.h"
1111
#import "LCErrorUtils.h"
12-
#import "LCUtils.h"
12+
#import "LCUtils_Internal.h"
1313
#import "LCObject_Internal.h"
1414
#import "LCFile_Internal.h"
1515
#import "LCGeoPoint_Internal.h"

AVOS/Sources/Foundation/File/LCFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55

66
#import <Foundation/Foundation.h>
7-
#import "LCConstants.h"
7+
#import "LCUtils.h"
88
#import "LCACL.h"
99

1010
@class LCFileQuery;
@@ -328,7 +328,7 @@ typedef NS_OPTIONS(NSUInteger, LCFileDownloadOption) {
328328
- (void)getThumbnail:(BOOL)scaleToFit
329329
width:(int)width
330330
height:(int)height
331-
withBlock:(LCImageResultBlock)block;
331+
withBlock:(LCIdResultBlock)block;
332332

333333
// MARK: - Query
334334

AVOS/Sources/Foundation/File/LCFile.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#import <Foundation/Foundation.h>
33
#import <CommonCrypto/CommonCrypto.h>
44

5-
#import "LCConstants.h"
65
#import "LCFile_Internal.h"
76
#import "LCFileTaskManager.h"
87
#import "LCPaasClient.h"
9-
#import "LCUtils.h"
8+
#import "LCUtils_Internal.h"
109
#import "LCNetworking.h"
1110
#import "LCErrorUtils.h"
1211
#import "LCPersistenceUtils.h"
@@ -1352,7 +1351,7 @@ - (NSString *)getThumbnailURLWithScaleToFit:(BOOL)scaleToFit
13521351
- (void)getThumbnail:(BOOL)scaleToFit
13531352
width:(int)width
13541353
height:(int)height
1355-
withBlock:(LCImageResultBlock)block
1354+
withBlock:(LCIdResultBlock)block
13561355
{
13571356
NSString *url = [self getThumbnailURLWithScaleToFit:scaleToFit width:width height:height];
13581357

AVOS/Sources/Foundation/LCApplication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <Foundation/Foundation.h>
10-
#import "LCConstants.h"
10+
#import "LCUtils.h"
1111

1212
typedef NS_OPTIONS(NSUInteger, LCLogLevel) {
1313
LCLogLevelNone = 0,

0 commit comments

Comments
 (0)