Skip to content

Commit

Permalink
Merge pull request #691 from zapcannon87/master
Browse files Browse the repository at this point in the history
feat(storage): clear default/current installation's persistent cache
  • Loading branch information
zapcannon87 authored May 12, 2022
2 parents 06f8740 + d982d84 commit 83d4ba7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
4 changes: 4 additions & 0 deletions AVOS/AVOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
D3A3FA39269ECD40002531C7 /* LCFriendship.h in Headers */ = {isa = PBXBuildFile; fileRef = D3A3FA37269ECD40002531C7 /* LCFriendship.h */; settings = {ATTRIBUTES = (Public, ); }; };
D3A3FA3A269ECD40002531C7 /* LCFriendship.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A3FA38269ECD40002531C7 /* LCFriendship.m */; };
D3AD74AB24BC216200D1BBEE /* LCUserTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */; };
D3D41AA9282D226800F6E5CD /* LCInstallationTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D41AA8282D226800F6E5CD /* LCInstallationTestCase.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -613,6 +614,7 @@
D3A3FA38269ECD40002531C7 /* LCFriendship.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LCFriendship.m; sourceTree = "<group>"; };
D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCUserTestCase.swift; sourceTree = "<group>"; };
D3C53FCB2106D84A00D48686 /* LCIMClientProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCIMClientProtocol.h; sourceTree = "<group>"; };
D3D41AA8282D226800F6E5CD /* LCInstallationTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCInstallationTestCase.swift; sourceTree = "<group>"; };
D3D6E43923544F520048E58F /* LCGPBExtensionRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCGPBExtensionRegistry.m; sourceTree = "<group>"; };
D3D6E43A23544F520048E58F /* LCGPBApi.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCGPBApi.pbobjc.h; sourceTree = "<group>"; };
D3D6E43B23544F520048E58F /* LCGPBEmpty.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCGPBEmpty.pbobjc.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1277,6 +1279,7 @@
C43D444427281D39006A31FD /* LCTestObject.h */,
C43D444527281D39006A31FD /* LCTestObject.m */,
D30B6B6124A0A933006ABE09 /* BaseTestCase.swift */,
D3D41AA8282D226800F6E5CD /* LCInstallationTestCase.swift */,
D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */,
C4B25E3C27267DE700F9414F /* LCObjectTestCase.swift */,
D313717F26BBDAC200123756 /* LCQueryTestCase.swift */,
Expand Down Expand Up @@ -1868,6 +1871,7 @@
files = (
D30B6B6224A0A933006ABE09 /* BaseTestCase.swift in Sources */,
D313718026BBDAC200123756 /* LCQueryTestCase.swift in Sources */,
D3D41AA9282D226800F6E5CD /* LCInstallationTestCase.swift in Sources */,
C497E8C52760A77300441160 /* LCPushTestCase.swift in Sources */,
C4B7A99327698C4A00D8833B /* LCIMClientTestCase.swift in Sources */,
D36A095A25BEA75000A4F312 /* IMMessageTestCase.swift in Sources */,
Expand Down
22 changes: 22 additions & 0 deletions AVOS/LeanCloudObjcTests/LCInstallationTestCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// LCInstallationTestCase.swift
// LeanCloudObjcTests
//
// Created by zapcannon87 on 2022/05/12.
// Copyright © 2022 LeanCloud Inc. All rights reserved.
//

import XCTest
@testable import LeanCloudObjc

class LCInstallationTestCase: BaseTestCase {

func testClearPersistentCache() {
let installation = LCInstallation.default()
installation.setDeviceTokenFrom(uuid.data(using: .utf8)!, teamId: "LeanCloud")
XCTAssertTrue(installation.save())
XCTAssertTrue(FileManager.default.fileExists(atPath: LCPersistenceUtils.currentInstallationArchivePath()))
LCInstallation.clearPersistentCache()
XCTAssertFalse(FileManager.default.fileExists(atPath: LCPersistenceUtils.currentInstallationArchivePath()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
#import "LCTestObject.h"
#import "LCIMConversation_Internal.h"
#import "LCIMMessage_Internal.h"

#import "LCPersistenceUtils.h"
3 changes: 3 additions & 0 deletions AVOS/Sources/Foundation/Push/LCInstallation.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ NS_ASSUME_NONNULL_BEGIN
/// For compatibility, same as the `defaultInstallation`.
+ (instancetype)currentInstallation;

/// Clear default/current installation's Persistent Cache.
+ (void)clearPersistentCache;

/// Create a new installation instance.
+ (instancetype)installation;

Expand Down
22 changes: 16 additions & 6 deletions AVOS/Sources/Foundation/Push/LCInstallation.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "LCPersistenceUtils.h"
#import "LCErrorUtils.h"
#import "LCRouter_Internal.h"
#import "LCLogger.h"

@implementation LCInstallation {
NSString *_deviceToken;
Expand Down Expand Up @@ -43,12 +44,10 @@ + (instancetype)defaultInstallation
dispatch_once(&onceToken, ^{
instance = [LCInstallation installation];
NSString *path = [LCPersistenceUtils currentInstallationArchivePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithDictionary:
[LCPersistenceUtils getJSONFromPath:path]];
if (dictionary) {
[LCObjectUtils copyDictionary:dictionary
toObject:instance];
if (path && [[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSDictionary *dictionary = [LCPersistenceUtils getJSONFromPath:path];
if ([dictionary isKindOfClass:[NSDictionary class]]) {
[LCObjectUtils copyDictionary:dictionary toObject:instance];
}
}
});
Expand All @@ -60,6 +59,17 @@ + (instancetype)currentInstallation
return [LCInstallation defaultInstallation];
}

+ (void)clearPersistentCache {
NSString *path = [LCPersistenceUtils currentInstallationArchivePath];
if (path && [[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
if (error) {
LCLoggerError(LCLoggerDomainStorage, @"Error: %@", error);
}
}
}

+ (NSString *)deviceType
{
#if TARGET_OS_TV
Expand Down
2 changes: 1 addition & 1 deletion AVOS/Sources/Foundation/UserAgent.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define SDK_VERSION @"13.7.1"
#define SDK_VERSION @"13.8.0"
2 changes: 1 addition & 1 deletion LeanCloudObjc.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'LeanCloudObjc'
s.version = '13.7.1'
s.version = '13.8.0'
s.homepage = 'https://leancloud.cn/'
s.summary = 'LeanCloud Objective-C SDK'
s.authors = 'LeanCloud'
Expand Down

0 comments on commit 83d4ba7

Please sign in to comment.