Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMPhobos
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMPhobos
Commits
2a14bd2d
Commit
2a14bd2d
authored
Sep 22, 2020
by
jz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify deviceid
parent
3389ab1d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
169 additions
and
107 deletions
+169
-107
NewPhobos.m
GMPhobos/Classes/NewPhobos.m
+10
-5
OldPhobos.m
GMPhobos/Classes/OldPhobos.m
+11
-6
PhobosDevice.h
GMPhobos/Classes/PhobosDevice.h
+29
-0
PhobosDevice.m
GMPhobos/Classes/PhobosDevice.m
+108
-0
PhobosUtil.h
GMPhobos/Classes/PhobosUtil.h
+1
-24
PhobosUtil.m
GMPhobos/Classes/PhobosUtil.m
+10
-72
No files found.
GMPhobos/Classes/NewPhobos.m
View file @
2a14bd2d
...
...
@@ -15,6 +15,7 @@
#import <mach/mach_time.h>
#import "PhobosDataManager.h"
#import "PhobosSendManager.h"
#import "PhobosDevice.h"
static
NewPhobos
*
_sharedClient
;
...
...
@@ -111,7 +112,9 @@ static NewPhobos *_sharedClient;
@"phone_operator"
:
PhobosSafeString
([
PhobosUtil
getTelephonyInfo
]),
@"total_memory"
:
PhobosSafeString
([
PhobosUtil
getTotalMemorySize
]),
@"run_time"
:
PhobosSafeString
([
PhobosUtil
deviceRunTime
]),
@"uuid"
:
PhobosSafeString
([
PhobosUtil
deviceId
]),
@"uuid"
:
PhobosSafeString
([
PhobosDevice
getDEVICEID
]),
@"idfa"
:
PhobosSafeString
([
PhobosDevice
getIDFA
]),
@"idfv"
:
PhobosSafeString
([
PhobosDevice
getIDFV
]),
@"build_version_release"
:
PhobosSafeString
([[
UIDevice
currentDevice
]
systemVersion
]),
};
[
NewPhobos
track
:
@"device_opened"
attributes
:
dict
sendNow
:
YES
];
...
...
@@ -210,7 +213,9 @@ static NewPhobos *_sharedClient;
@"phone_operator"
:
[
PhobosUtil
getTelephonyInfo
],
@"total_memory"
:
[
PhobosUtil
getTotalMemorySize
],
@"run_time"
:
[
PhobosUtil
deviceRunTime
],
@"uuid"
:
[
PhobosUtil
deviceId
],
@"uuid"
:
PhobosSafeString
([
PhobosDevice
getDEVICEID
]),
@"idfa"
:
PhobosSafeString
([
PhobosDevice
getIDFA
]),
@"idfv"
:
PhobosSafeString
([
PhobosDevice
getIDFV
]),
@"build_version_release"
:
[[
UIDevice
currentDevice
]
systemVersion
],
};
[
NewPhobos
trackSessionOverWithAttributes
:
dict
];
...
...
@@ -320,9 +325,9 @@ static NewPhobos *_sharedClient;
NSString
*
currentTime
=
[
PhobosUtil
currentTime
];
NSMutableDictionary
*
deviceParams
=
[
NSMutableDictionary
new
];
[
deviceParams
setValue
:
PhobosSafeString
([
[[
ASIdentifierManager
sharedManager
]
advertisingIdentifier
]
UUIDString
])
forKey
:
@"idfa"
];
[
deviceParams
setValue
:
PhobosSafeString
([
[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
])
forKey
:
@"idfv"
];
[
deviceParams
setValue
:
PhobosSafeString
([
Phobos
Util
deviceId
])
forKey
:
@"device_id"
];
[
deviceParams
setValue
:
PhobosSafeString
([
PhobosDevice
getIDFA
])
forKey
:
@"idfa"
];
[
deviceParams
setValue
:
PhobosSafeString
([
PhobosDevice
getIDFV
])
forKey
:
@"idfv"
];
[
deviceParams
setValue
:
PhobosSafeString
([
Phobos
Device
getDEVICEID
])
forKey
:
@"device_id"
];
[
deviceParams
setValue
:
@"ios"
forKey
:
@"device_type"
];
[
deviceParams
setValue
:
@"Apple"
forKey
:
@"manufacturer"
];
[
deviceParams
setValue
:
@
(
self
.
gps
.
coordinate
.
latitude
)
forKey
:
@"lat"
];
...
...
GMPhobos/Classes/OldPhobos.m
View file @
2a14bd2d
...
...
@@ -11,6 +11,7 @@
#import "UIResponder+PhobosPV.h"
#import "PhobosUtil.h"
#import "PhobosCustomVisibleController.h"
#import "PhobosDevice.h"
#import <GMCache/GMCache.h>
#import <mach/mach_time.h>
...
...
@@ -98,14 +99,18 @@ static OldPhobos *sharedClient = nil;
-
(
void
)
handleEventDeviceOpened
{
/** 每次打开APP埋点 **/
// [deviceParams setValue:PhobosSafeString([PhobosDevice getIDFA]) forKey:@"idfa"];
// [deviceParams setValue:PhobosSafeString([PhobosDevice getIDFV]) forKey:@"idfv"];
// [deviceParams setValue:PhobosSafeString([PhobosDevice getDEVICEID]) forKey:@"device_id"];
NSDictionary
*
dict
=
@{
@"build_cpu_abi"
:
PhobosSafeString
([
PhobosUtil
currentDeviceCPUType
]),
@"cpu_count"
:
PhobosSafeString
([
PhobosUtil
currentDeviceCPUCount
]),
@"mac_address"
:
PhobosSafeString
([
PhobosUtil
getMacAddress
]),
@"phone_operator"
:
PhobosSafeString
([
PhobosUtil
getTelephonyInfo
]),
@"total_memory"
:
PhobosSafeString
([
PhobosUtil
getTotalMemorySize
]),
@"run_time"
:
PhobosSafeString
([
PhobosUtil
deviceRunTime
]),
@"uuid"
:
PhobosSafeString
([
PhobosUtil
deviceId
]),
@"uuid"
:
PhobosSafeString
([
PhobosDevice
getDEVICEID
]),
@"idfa"
:
PhobosSafeString
([
PhobosDevice
getIDFA
]),
@"idfv"
:
PhobosSafeString
([
PhobosDevice
getIDFV
]),
@"build_version_release"
:
PhobosSafeString
([[
UIDevice
currentDevice
]
systemVersion
]),
};
[
OldPhobos
track
:
@"device_opened"
attributes
:
dict
sendNow
:
YES
];
...
...
@@ -206,7 +211,7 @@ static OldPhobos *sharedClient = nil;
@"phone_operator"
:
[
PhobosUtil
getTelephonyInfo
],
@"total_memory"
:
[
PhobosUtil
getTotalMemorySize
],
@"run_time"
:
[
PhobosUtil
deviceRunTime
],
@"uuid"
:
[
Phobos
Util
deviceId
],
@"uuid"
:
[
Phobos
Device
getDEVICEID
],
@"build_version_release"
:
[[
UIDevice
currentDevice
]
systemVersion
],
};
[
OldPhobos
track
:
@"on_app_session_over"
attributes
:
dict
];
...
...
@@ -424,9 +429,9 @@ static OldPhobos *sharedClient = nil;
@try
{
NSString
*
currentTime
=
[
PhobosUtil
currentTime
];
NSMutableDictionary
*
deviceParams
=
[
NSMutableDictionary
new
];
[
deviceParams
setValue
:
PhobosSafeString
([
[[
ASIdentifierManager
sharedManager
]
advertisingIdentifier
]
UUIDString
])
forKey
:
@"idfa"
];
[
deviceParams
setValue
:
PhobosSafeString
([
[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
])
forKey
:
@"idfv"
];
[
deviceParams
setValue
:
PhobosSafeString
([
Phobos
Util
deviceId
])
forKey
:
@"device_id"
];
[
deviceParams
setValue
:
PhobosSafeString
([
PhobosDevice
getIDFA
])
forKey
:
@"idfa"
];
[
deviceParams
setValue
:
PhobosSafeString
([
PhobosDevice
getIDFV
])
forKey
:
@"idfv"
];
[
deviceParams
setValue
:
PhobosSafeString
([
Phobos
Device
getDEVICEID
])
forKey
:
@"device_id"
];
[
deviceParams
setValue
:
@"ios"
forKey
:
@"device_type"
];
[
deviceParams
setValue
:
@"Apple"
forKey
:
@"manufacturer"
];
[
deviceParams
setValue
:
@
(
self
.
gps
.
coordinate
.
latitude
)
forKey
:
@"lat"
];
...
...
GMPhobos/Classes/PhobosDevice.h
0 → 100644
View file @
2a14bd2d
//
// PhobosDevice.h
// GMPhobos
//
// Created by Q14 on 2020/9/22.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef
void
(
^
PhobosGetIDFACompleteBlock
)(
NSDictionary
*
dict
);
@interface
PhobosDevice
:
NSObject
/// 获取IDFA,同步获取 从钥匙串中获取
+
(
NSString
*
)
getIDFA
;
/// 获取IDFA,异步获取IDFA
+
(
void
)
getIDFAString
:(
PhobosGetIDFACompleteBlock
)
completeBlock
;
/// 获取IDFV
+
(
NSString
*
)
getIDFV
;
/// 获取DEVICEID,同步获取 取出的是默认第一次的idfv
+
(
NSString
*
)
getDEVICEID
;
@end
NS_ASSUME_NONNULL_END
GMPhobos/Classes/PhobosDevice.m
0 → 100644
View file @
2a14bd2d
//
// PhobosDevice.m
// GMPhobos
//
// Created by Q14 on 2020/9/22.
//
#import "PhobosDevice.h"
#import <AdSupport/ASIdentifierManager.h>
#import <SAMKeychain/SAMKeychain.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
//钥匙串账户
NSString
*
const
keyChainAccount
=
@"com.wanmeizhensuo.ZhengXing.phobos.keychain"
;
//钥匙串账户 表示device_id
NSString
*
const
DEVICEID
=
@"device_id"
;
//钥匙串账户 表示idfa
NSString
*
const
IDFA
=
@"idfa"
;
// 默认获取不到的idfa
NSString
*
defaultIDFA
=
@"00000000-0000-0000-0000-000000000000"
;
@implementation
PhobosDevice
#pragma mark - getIDFA
//同步获取IDFA 直接从钥匙串中获取
+
(
NSString
*
)
getIDFA
{
//直接从钥匙串中获取
NSString
*
keyChainIDFA
=
[
self
getKeyChainService
:
IDFA
account
:
keyChainAccount
];
//判断获取的钥匙串是否为空
if
([
self
checkIdfaIsNull
:
keyChainIDFA
])
{
if
(
@available
(
iOS
14
,
*
))
{
// 如果是iOS14 未从钥匙串中获取到idfa直接按默认的
keyChainIDFA
=
defaultIDFA
;
}
else
{
keyChainIDFA
=
[[
ASIdentifierManager
sharedManager
]
advertisingIdentifier
].
UUIDString
;
if
([
self
checkIdfaIsNull
:
keyChainIDFA
])
{
[
self
saveKeyChainWithValue
:
keyChainIDFA
service
:
IDFA
account
:
keyChainAccount
];
}
}
}
return
keyChainIDFA
;
}
//同步获取IDFA
+
(
void
)
getIDFAString
:
(
PhobosGetIDFACompleteBlock
)
completeBlock
{
if
(
@available
(
iOS
14
,
*
))
{
__block
NSString
*
idfaString
=
@""
;
[
ATTrackingManager
requestTrackingAuthorizationWithCompletionHandler
:
^
(
ATTrackingManagerAuthorizationStatus
status
)
{
BOOL
isAuthor
=
NO
;
if
(
status
==
ATTrackingManagerAuthorizationStatusAuthorized
)
{
isAuthor
=
YES
;
idfaString
=
[[
ASIdentifierManager
sharedManager
]
advertisingIdentifier
].
UUIDString
;
}
if
(
!
[
self
checkIdfaIsNull
:
idfaString
])
{
[
self
saveKeyChainWithValue
:
idfaString
service
:
IDFA
account
:
keyChainAccount
];
}
completeBlock
(@{
@"idfa"
:
idfaString
,
@"is_author"
:
@
(
isAuthor
)});
}];
}
else
{
// 使用原方式访问IDFA
NSString
*
idfaString
=
[[[
ASIdentifierManager
sharedManager
]
advertisingIdentifier
]
UUIDString
];
BOOL
isAuthor
=
NO
;
if
(
!
[
self
checkIdfaIsNull
:
idfaString
])
{
isAuthor
=
YES
;
[
self
saveKeyChainWithValue
:
idfaString
service
:
IDFA
account
:
keyChainAccount
];
}
completeBlock
(@{
@"idfa"
:
idfaString
,
@"is_author"
:
@
(
isAuthor
)});
}
}
#pragma mark - 对IDFA判空处理
//检查idfa 是否为空
+
(
BOOL
)
checkIdfaIsNull
:
(
NSString
*
)
idfa
{
return
!
idfa
||
[
idfa
isEqualToString
:
@"00000000-0000-0000-0000-000000000000"
];
}
#pragma mark - getIDFV
+
(
NSString
*
)
getIDFV
{
return
[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
];
}
#pragma mark - getDEVICEID
+
(
NSString
*
)
getDEVICEID
{
NSString
*
deviceId
=
[
self
getKeyChainService
:
DEVICEID
account
:
keyChainAccount
];
if
([
self
checkIdfaIsNull
:
deviceId
])
{
deviceId
=
[
self
getIDFV
];
[
self
saveKeyChainWithValue
:
deviceId
service
:
DEVICEID
account
:
keyChainAccount
];
}
return
deviceId
;
}
#pragma mark - 钥匙串封装
+
(
void
)
saveKeyChainWithValue
:
(
NSString
*
)
value
service
:
(
NSString
*
)
service
account
:
(
NSString
*
)
account
{
[
SAMKeychain
setPassword
:
value
forService
:
service
account
:
account
];
[
SAMKeychain
setAccessibilityType
:
kSecAttrAccessibleAlwaysThisDeviceOnly
];
}
//根据 service 与账户keyChain 获取存储的值
+
(
NSString
*
)
getKeyChainService
:
(
NSString
*
)
service
account
:
(
NSString
*
)
account
{
return
[
SAMKeychain
passwordForService
:
service
account
:
account
];
}
@end
GMPhobos/Classes/PhobosUtil.h
View file @
2a14bd2d
...
...
@@ -10,7 +10,6 @@
typedef
void
(
^
SendDataSuccessBlock
)(
NSInteger
code
);
typedef
void
(
^
PhobosGetIDFACompleteBlock
)(
NSString
*
idfa
);
@interface
PhobosUtil
:
NSObject
...
...
@@ -54,7 +53,7 @@ typedef void (^PhobosGetIDFACompleteBlock)(NSString *idfa);
+
(
NSString
*
)
getAppVersion
;
+
(
BOOL
)
isNonEmpty
:(
NSString
*
)
string
;
+
(
NSData
*
)
encodeJSON
:(
id
)
obj
;
+
(
NSString
*
)
deviceId
;
//
+ (NSString *)deviceId;
/** 获取手机型号 */
+
(
NSString
*
)
platform
;
/**
...
...
@@ -109,26 +108,4 @@ typedef void (^PhobosGetIDFACompleteBlock)(NSString *idfa);
* @since 5.9.3
*/
+
(
NSString
*
)
convertToJsonString
:(
id
)
object
;
/*!
* @author 乔金柱, 20-9-17
*
* @brief 获取当前设备的idfa
* 1. 获取逻辑规则会先钥匙串中取
* 2. 然后根绝API 取出
* @since 7.34.0
*/
+
(
void
)
getIDFAString
:(
PhobosGetIDFACompleteBlock
)
completeBlock
;
/*!
* @author 乔金柱, 20-9-17
*
* @brief 获取当前设备的idfa
* 1. 获取逻辑规则先钥匙串中取
* @since 7.34.0
*/
+
(
NSString
*
)
saveIDFAFromKeyChain
:(
NSString
*
)
idfaString
;
@end
GMPhobos/Classes/PhobosUtil.m
View file @
2a14bd2d
...
...
@@ -23,9 +23,6 @@
#import "Phobos.h"
#import <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonDigest.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/ASIdentifierManager.h>
#import <SAMKeychain/SAMKeychain.h>
#define IOS_CELLULAR @"pdp_ip0"
#define IOS_WIFI @"en0"
...
...
@@ -230,16 +227,16 @@
return
[
str
length
]
>
0
;
}
+
(
NSString
*
)
deviceId
{
NSString
*
idfa
=
[[[
ASIdentifierManager
sharedManager
]
advertisingIdentifier
]
UUIDString
];
NSString
*
idfv
=
[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
];
if
(
idfa
!=
nil
&&
!
[
idfa
isEqualToString
:
@"00000000-0000-0000-0000-000000000000"
])
{
return
idfa
;
}
return
idfv
;
}
//
+ (NSString *)deviceId {
//
NSString *idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
//
NSString *idfv = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
//
//
if (idfa != nil && ![idfa isEqualToString:@"00000000-0000-0000-0000-000000000000"]) {
//
return idfa;
//
}
//
//
return idfv;
//
}
+
(
NSString
*
)
getIPAddress
:
(
BOOL
)
preferIPv4
{
NSArray
*
searchArray
=
preferIPv4
?
...
...
@@ -497,63 +494,4 @@
}
return
jsonString
;
}
+
(
void
)
getIDFAString
:
(
PhobosGetIDFACompleteBlock
)
completeBlock
{
if
(
@available
(
iOS
14
,
*
))
{
__block
NSString
*
idfaString
=
@""
;
[
ATTrackingManager
requestTrackingAuthorizationWithCompletionHandler
:
^
(
ATTrackingManagerAuthorizationStatus
status
)
{
if
(
status
==
ATTrackingManagerAuthorizationStatusAuthorized
)
{
idfaString
=
[[
ASIdentifierManager
sharedManager
]
advertisingIdentifier
].
UUIDString
;
}
//检测获取到的idfa是否为空 如果为空从钥匙串中取
if
([
self
checkIdfaIsNull
:
idfaString
])
{
idfaString
=
[
self
getIDFAFromKeyChain
];
}
//从钥匙串中idfa为空 则去udid
if
([
self
checkIdfaIsNull
:
idfaString
])
{
idfaString
=
[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
];
}
[
self
saveIDFAFromKeyChain
:
idfaString
];
completeBlock
(
idfaString
);
}];
}
else
{
// 使用原方式访问IDFA
NSString
*
idfaString
=
[[[
ASIdentifierManager
sharedManager
]
advertisingIdentifier
]
UUIDString
];
//检测获取到的idfa是否为空 如果为空从钥匙串中取
if
([
self
checkIdfaIsNull
:
idfaString
])
{
idfaString
=
[
self
getIDFAFromKeyChain
];
}
//从钥匙串中idfa为空 则去udid
if
([
self
checkIdfaIsNull
:
idfaString
])
{
idfaString
=
[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
];
}
[
self
saveIDFAFromKeyChain
:
idfaString
];
completeBlock
(
idfaString
);
}
}
+
(
BOOL
)
checkIdfaIsNull
:
(
NSString
*
)
idfa
{
return
!
idfa
||
[
idfa
isEqualToString
:
@"00000000-0000-0000-0000-000000000000"
];
}
//从钥匙串获取idfa
+
(
NSString
*
)
getIDFAFromKeyChain
{
NSString
*
idfaStr
=
[
SAMKeychain
passwordForService
:
@"idfa"
account
:
@"com.gengmei.appid"
];
return
idfaStr
;
}
//存储idfa到钥匙串中
+
(
NSString
*
)
saveIDFAFromKeyChain
:
(
NSString
*
)
idfaString
{
//只在这个设备上获取 如果换设备不记录
[
SAMKeychain
setPassword
:
idfaString
forService
:
@"idfa"
account
:
@"com.gengmei.appid"
];
[
SAMKeychain
setAccessibilityType
:
kSecAttrAccessibleAlwaysThisDeviceOnly
];
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment