-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
194 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// SAMacHistoryFileStorePlugin.h | ||
// SensorsAnalyticsSDK | ||
// | ||
// Created by 储强盛 on 2024/9/2. | ||
// Copyright © 2015-2024 Sensors Data Co., Ltd. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
|
||
#import <Foundation/Foundation.h> | ||
#import "SAStorePlugin.h" | ||
|
||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
// macOS 历史文件迁移 | ||
@interface SAMacHistoryFileStorePlugin : NSObject<SAStorePlugin> | ||
|
||
|
||
+ (NSString *)filePath:(NSString *)key; | ||
|
||
- (NSArray *)storeKeys; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// SAMacHistoryFileStorePlugin.m | ||
// SensorsAnalyticsSDK | ||
// | ||
// Created by 储强盛 on 2024/9/2. | ||
// Copyright © 2015-2024 Sensors Data Co., Ltd. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#if ! __has_feature(objc_arc) | ||
#error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag on this file. | ||
#endif | ||
|
||
#import "SAMacHistoryFileStorePlugin.h" | ||
|
||
static NSString * const kSAMacHistoryFileStorePluginType = @"cn.sensorsdata.File.Mac."; | ||
|
||
|
||
@implementation SAMacHistoryFileStorePlugin | ||
|
||
|
||
+ (NSString *)filePath:(NSString *)key { | ||
NSString *name = [key stringByReplacingOccurrencesOfString:kSAMacHistoryFileStorePluginType withString:@""]; | ||
// 兼容老版 macOS SDK 的本地数据 | ||
NSString *filename = [NSString stringWithFormat:@"com.sensorsdata.analytics.mini.SensorsAnalyticsSDK.%@.plist", name]; | ||
return [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject] | ||
stringByAppendingPathComponent:filename]; | ||
} | ||
|
||
#pragma mark - SAStorePlugin | ||
|
||
- (NSArray<NSString *> *)storeKeys { | ||
return @[@"$channel_device_info", @"login_id", @"distinct_id", @"com.sensorsdata.loginidkey", @"com.sensorsdata.identities", @"first_day", @"super_properties", @"latest_utms", @"SAEncryptSecretKey", @"SAVisualPropertiesConfig", @"SASessionModel"]; | ||
} | ||
|
||
- (NSString *)type { | ||
return kSAMacHistoryFileStorePluginType; | ||
} | ||
|
||
- (void)upgradeWithOldPlugin:(nonnull id<SAStorePlugin>)oldPlugin { | ||
} | ||
|
||
- (nullable id)objectForKey:(nonnull NSString *)key { | ||
if (!key) { | ||
return nil; | ||
} | ||
NSString *filePath = [SAMacHistoryFileStorePlugin filePath:key]; | ||
@try { | ||
return [NSKeyedUnarchiver unarchiveObjectWithFile:filePath]; | ||
} @catch (NSException *exception) { | ||
return nil; | ||
} | ||
} | ||
|
||
- (void)setObject:(nullable id)value forKey:(nonnull NSString *)key { | ||
if (!key) { | ||
return; | ||
} | ||
// 屏蔽非法数据类型,防止野指针造成异常 | ||
if(!value && ![value conformsToProtocol:@protocol(NSCoding)]) { | ||
return; | ||
} | ||
|
||
NSString *filePath = [SAMacHistoryFileStorePlugin filePath:key]; | ||
|
||
// macOS10.13 不包含 NSFileProtectionComplete | ||
NSDictionary *protection = [NSDictionary dictionary]; | ||
|
||
[[NSFileManager defaultManager] setAttributes:protection | ||
ofItemAtPath:filePath | ||
error:nil]; | ||
[NSKeyedArchiver archiveRootObject:value toFile:filePath]; | ||
} | ||
|
||
- (void)removeObjectForKey:(nonnull NSString *)key { | ||
NSString *filePath = [SAMacHistoryFileStorePlugin filePath:key]; | ||
[[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; | ||
} | ||
|
||
|
||
@end |