From 468b432edb70cf99c6f7e39ac6e77dbf83c0d25d Mon Sep 17 00:00:00 2001 From: zapcannon87 Date: Thu, 12 May 2022 19:36:56 +0800 Subject: [PATCH 1/2] feat(storage): clear default/current installation's persistent cache --- AVOS/AVOS.xcodeproj/project.pbxproj | 4 ++++ .../LCInstallationTestCase.swift | 22 +++++++++++++++++++ .../LeanCloudObjcTests-Bridging-Header.h | 2 +- AVOS/Sources/Foundation/Push/LCInstallation.h | 3 +++ AVOS/Sources/Foundation/Push/LCInstallation.m | 22 ++++++++++++++----- 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 AVOS/LeanCloudObjcTests/LCInstallationTestCase.swift diff --git a/AVOS/AVOS.xcodeproj/project.pbxproj b/AVOS/AVOS.xcodeproj/project.pbxproj index e14f56af..776ca51f 100644 --- a/AVOS/AVOS.xcodeproj/project.pbxproj +++ b/AVOS/AVOS.xcodeproj/project.pbxproj @@ -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 */ @@ -613,6 +614,7 @@ D3A3FA38269ECD40002531C7 /* LCFriendship.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LCFriendship.m; sourceTree = ""; }; D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCUserTestCase.swift; sourceTree = ""; }; D3C53FCB2106D84A00D48686 /* LCIMClientProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCIMClientProtocol.h; sourceTree = ""; }; + D3D41AA8282D226800F6E5CD /* LCInstallationTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCInstallationTestCase.swift; sourceTree = ""; }; D3D6E43923544F520048E58F /* LCGPBExtensionRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCGPBExtensionRegistry.m; sourceTree = ""; }; D3D6E43A23544F520048E58F /* LCGPBApi.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCGPBApi.pbobjc.h; sourceTree = ""; }; D3D6E43B23544F520048E58F /* LCGPBEmpty.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCGPBEmpty.pbobjc.h; sourceTree = ""; }; @@ -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 */, @@ -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 */, diff --git a/AVOS/LeanCloudObjcTests/LCInstallationTestCase.swift b/AVOS/LeanCloudObjcTests/LCInstallationTestCase.swift new file mode 100644 index 00000000..21a4e454 --- /dev/null +++ b/AVOS/LeanCloudObjcTests/LCInstallationTestCase.swift @@ -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())) + } +} diff --git a/AVOS/LeanCloudObjcTests/LeanCloudObjcTests-Bridging-Header.h b/AVOS/LeanCloudObjcTests/LeanCloudObjcTests-Bridging-Header.h index 5f62b323..6500ac53 100644 --- a/AVOS/LeanCloudObjcTests/LeanCloudObjcTests-Bridging-Header.h +++ b/AVOS/LeanCloudObjcTests/LeanCloudObjcTests-Bridging-Header.h @@ -14,4 +14,4 @@ #import "LCTestObject.h" #import "LCIMConversation_Internal.h" #import "LCIMMessage_Internal.h" - +#import "LCPersistenceUtils.h" diff --git a/AVOS/Sources/Foundation/Push/LCInstallation.h b/AVOS/Sources/Foundation/Push/LCInstallation.h index bbcff8da..0ea695e7 100644 --- a/AVOS/Sources/Foundation/Push/LCInstallation.h +++ b/AVOS/Sources/Foundation/Push/LCInstallation.h @@ -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; diff --git a/AVOS/Sources/Foundation/Push/LCInstallation.m b/AVOS/Sources/Foundation/Push/LCInstallation.m index fe54c9b7..01b34e07 100644 --- a/AVOS/Sources/Foundation/Push/LCInstallation.m +++ b/AVOS/Sources/Foundation/Push/LCInstallation.m @@ -11,6 +11,7 @@ #import "LCPersistenceUtils.h" #import "LCErrorUtils.h" #import "LCRouter_Internal.h" +#import "LCLogger.h" @implementation LCInstallation { NSString *_deviceToken; @@ -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]; } } }); @@ -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 From d982d84e4b23fda3fbe196e570c5228a9f2e0604 Mon Sep 17 00:00:00 2001 From: zapcannon87 Date: Thu, 12 May 2022 19:45:30 +0800 Subject: [PATCH 2/2] release: 13.8.0 --- AVOS/Sources/Foundation/UserAgent.h | 2 +- LeanCloudObjc.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AVOS/Sources/Foundation/UserAgent.h b/AVOS/Sources/Foundation/UserAgent.h index e1c91dd8..3dddb91c 100644 --- a/AVOS/Sources/Foundation/UserAgent.h +++ b/AVOS/Sources/Foundation/UserAgent.h @@ -1 +1 @@ -#define SDK_VERSION @"13.7.1" +#define SDK_VERSION @"13.8.0" diff --git a/LeanCloudObjc.podspec b/LeanCloudObjc.podspec index fdc76e84..b4799548 100644 --- a/LeanCloudObjc.podspec +++ b/LeanCloudObjc.podspec @@ -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'