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
bb2ea48b
Commit
bb2ea48b
authored
Dec 04, 2018
by
朱璇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改精准曝光方法
parent
e280b83b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
11 deletions
+80
-11
Phobos.h
GMPhobos/Classes/Phobos.h
+0
-5
Phobos.m
GMPhobos/Classes/Phobos.m
+49
-3
PhobosUtil.h
GMPhobos/Classes/PhobosUtil.h
+8
-0
PhobosUtil.m
GMPhobos/Classes/PhobosUtil.m
+23
-3
No files found.
GMPhobos/Classes/Phobos.h
View file @
bb2ea48b
...
...
@@ -77,11 +77,6 @@
*/
@property
(
copy
,
nonatomic
)
NSString
*
serverAPI
;
/**
数据接收的服务器API(新开的接口)7730精准曝光
*/
@property
(
copy
,
nonatomic
)
NSString
*
currentServerAPI
;
/**
从主项目获取当前显示的controller
*/
...
...
GMPhobos/Classes/Phobos.m
View file @
bb2ea48b
...
...
@@ -279,17 +279,16 @@ static NSString *sdkVersion = @"110";
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
//超过一定数量的话,统一发送一次
if
(
array
.
count
>
PhobosShardCount
)
{
[
sharedClient
sendArray
:
array
cleanCacheRightNow
:
YES
];
[
sharedClient
sendArray
:
array
c
urrentAPI
:
currentAPI
c
leanCacheRightNow
:
YES
];
}
}
+
(
void
)
track
:
(
NSString
*
)
eventId
attributes
:
(
NSDictionary
*
)
attributes
sendNow
:
(
BOOL
)
sendNow
currentAPI
:
(
NSString
*
)
currentAPI
{
[
Phobos
sharedClient
].
currentServerAPI
=
currentAPI
;
NSDictionary
*
dict
=
[
sharedClient
prepareDictionaryForEvent
:
eventId
attributes
:
attributes
];
if
(
sendNow
)
{
NSArray
*
array
=
@[
dict
];
// 实时发送的埋点,不能立即清楚缓存
[
sharedClient
sendArray
:
array
cleanCacheRightNow
:
NO
];
[
sharedClient
sendArray
:
array
c
urrentAPI
:
currentAPI
c
leanCacheRightNow
:
NO
];
}
else
{
[
sharedClient
save
:
dict
];
}
...
...
@@ -477,6 +476,30 @@ static NSString *sdkVersion = @"110";
}
}
/*
从缓存区获取数据,发给服务器,请求成功的时候,把缓存区的数据删除掉
*/
-
(
void
)
sendArrayWithCurrentAPI
:
(
NSString
*
)
currentAPI
{
NSMutableArray
*
dataArray
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
if
(
_logEnabled
)
{
NSData
*
data
=
[
NSJSONSerialization
dataWithJSONObject
:
dataArray
options
:
NSJSONWritingPrettyPrinted
error
:
nil
];
NSString
*
jsonString
=
[[
NSString
alloc
]
initWithData
:
data
encoding
:
NSUTF8StringEncoding
];
phobosLog
([
NSString
stringWithFormat
:
@"array prepare to fly --✈: %@"
,
jsonString
]);
}
@try
{
NSData
*
JSON
=
[
PhobosUtil
encodeJSON
:
dataArray
];
NSData
*
compressedData
=
[
PhobosUtil
compressData
:
JSON
];
if
(
compressedData
)
{
[
PhobosUtil
sendData
:
compressedData
currentAPI
:
currentAPI
success
:^
(
NSInteger
code
)
{
phobosLog
(
@"✈ ---------- ✈ data arrived Mars"
);
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
}];
}
}
@catch
(
NSException
*
exception
)
{
phobosLog
(
exception
);
}
}
/**
该方法有改动,现在的逻辑是:当前方法只接受发送的请求,然后把数据转存到另一个缓存区,
让sendArray方法负责发送,数据一旦转移到缓存区,就把原有的数据干掉。
...
...
@@ -505,6 +528,29 @@ static NSString *sdkVersion = @"110";
}
}
/**
上边方法新加了一个API字段
*/
-
(
void
)
sendArray
:
(
NSArray
*
)
array
currentAPI
:
(
NSString
*
)
currentAPI
cleanCacheRightNow
:
(
BOOL
)
clean
{
@try
{
//1.获取缓存区的数据,把新数据追加进去
NSMutableArray
*
dataArray
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
if
(
dataArray
)
{
[
dataArray
addObjectsFromArray
:
array
];
}
else
{
dataArray
=
[
NSMutableArray
arrayWithArray
:
array
];
}
[
GMCache
storeObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
object
:
dataArray
];
//2.把缓存区的数据发送给服务器
[
self
sendArrayWithCurrentAPI
:
currentAPI
];
//3.把原有的数据删除
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
}
@catch
(
NSException
*
exception
)
{
phobosLog
(
exception
);
}
}
#pragma mark - helpers
-
(
void
)
catchNullForEvent
:
(
NSString
*
)
eventId
attributes
:
(
NSDictionary
*
)
attributes
{
dispatch_async
(
dispatch_get_global_queue
(
0
,
0
),
^
{
...
...
GMPhobos/Classes/PhobosUtil.h
View file @
bb2ea48b
...
...
@@ -31,6 +31,14 @@ typedef void (^SendDataSuccessBlock)(NSInteger code);
*/
+
(
void
)
sendData
:(
NSData
*
)
data
success
:(
SendDataSuccessBlock
)
success
;
/**
* @brief 上传数据
*
*
* @7735 精准曝光
*/
+
(
void
)
sendData
:(
NSData
*
)
data
currentAPI
:(
NSString
*
)
currentAPI
success
:(
SendDataSuccessBlock
)
success
;
+
(
NSString
*
)
currentTime
;
+
(
NSString
*
)
getAppVersion
;
+
(
BOOL
)
isNonEmpty
:(
NSString
*
)
string
;
...
...
GMPhobos/Classes/PhobosUtil.m
View file @
bb2ea48b
...
...
@@ -114,9 +114,7 @@
+
(
void
)
sendData
:(
NSData
*
)
data
success
:(
SendDataSuccessBlock
)
success
{
@try
{
NSString
*
url
=
[
Phobos
sharedClient
].
currentServerAPI
.
length
>
0
?
[
Phobos
sharedClient
].
currentServerAPI
:
[
Phobos
sharedClient
].
serverAPI
;
NSMutableURLRequest
*
request
=
[[
NSMutableURLRequest
alloc
]
initWithURL
:[
NSURL
URLWithString
:
url
]];
[
Phobos
sharedClient
].
currentServerAPI
=
@""
;
// 用完置为空 防止下次判断无效出现错误
NSMutableURLRequest
*
request
=
[[
NSMutableURLRequest
alloc
]
initWithURL
:[
NSURL
URLWithString
:[
Phobos
sharedClient
].
serverAPI
]];
[
request
setValue
:
@"gzip"
forHTTPHeaderField
:
@"Content-Encoding"
];
request
.
HTTPBody
=
data
;
request
.
HTTPMethod
=
@"POST"
;
...
...
@@ -137,6 +135,28 @@
}
}
+
(
void
)
sendData
:(
NSData
*
)
data
currentAPI
:(
NSString
*
)
currentAPI
success
:(
SendDataSuccessBlock
)
success
{
@try
{
NSMutableURLRequest
*
request
=
[[
NSMutableURLRequest
alloc
]
initWithURL
:[
NSURL
URLWithString
:
currentAPI
]];
[
request
setValue
:
@"gzip"
forHTTPHeaderField
:
@"Content-Encoding"
];
request
.
HTTPBody
=
data
;
request
.
HTTPMethod
=
@"POST"
;
// sendAsynchronousRequest 在iOS9以后y被废除了
NSURLSession
*
session
=
[
NSURLSession
sharedSession
];
NSURLSessionDataTask
*
dataTask
=
[
session
dataTaskWithRequest
:
request
completionHandler
:
^
(
NSData
*
_Nullable
data
,
NSURLResponse
*
_Nullable
response
,
NSError
*
_Nullable
error
)
{
if
(
!
error
)
{
//没有错误,返回正确;
if
(
success
)
{
success
(
200
);
}
}
}];
[
dataTask
resume
];
}
@catch
(
NSException
*
exception
)
{
phobosLog
(
exception
);
}
}
/**
* @brief 将对象转成JSON格式数据
...
...
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