Ta android + ios

This commit is contained in:
LYP
2024-08-07 20:22:28 +08:00
parent 69fee08c61
commit 76458664d8
722 changed files with 41709 additions and 1 deletions

View File

@@ -0,0 +1,121 @@
#import <Foundation/Foundation.h>
#if __has_include(<ThinkingSDK/TDConstant.h>)
#import <ThinkingSDK/TDConstant.h>
#else
#import "TDConstant.h"
#endif
#if __has_include(<ThinkingSDK/TDSecurityPolicy.h>)
#import <ThinkingSDK/TDSecurityPolicy.h>
#else
#import "TDSecurityPolicy.h"
#endif
#if TARGET_OS_IOS
#if __has_include(<ThinkingSDK/TDSecretKey.h>)
#import <ThinkingSDK/TDSecretKey.h>
#else
#import "TDSecretKey.h"
#endif
#endif
NS_ASSUME_NONNULL_BEGIN
@interface TDConfig:NSObject <NSCopying>
/**
Set automatic burying type
*/
@property (assign, nonatomic) ThinkingAnalyticsAutoTrackEventType autoTrackEventType;
/**
Network environment for data transmission
*/
@property (assign, nonatomic) ThinkingNetworkType networkTypePolicy;
/**
Data upload interval
*/
@property (nonatomic, strong) NSNumber *uploadInterval;
/**
When there is data to upload, when the number of data cache reaches the uploadsize, upload the data immediately
*/
@property (nonatomic, strong) NSNumber *uploadSize;
/**
Event blacklist, event names that are not counted are added here
*/
@property (strong, nonatomic) NSArray *disableEvents;
/**
The maximum number of cached events, the default is 10000, the minimum is 5000
*/
@property (class, nonatomic) NSInteger maxNumEvents DEPRECATED_MSG_ATTRIBUTE("Please config TAConfigInfo in main info.plist");
/**
Data cache expiration time, the default is 10 days, the longest is 10 days
*/
@property (class, nonatomic) NSInteger expirationDays DEPRECATED_MSG_ATTRIBUTE("Please config TAConfigInfo in main info.plist");
/**
appid
*/
@property (atomic, copy) NSString *appid;
/**
instance Token
*/
@property (atomic, copy) NSString *(^getInstanceName)(void);
/**
Server URL
*/
@property (atomic, copy) NSString *configureURL;
/**
Initialize and configure background self-starting events
YES: Collect background self-starting events
NO: Do not collect background self-starting events
*/
@property (nonatomic, assign) BOOL trackRelaunchedInBackgroundEvents;
/**
Debug Mode
*/
@property (nonatomic, assign) ThinkingAnalyticsDebugMode debugMode;
/**
app launchOptions
*/
@property (nonatomic, copy) NSDictionary *launchOptions;
/**
Initialize and configure the certificate verification policy
*/
@property (nonatomic, strong) TDSecurityPolicy *securityPolicy;
/**
Set default time zone
You can use this time zone to compare the offset of the current time zone and the default time zone
*/
@property (nonatomic, strong) NSTimeZone *defaultTimeZone;
/**
instance name
*/
@property (nonatomic, copy) NSString *name;
+ (TDConfig *)defaultTDConfig;
- (instancetype)initWithAppId:(NSString *)appId serverUrl:(NSString *)serverUrl;
- (void)updateConfig:(void(^)(NSDictionary *secretKey))block;
- (void)setNetworkType:(ThinkingAnalyticsNetworkType)type;
/// enable encryption
@property (nonatomic, assign) BOOL enableEncrypt;
#if TARGET_OS_IOS
/// Get local key configuration
@property (nonatomic, strong) TDSecretKey *secretKey;
#endif
/// instance token
- (NSString *)getMapInstanceToken;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: e5805b4fe4e0cb14b99e72c26b9bb196
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,187 @@
#import "TDConfig.h"
#import "TANetwork.h"
#import "ThinkingAnalyticsSDKPrivate.h"
#import "TDSecurityPolicy.h"
#import "TDFile.h"
#import "NSString+TDString.h"
#define TDSDKSETTINGS_PLIST_SETTING_IMPL(TYPE, PLIST_KEY, GETTER, SETTER, DEFAULT_VALUE, ENABLE_CACHE) \
static TYPE *g_##PLIST_KEY = nil; \
+ (TYPE *)GETTER \
{ \
if (!g_##PLIST_KEY && ENABLE_CACHE) { \
g_##PLIST_KEY = [[[NSUserDefaults standardUserDefaults] objectForKey:@#PLIST_KEY] copy]; \
} \
if (!g_##PLIST_KEY) { \
g_##PLIST_KEY = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@#PLIST_KEY] copy] ?: DEFAULT_VALUE; \
} \
return g_##PLIST_KEY; \
} \
+ (void)SETTER:(TYPE *)value { \
g_##PLIST_KEY = [value copy]; \
if (ENABLE_CACHE) { \
if (value) { \
[[NSUserDefaults standardUserDefaults] setObject:value forKey:@#PLIST_KEY]; \
} else { \
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@#PLIST_KEY]; \
} \
} \
}
#define kTAConfigInfo @"TAConfigInfo"
static TDConfig * _defaultTDConfig;
static NSDictionary *configInfo;
@implementation TDConfig
TDSDKSETTINGS_PLIST_SETTING_IMPL(NSNumber, ThinkingSDKMaxCacheSize, _maxNumEventsNumber, _setMaxNumEventsNumber, @10000, NO);
TDSDKSETTINGS_PLIST_SETTING_IMPL(NSNumber, ThinkingSDKExpirationDays, _expirationDaysNumber, _setExpirationDaysNumber, @10, NO);
+ (TDConfig *)defaultTDConfig {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_defaultTDConfig = [TDConfig new];
});
return _defaultTDConfig;
}
- (instancetype)init {
self = [super init];
if (self) {
_trackRelaunchedInBackgroundEvents = NO;
_autoTrackEventType = ThinkingAnalyticsEventTypeNone;
_networkTypePolicy = ThinkingNetworkTypeWIFI | ThinkingNetworkType3G | ThinkingNetworkType4G | ThinkingNetworkType2G | ThinkingNetworkType5G;
_securityPolicy = [TDSecurityPolicy defaultPolicy];
_defaultTimeZone = [NSTimeZone localTimeZone];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if (!configInfo) {
configInfo = (NSDictionary *)[[[NSBundle mainBundle] infoDictionary] objectForKey: kTAConfigInfo];
}
if (configInfo && [configInfo.allKeys containsObject:@"maxNumEvents"]) {
[TDConfig setMaxNumEvents:[configInfo[@"maxNumEvents"] integerValue]];
}
if (configInfo && [configInfo.allKeys containsObject:@"expirationDays"]) {
[TDConfig setExpirationDays:[configInfo[@"expirationDays"] integerValue]];
}
#pragma clang diagnostic pop
}
return self;
}
- (instancetype)initWithAppId:(NSString *)appId serverUrl:(NSString *)serverUrl
{
self = [self init];
if (self) {
_appid = appId;
_configureURL = serverUrl;
}
return self;
}
- (void)setName:(NSString *)name {
_name = name.td_trim;
}
- (void)updateConfig:(void(^)(NSDictionary *secretKey))block {
NSString *serverUrlStr = [NSString stringWithFormat:@"%@/config",self.configureURL];
TANetwork *network = [[TANetwork alloc] init];
network.serverURL = [NSURL URLWithString:serverUrlStr];
network.securityPolicy = _securityPolicy;
[network fetchRemoteConfig:self.appid handler:^(NSDictionary * _Nonnull result, NSError * _Nullable error) {
if (!error) {
NSInteger uploadInterval = [[result objectForKey:@"sync_interval"] integerValue];
NSInteger uploadSize = [[result objectForKey:@"sync_batch_size"] integerValue];
if (uploadInterval != [self->_uploadInterval integerValue] || uploadSize != [self->_uploadSize integerValue]) {
TDFile *file = [[TDFile alloc] initWithAppid:self.appid];
if (uploadInterval > 0) {
self.uploadInterval = [NSNumber numberWithInteger:uploadInterval];
[file archiveUploadInterval:self.uploadInterval];
NSString *name = self.getInstanceName ? self.getInstanceName() : self.appid;
[[ThinkingAnalyticsSDK sharedInstanceWithAppid:name] startFlushTimer];
}
if (uploadSize > 0) {
self.uploadSize = [NSNumber numberWithInteger:uploadSize];
[file archiveUploadSize:self.uploadSize];
}
}
self.disableEvents = [result objectForKey:@"disable_event_list"];
if (block) {
block([result objectForKey:@"secret_key"]);
}
}
}];
}
- (void)setNetworkType:(ThinkingAnalyticsNetworkType)type {
if (type == TDNetworkTypeDefault) {
_networkTypePolicy = ThinkingNetworkTypeWIFI | ThinkingNetworkType3G | ThinkingNetworkType4G | ThinkingNetworkType2G | ThinkingNetworkType5G;
} else if (type == TDNetworkTypeOnlyWIFI) {
_networkTypePolicy = ThinkingNetworkTypeWIFI;
} else if (type == TDNetworkTypeALL) {
_networkTypePolicy = ThinkingNetworkTypeWIFI | ThinkingNetworkType3G | ThinkingNetworkType4G | ThinkingNetworkType2G | ThinkingNetworkType5G;
}
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone {
TDConfig *config = [[[self class] allocWithZone:zone] init];
config.trackRelaunchedInBackgroundEvents = self.trackRelaunchedInBackgroundEvents;
config.autoTrackEventType = self.autoTrackEventType;
config.networkTypePolicy = self.networkTypePolicy;
config.launchOptions = [self.launchOptions copyWithZone:zone];
config.debugMode = self.debugMode;
config.securityPolicy = [self.securityPolicy copyWithZone:zone];
config.defaultTimeZone = [self.defaultTimeZone copyWithZone:zone];
config.name = [self.name copy];
config.enableEncrypt = self.enableEncrypt;
#if TARGET_OS_IOS
config.secretKey = [self.secretKey copyWithZone:zone];
#endif
return config;
}
#pragma mark - SETTINGS
+ (NSInteger)maxNumEvents {
NSInteger maxNumEvents = [self _maxNumEventsNumber].integerValue;
if (maxNumEvents < 5000) {
maxNumEvents = 5000;
}
return maxNumEvents;
}
+ (void)setMaxNumEvents:(NSInteger)maxNumEventsNumber {
[self _setMaxNumEventsNumber:@(maxNumEventsNumber)];
}
+ (NSInteger)expirationDays {
NSInteger maxNumEvents = [self _expirationDaysNumber].integerValue;
return maxNumEvents >= 0 ? maxNumEvents : 10;
}
+ (void)setExpirationDays:(NSInteger)expirationDays {
[self _setExpirationDaysNumber:@(expirationDays)];
}
- (NSString *)getMapInstanceToken {
if (self.name && [self.name isKindOfClass:[NSString class]] && self.name.length) {
return self.name;
} else {
return self.appid;
}
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: b007bca1536bc814290c35117a66cd02
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
//
// TDPublicConfig.h
// ThinkingSDK
//
// Created by LiHuanan on 2020/9/8.
// Copyright © 2020 thinkingdata. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TDPublicConfig : NSObject
@property(copy,nonatomic) NSArray* controllers;
@property(copy,nonatomic) NSString* version;
+ (NSArray*)controllers;
+ (NSString*)version;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: c13fea031fd993643bd0ce9283f94fd1
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,62 @@
//
// TDPublicConfig.m
// ThinkingSDK
//
// Created by LiHuanan on 2020/9/8.
// Copyright © 2020 thinkingdata. All rights reserved.
//
#import "TDPublicConfig.h"
static TDPublicConfig* config;
@implementation TDPublicConfig
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
config = [TDPublicConfig new];
});
}
- (instancetype)init
{
self = [super init];
if(self)
{
self.controllers = @[
@"UICompatibilityInputViewController",
@"UIKeyboardCandidateGridCollectionViewController",
@"UIInputWindowController",
@"UIApplicationRotationFollowingController",
@"UIApplicationRotationFollowingControllerNoTouches",
@"UISystemKeyboardDockController",
@"UINavigationController",
@"SFBrowserRemoteViewController",
@"SFSafariViewController",
@"UIAlertController",
@"UIImagePickerController",
@"PUPhotoPickerHostViewController",
@"UIViewController",
@"UITableViewController",
@"UITabBarController",
@"_UIRemoteInputViewController",
@"UIEditingOverlayViewController",
@"_UIAlertControllerTextFieldViewController",
@"UIActivityGroupViewController",
@"_UISFAirDropInstructionsViewController",
@"_UIActivityGroupListViewController",
@"_UIShareExtensionRemoteViewController",
@"SLRemoteComposeViewController",
@"SLComposeViewController",
];
}
return self;
}
+ (NSArray*)controllers
{
return config.controllers;
}
+ (NSString*)version
{
return @"2.8.6";
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 1a055ec55ad5b354ead3b844939d7eba
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant: