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
4a58871b
Commit
4a58871b
authored
Jul 01, 2020
by
yueming lu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
photo数据存储重构
parent
0caeec4a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
241 additions
and
127 deletions
+241
-127
GMViewController.m
Example/GMPhobos/GMViewController.m
+13
-12
NewPhobos.h
GMPhobos/Classes/NewPhobos.h
+0
-3
NewPhobos.m
GMPhobos/Classes/NewPhobos.m
+9
-14
OldPhobos.m
GMPhobos/Classes/OldPhobos.m
+9
-8
Phobos.m
GMPhobos/Classes/Phobos.m
+4
-4
GMPhobosPageViewModel.h
GMPhobos/Classes/PhobosDataStorage/GMPhobosPageViewModel.h
+33
-0
GMPhobosPageViewModel.m
GMPhobos/Classes/PhobosDataStorage/GMPhobosPageViewModel.m
+49
-0
GMPhobosSqulitModel.h
GMPhobos/Classes/PhobosDataStorage/GMPhobosSqulitModel.h
+10
-5
GMPhobosSqulitModel.m
GMPhobos/Classes/PhobosDataStorage/GMPhobosSqulitModel.m
+10
-15
GMPhobosTool.h
GMPhobos/Classes/PhobosDataStorage/GMPhobosTool.h
+24
-0
GMPhobosTool.m
GMPhobos/Classes/PhobosDataStorage/GMPhobosTool.m
+51
-0
GMSQliteManager.h
GMPhobos/Classes/PhobosDataStorage/GMSQliteManager.h
+1
-3
GMSQliteManager.m
GMPhobos/Classes/PhobosDataStorage/GMSQliteManager.m
+24
-46
PhobosDataManager.m
GMPhobos/Classes/PhobosDataStorage/PhobosDataManager.m
+0
-0
PhobosSendManager.m
GMPhobos/Classes/PhobosDataStorage/PhobosSendManager.m
+2
-15
UIResponder+PhobosPV.m
GMPhobos/Classes/UIResponder+PhobosPV.m
+2
-2
No files found.
Example/GMPhobos/GMViewController.m
View file @
4a58871b
...
@@ -97,23 +97,24 @@ NSString *const MockCityId = @"beijing";
...
@@ -97,23 +97,24 @@ NSString *const MockCityId = @"beijing";
[
Phobos
track
:
@"计数发送"
attributes
:@{
@"index"
:
@
(
i
)}
sendNow
:
NO
];
[
Phobos
track
:
@"计数发送"
attributes
:@{
@"index"
:
@
(
i
)}
sendNow
:
NO
];
}
}
NSLog
(
@"&&&&&&&&&&&&&&&&&"
);
NSLog
(
@"&&&&&&&&&&&&&&&&&"
);
}
}
break
;
break
;
case
3
:
//@"瞬间发送",
case
3
:
//@"瞬间发送",
{
{
[
Phobos
track
:
@"瞬间发送"
attributes
:@{
@"index"
:
@
(
0
)}
sendNow
:
YES
];
[
Phobos
track
:
@"瞬间发送"
attributes
:@{
@"index"
:
@
(
0
)}
sendNow
:
YES
];
}
}
break
;
break
;
case
4
:
//瞬间发送和计数发送
case
4
:
//瞬间发送和计数发送
{
{
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
dispatch_async
(
dispatch_get_global_queue
(
0
,
0
),
^
{
[
Phobos
track
:
@"瞬间发送和计数发送"
attributes
:@{
@"index"
:
@
(
i
)}
sendNow
:
i
%
9
];
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
}
[
Phobos
track
:
@"瞬间发送和计数发送"
attributes
:@{
@"index"
:
@
(
i
)}
sendNow
:
i
%
9
];
}
});
}
}
break
;
break
;
case
5
:
//
清空
数据
case
5
:
//
表中有多少条
数据
{
{
[
Phobos
fetchToBeSendPhobosDataCount
];
[
Phobos
fetchToBeSendPhobosDataCount
];
}
}
...
@@ -134,13 +135,13 @@ NSString *const MockCityId = @"beijing";
...
@@ -134,13 +135,13 @@ NSString *const MockCityId = @"beijing";
NSMutableDictionary
*
dict
=
[[
NSMutableDictionary
alloc
]
init
];
NSMutableDictionary
*
dict
=
[[
NSMutableDictionary
alloc
]
init
];
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
[
dict
setObject
:
inDate
forKey
:
@"in"
];
[
dict
setObject
:
inDate
forKey
:
@"in"
];
[
dict
setObject
:
@"
test
"
forKey
:
@"page_name"
];
[
dict
setObject
:
@"
home
"
forKey
:
@"page_name"
];
[
dict
setObject
:
@"
"
forKey
:
@"business_id
"
];
[
dict
setObject
:
@"
referrer"
forKey
:
@"referrer
"
];
[
dict
setObject
:
@""
forKey
:
@"referrer"
];
[
dict
setObject
:
@"
referrer
"
forKey
:
@"referrer"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"fake"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"fake"
];
[
dict
setObject
:
@""
forKey
:
@"referrer_id"
];
[
dict
setObject
:
@"
referrer_id
"
forKey
:
@"referrer_id"
];
[
dict
setObject
:
@""
forKey
:
@"extra_param"
];
[
dict
setObject
:
@"
extra_param
"
forKey
:
@"extra_param"
];
[
dict
setObject
:
@""
forKey
:
@"referrer_tab_name"
];
[
dict
setObject
:
@"
referrer_tab_name
"
forKey
:
@"referrer_tab_name"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"is_push"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"is_push"
];
NSString
*
name
=
[
NSString
stringWithFormat
:
@"page_view-%d"
,
index
];
NSString
*
name
=
[
NSString
stringWithFormat
:
@"page_view-%d"
,
index
];
[
Phobos
track
:
name
attributes
:
dict
];
[
Phobos
track
:
name
attributes
:
dict
];
...
...
GMPhobos/Classes/NewPhobos.h
View file @
4a58871b
...
@@ -173,9 +173,6 @@ NS_ASSUME_NONNULL_BEGIN
...
@@ -173,9 +173,6 @@ NS_ASSUME_NONNULL_BEGIN
/** 获取所有非立即发送埋点数量 */
/** 获取所有非立即发送埋点数量 */
+
(
NSUInteger
)
fetchToBeSendPhobosDataCount
;
+
(
NSUInteger
)
fetchToBeSendPhobosDataCount
;
/** 获取待发送埋点数据 */
+
(
NSArray
*
)
fetchToBeSendPhobosData
;
/** 清除待发送埋点数据缓存 */
/** 清除待发送埋点数据缓存 */
+
(
void
)
removeAllPhobosData
;
+
(
void
)
removeAllPhobosData
;
...
...
GMPhobos/Classes/NewPhobos.m
View file @
4a58871b
...
@@ -105,15 +105,15 @@ static NewPhobos *_sharedClient;
...
@@ -105,15 +105,15 @@ static NewPhobos *_sharedClient;
-
(
void
)
handleEventDeviceOpened
{
-
(
void
)
handleEventDeviceOpened
{
/** 每次打开APP埋点 **/
/** 每次打开APP埋点 **/
NSDictionary
*
dict
=
@{
@"build_cpu_abi"
:
[
PhobosUtil
currentDeviceCPUType
]
,
NSDictionary
*
dict
=
@{
@"build_cpu_abi"
:
PhobosSafeString
([
PhobosUtil
currentDeviceCPUType
])
,
@"cpu_count"
:
[
PhobosUtil
currentDeviceCPUCount
]
,
@"cpu_count"
:
PhobosSafeString
([
PhobosUtil
currentDeviceCPUCount
])
,
@"mac_address"
:
[
PhobosUtil
getMacAddress
]
,
@"mac_address"
:
PhobosSafeString
([
PhobosUtil
getMacAddress
])
,
@"phone_operator"
:
[
PhobosUtil
getTelephonyInfo
]
,
@"phone_operator"
:
PhobosSafeString
([
PhobosUtil
getTelephonyInfo
])
,
@"total_memory"
:
[
PhobosUtil
getTotalMemorySize
]
,
@"total_memory"
:
PhobosSafeString
([
PhobosUtil
getTotalMemorySize
])
,
@"run_time"
:
[
PhobosUtil
deviceRunTime
]
,
@"run_time"
:
PhobosSafeString
([
PhobosUtil
deviceRunTime
])
,
@"uuid"
:
[
PhobosUtil
deviceId
]
,
@"uuid"
:
PhobosSafeString
([
PhobosUtil
deviceId
])
,
@"build_version_release"
:
[[
UIDevice
currentDevice
]
systemVersion
]
,
@"build_version_release"
:
PhobosSafeString
([[
UIDevice
currentDevice
]
systemVersion
])
,
};
};
[
NewPhobos
track
:
@"device_opened"
attributes
:
dict
sendNow
:
YES
];
[
NewPhobos
track
:
@"device_opened"
attributes
:
dict
sendNow
:
YES
];
}
}
...
@@ -435,11 +435,6 @@ static NewPhobos *_sharedClient;
...
@@ -435,11 +435,6 @@ static NewPhobos *_sharedClient;
return
[[
PhobosDataManager
sharedPhobosDataManager
]
messageCount
]
;
return
[[
PhobosDataManager
sharedPhobosDataManager
]
messageCount
]
;
}
}
///** 获取待发送埋点数据, 用同步来保障异步获取数据 */
//+ (NSArray *)fetchToBeSendPhobosData {
// return [PhobosDataManager fetchToBeSendDataEntities];
//}
//
/** 清除待发送埋点数据缓存 */
/** 清除待发送埋点数据缓存 */
+
(
void
)
removeAllPhobosData
{
+
(
void
)
removeAllPhobosData
{
[[
PhobosDataManager
sharedPhobosDataManager
]
removeAll
];
[[
PhobosDataManager
sharedPhobosDataManager
]
removeAll
];
...
...
GMPhobos/Classes/OldPhobos.m
View file @
4a58871b
...
@@ -98,14 +98,15 @@ static OldPhobos *sharedClient = nil;
...
@@ -98,14 +98,15 @@ static OldPhobos *sharedClient = nil;
-
(
void
)
handleEventDeviceOpened
{
-
(
void
)
handleEventDeviceOpened
{
/** 每次打开APP埋点 **/
/** 每次打开APP埋点 **/
NSDictionary
*
dict
=
@{
@"build_cpu_abi"
:
[
PhobosUtil
currentDeviceCPUType
],
@"cpu_count"
:
[
PhobosUtil
currentDeviceCPUCount
],
NSDictionary
*
dict
=
@{
@"build_cpu_abi"
:
PhobosSafeString
([
PhobosUtil
currentDeviceCPUType
]),
@"mac_address"
:
[
PhobosUtil
getMacAddress
],
@"cpu_count"
:
PhobosSafeString
([
PhobosUtil
currentDeviceCPUCount
]),
@"phone_operator"
:
[
PhobosUtil
getTelephonyInfo
],
@"mac_address"
:
PhobosSafeString
([
PhobosUtil
getMacAddress
]),
@"total_memory"
:
[
PhobosUtil
getTotalMemorySize
],
@"phone_operator"
:
PhobosSafeString
([
PhobosUtil
getTelephonyInfo
]),
@"run_time"
:
[
PhobosUtil
deviceRunTime
],
@"total_memory"
:
PhobosSafeString
([
PhobosUtil
getTotalMemorySize
]),
@"uuid"
:
[
PhobosUtil
deviceId
],
@"run_time"
:
PhobosSafeString
([
PhobosUtil
deviceRunTime
]),
@"build_version_release"
:
[[
UIDevice
currentDevice
]
systemVersion
],
@"uuid"
:
PhobosSafeString
([
PhobosUtil
deviceId
]),
@"build_version_release"
:
PhobosSafeString
([[
UIDevice
currentDevice
]
systemVersion
]),
};
};
[
OldPhobos
track
:
@"device_opened"
attributes
:
dict
sendNow
:
YES
];
[
OldPhobos
track
:
@"device_opened"
attributes
:
dict
sendNow
:
YES
];
}
}
...
...
GMPhobos/Classes/Phobos.m
View file @
4a58871b
...
@@ -244,10 +244,10 @@ static BOOL isGray = NO;
...
@@ -244,10 +244,10 @@ static BOOL isGray = NO;
return
isGray
?
[
NewPhobos
fetchToBeSendPhobosDataCount
]
:
0
;
return
isGray
?
[
NewPhobos
fetchToBeSendPhobosDataCount
]
:
0
;
}
}
/** 获取待发送埋点数据 */
/
//
** 获取待发送埋点数据 */
+
(
NSArray
*
)
fetchToBeSendPhobosData
{
//
+ (NSArray *)fetchToBeSendPhobosData {
return
isGray
?
[
NewPhobos
fetchToBeSendPhobosData
]
:
@[];
//
return isGray ? [NewPhobos fetchToBeSendPhobosData] : @[];
}
//
}
/** 清除待发送埋点数据缓存 */
/** 清除待发送埋点数据缓存 */
+
(
void
)
removeAllPhobosData
{
+
(
void
)
removeAllPhobosData
{
...
...
GMPhobos/Classes/PhobosDataStorage/GMPhobosPageViewModel.h
0 → 100644
View file @
4a58871b
//
// GMPhobosPageViewModel.h
// GMPhobos
//
// Created by edz on 2020/6/22.
//
#import "GMPhobosSqulitModel.h"
@interface
GMPhobosPageViewModel
:
GMPhobosSqulitModel
@property
(
nonatomic
,
strong
)
NSString
*
gm_out
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_in
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_page_name
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_business_id
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_referrer
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_referrer_link
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_referrer_id
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_extra_param
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_referrer_tab_name
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_is_push
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_message_id
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_in_time_millis
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_out_time_millis
;
@property
(
nonatomic
,
strong
)
NSString
*
gm_is_first
;
+
(
GMPhobosPageViewModel
*
)
pageViewModelOfDict
:(
NSDictionary
*
)
data
type
:(
NSString
*
)
phobosType
urlApi
:(
NSString
*
)
urlapi
tableName
:(
NSString
*
)
name
immediately
:(
BOOL
)
status
;
@end
GMPhobos/Classes/PhobosDataStorage/GMPhobosPageViewModel.m
0 → 100644
View file @
4a58871b
//
// GMPhobosPageViewModel.m
// GMPhobos
//
// Created by edz on 2020/6/22.
//
#import "GMPhobosPageViewModel.h"
@implementation
GMPhobosPageViewModel
+
(
GMPhobosPageViewModel
*
)
pageViewModelOfDict
:(
NSDictionary
*
)
dict
type
:(
NSString
*
)
phobosType
urlApi
:(
NSString
*
)
urlapi
tableName
:(
NSString
*
)
name
immediately
:(
BOOL
)
status
{
NSDictionary
*
data
=
dict
[
@"params"
];
GMPhobosPageViewModel
*
model
=
[[
GMPhobosPageViewModel
alloc
]
init
];
//共有参数
model
.
tableName
=
name
;
model
.
data
=
[
GMPhobosTool
dictionaryToJsonString
:
data
];
NSTimeInterval
time
=
[[
NSDate
date
]
timeIntervalSince1970
]
*
1000
;
model
.
messageItemId
=
[
NSString
stringWithFormat
:
@"%.f*%lld"
,
time
,
mach_absolute_time
()];
model
.
status
=
PhobosDataSendStatus_wait
;
model
.
phobosType
=
phobosType
;
model
.
api
=
urlapi
;
model
.
immediately
=
status
;
//私有参数
model
.
gm_out
=
data
[
@"out"
];
model
.
gm_in
=
data
[
@"in"
];
model
.
gm_page_name
=
data
[
@"page_name"
];
model
.
gm_business_id
=
data
[
@"business_id"
];
model
.
gm_referrer
=
data
[
@"referrer"
];
model
.
gm_referrer_link
=
data
[
@"referrer_link"
];
model
.
gm_referrer_id
=
data
[
@"referrer_id"
];
model
.
gm_extra_param
=
data
[
@"extra_param"
];
model
.
gm_referrer_tab_name
=
data
[
@"referrer_tab_name"
];
model
.
gm_is_push
=
data
[
@"is_push"
];
model
.
gm_is_push
=
data
[
@"is_push"
];
model
.
gm_message_id
=
data
[
@"message_id"
];
model
.
gm_in_time_millis
=
data
[
@"in_time_millis"
];
model
.
gm_out_time_millis
=
data
[
@"out_time_millis"
];
model
.
gm_is_first
=
data
[
@"is_first"
];
return
model
;
}
@end
GMPhobos/Classes/PhobosDataStorage/GMPhobosSqulitModel.h
View file @
4a58871b
...
@@ -6,7 +6,8 @@
...
@@ -6,7 +6,8 @@
//
//
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>
#import "GMPhobosTool.h"
#import <mach/mach_time.h>
typedef
NS_ENUM
(
int
,
PhobosDataSendStatus
)
{
typedef
NS_ENUM
(
int
,
PhobosDataSendStatus
)
{
PhobosDataSendStatus_wait
=
1
,
// 待发送数据
PhobosDataSendStatus_wait
=
1
,
// 待发送数据
...
@@ -19,21 +20,25 @@ typedef NS_ENUM(int, PhobosDataSendStatus) {
...
@@ -19,21 +20,25 @@ typedef NS_ENUM(int, PhobosDataSendStatus) {
@interface
GMPhobosSqulitModel
:
NSObject
@interface
GMPhobosSqulitModel
:
NSObject
/// 唯一标识(用于筛选)
/// 唯一标识(用于筛选)
@property
(
nonatomic
,
strong
)
NSString
*
messageId
;
@property
(
nonatomic
,
strong
)
NSString
*
messageI
temI
d
;
/// 埋点类型
/// 埋点类型
@property
(
nonatomic
,
strong
)
NSString
*
phobosType
;
@property
(
nonatomic
,
strong
)
NSString
*
phobosType
;
/// 内容
/// 内容
@property
(
nonatomic
,
strong
)
NSString
*
data
;
@property
(
nonatomic
,
strong
)
NSString
*
data
;
/// 路径
/// 路径
@property
(
nonatomic
,
strong
)
NSString
*
api
;
@property
(
nonatomic
,
strong
)
NSString
*
api
;
///插入表格名称
@property
(
nonatomic
,
strong
)
NSString
*
tableName
;
/// 数据状态
/// 数据状态
@property
(
nonatomic
,
assign
)
PhobosDataSendStatus
status
;
@property
(
nonatomic
,
assign
)
PhobosDataSendStatus
status
;
///是否是立刻发的埋点
///是否是立刻发的埋点
@property
(
nonatomic
,
assign
)
BOOL
immediately
;
@property
(
nonatomic
,
assign
)
BOOL
immediately
;
+
(
GMPhobosSqulitModel
*
)
modelOfDict
:(
NSDictionary
*
)
data
+
(
GMPhobosSqulitModel
*
)
modelOfDict
:(
NSDictionary
*
)
data
type
:(
NSString
*
)
phobosType
type
:(
NSString
*
)
phobosType
urlApi
:(
NSString
*
)
urlapi
urlApi
:(
NSString
*
)
urlapi
immediately
:(
BOOL
)
status
;
tableName
:(
NSString
*
)
name
immediately
:(
BOOL
)
status
;
@end
@end
GMPhobos/Classes/PhobosDataStorage/GMPhobosSqulitModel.m
View file @
4a58871b
...
@@ -6,17 +6,20 @@
...
@@ -6,17 +6,20 @@
//
//
#import "GMPhobosSqulitModel.h"
#import "GMPhobosSqulitModel.h"
#import <mach/mach_time.h>
@implementation
GMPhobosSqulitModel
@implementation
GMPhobosSqulitModel
+
(
GMPhobosSqulitModel
*
)
modelOfDict
:(
NSDictionary
*
)
data
+
(
GMPhobosSqulitModel
*
)
modelOfDict
:(
NSDictionary
*
)
data
type
:(
NSString
*
)
phobosType
type
:(
NSString
*
)
phobosType
urlApi
:(
NSString
*
)
urlapi
urlApi
:(
NSString
*
)
urlapi
immediately
:(
BOOL
)
status
{
tableName
:(
NSString
*
)
name
immediately
:(
BOOL
)
status
{
GMPhobosSqulitModel
*
model
=
[
GMPhobosSqulitModel
new
];
GMPhobosSqulitModel
*
model
=
[
GMPhobosSqulitModel
new
];
model
.
data
=
[
GMPhobosSqulitModel
dictionaryToJsonString
:
data
];
model
.
tableName
=
name
;
model
.
data
=
[
GMPhobosTool
dictionaryToJsonString
:
data
];
NSTimeInterval
time
=
[[
NSDate
date
]
timeIntervalSince1970
]
*
1000
;
NSTimeInterval
time
=
[[
NSDate
date
]
timeIntervalSince1970
]
*
1000
;
model
.
messageId
=
[
NSString
stringWithFormat
:
@"%.f*%lld"
,
time
,
mach_absolute_time
()];
model
.
messageI
temI
d
=
[
NSString
stringWithFormat
:
@"%.f*%lld"
,
time
,
mach_absolute_time
()];
model
.
status
=
PhobosDataSendStatus_wait
;
model
.
status
=
PhobosDataSendStatus_wait
;
model
.
phobosType
=
phobosType
;
model
.
phobosType
=
phobosType
;
model
.
api
=
urlapi
;
model
.
api
=
urlapi
;
...
@@ -24,13 +27,5 @@
...
@@ -24,13 +27,5 @@
return
model
;
return
model
;
}
}
+
(
NSString
*
)
dictionaryToJsonString
:(
NSDictionary
*
)
dict
{
NSError
*
error
=
nil
;
NSData
*
jsonData
=
[
NSJSONSerialization
dataWithJSONObject
:
dict
options
:
NSJSONWritingPrettyPrinted
error
:&
error
];
if
(
error
)
{
return
nil
;
}
return
[[
NSString
alloc
]
initWithData
:
jsonData
encoding
:
NSUTF8StringEncoding
];
}
@end
@end
GMPhobos/Classes/PhobosDataStorage/GMPhobosTool.h
0 → 100644
View file @
4a58871b
//
// GMPhobosTool.h
// GMPhobos
//
// Created by edz on 2020/6/23.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface
GMPhobosTool
:
NSObject
/// 拆分数组
/// @param array 原数组
/// @param subSize 每个数组的长度
+
(
NSArray
*
)
splitArray
:(
NSArray
*
)
array
withSubSize
:(
int
)
subSize
;
/// dictionary 转json
/// @param dict dict
+
(
NSString
*
)
dictionaryToJsonString
:(
NSDictionary
*
)
dict
;
@end
NS_ASSUME_NONNULL_END
GMPhobos/Classes/PhobosDataStorage/GMPhobosTool.m
0 → 100644
View file @
4a58871b
//
// GMPhobosTool.m
// GMPhobos
//
// Created by edz on 2020/6/23.
//
#import "GMPhobosTool.h"
@implementation
GMPhobosTool
+
(
NSArray
*
)
splitArray
:(
NSArray
*
)
array
withSubSize
:(
int
)
subSize
{
if
(
subSize
<
1
)
return
[
NSArray
new
];
// 数组将被拆分成指定长度数组的个数
unsigned
long
count
=
array
.
count
%
subSize
==
0
?
(
array
.
count
/
subSize
)
:
(
array
.
count
/
subSize
+
1
);
// 用来保存指定长度数组的可变数组对象
NSMutableArray
*
arr
=
[[
NSMutableArray
alloc
]
init
];
//利用总个数进行循环,将指定长度的元素加入数组
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
//数组下标
int
index
=
i
*
subSize
;
//保存拆分的固定长度的数组元素的可变数组
NSMutableArray
*
arr1
=
[[
NSMutableArray
alloc
]
init
];
//移除子数组的所有元素
[
arr1
removeAllObjects
];
int
j
=
index
;
//将数组下标乘以1、2、3,得到拆分时数组的最大下标值,但最大不能超过数组的总大小
while
(
j
<
subSize
*
(
i
+
1
)
&&
j
<
array
.
count
)
{
[
arr1
addObject
:[
array
objectAtIndex
:
j
]];
j
+=
1
;
}
//将子数组添加到保存子数组的数组中
[
arr
addObject
:[
arr1
copy
]];
}
return
[
arr
copy
];
}
+
(
NSString
*
)
dictionaryToJsonString
:(
NSDictionary
*
)
dict
{
NSError
*
error
=
nil
;
NSData
*
jsonData
=
[
NSJSONSerialization
dataWithJSONObject
:
dict
options
:
NSJSONWritingPrettyPrinted
error
:&
error
];
if
(
error
)
{
return
nil
;
}
return
[[
NSString
alloc
]
initWithData
:
jsonData
encoding
:
NSUTF8StringEncoding
];
}
@end
GMPhobos/Classes/PhobosDataStorage/GMSQliteManager.h
View file @
4a58871b
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
//
//
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>
#import <MJExtension/MJExtension.h>
// 数据库中常见的几种类型
// 数据库中常见的几种类型
#define SQL_TEXT @"TEXT" //文本
#define SQL_TEXT @"TEXT" //文本
...
@@ -16,9 +17,6 @@
...
@@ -16,9 +17,6 @@
@interface
GMSQliteManager
:
NSObject
@interface
GMSQliteManager
:
NSObject
#pragma mark - 创建数据库
/// 创建数据库的单利方法
+
(
instancetype
)
sharedSQliteManager
;
#pragma mark - 创建表
#pragma mark - 创建表
/// 创建表
/// 创建表
...
...
GMPhobos/Classes/PhobosDataStorage/GMSQliteManager.m
View file @
4a58871b
...
@@ -23,34 +23,26 @@
...
@@ -23,34 +23,26 @@
@implementation
GMSQliteManager
@implementation
GMSQliteManager
static
GMSQliteManager
*
squliteManager
=
nil
;
-
(
instancetype
)
init
{
+
(
instancetype
)
sharedSQliteManager
{
self
=
[
super
init
];
static
dispatch_once_t
onceToken
;
if
(
self
)
{
dispatch_once
(
&
onceToken
,
^
{
[
GMSQliteManager
shareDatabase
];
});
return
squliteManager
;
}
+
(
instancetype
)
shareDatabase
{
if
(
!
squliteManager
)
{
NSString
*
path
=
[[
NSSearchPathForDirectoriesInDomains
(
NSDocumentDirectory
,
NSUserDomainMask
,
YES
)
lastObject
]
stringByAppendingPathComponent
:
@"GMFMDB.sqlite"
];
NSString
*
path
=
[[
NSSearchPathForDirectoriesInDomains
(
NSDocumentDirectory
,
NSUserDomainMask
,
YES
)
lastObject
]
stringByAppendingPathComponent
:
@"GMFMDB.sqlite"
];
NSLog
(
@"path------%@"
,
path
);
NSLog
(
@"path------%@"
,
path
);
FMDatabase
*
fmdb
=
[
FMDatabase
databaseWithPath
:
path
];
FMDatabase
*
fmdb
=
[
FMDatabase
databaseWithPath
:
path
];
squliteManager
=
[
GMSQliteManager
new
];
self
.
db
=
fmdb
;
squliteManager
.
db
=
fmdb
;
self
.
dbPath
=
path
;
squliteManager
.
dbPath
=
path
;
FMDatabaseQueue
*
queue
=
[
FMDatabaseQueue
databaseQueueWithPath
:
path
];
FMDatabaseQueue
*
queue
=
[
FMDatabaseQueue
databaseQueueWithPath
:
path
];
s
quliteManager
.
dbQueue
=
queue
;
s
elf
.
dbQueue
=
queue
;
[
s
quliteManager
.
db
open
];
[
s
elf
.
db
open
];
}
}
if
(
!
s
quliteManager
.
db
.
isOpen
)
{
if
(
!
s
elf
.
db
.
isOpen
)
{
[
s
quliteManager
.
db
open
];
[
s
elf
.
db
open
];
}
}
return
s
quliteManager
;
return
s
elf
;
}
}
/// 创建表
/// 创建表
-
(
BOOL
)
gm_createTable
:
(
NSString
*
)
tableName
model
:
(
Class
)
modelClass
{
-
(
BOOL
)
gm_createTable
:
(
NSString
*
)
tableName
model
:
(
Class
)
modelClass
{
NSDictionary
*
dict
=
[
self
modelToDictionary
:
modelClass
excludePropertyName
:
nil
];
NSDictionary
*
dict
=
[
self
modelToDictionary
:
modelClass
excludePropertyName
:
nil
];
...
@@ -79,7 +71,8 @@ static GMSQliteManager *squliteManager = nil;
...
@@ -79,7 +71,8 @@ static GMSQliteManager *squliteManager = nil;
/// 模型插入
/// 模型插入
-
(
BOOL
)
gm_insertTable
:
(
NSString
*
)
tableName
model
:
(
NSObject
*
)
model
{
-
(
BOOL
)
gm_insertTable
:
(
NSString
*
)
tableName
model
:
(
NSObject
*
)
model
{
//模型转字典
//模型转字典
NSDictionary
*
dict
=
[
self
getModelPropertyKeyValue
:
model
];
NSDictionary
*
dict
=
model
.
mj_keyValues
;;
bool
status
=
[
self
gm_insertTable
:
tableName
dict
:
dict
];
bool
status
=
[
self
gm_insertTable
:
tableName
dict
:
dict
];
return
status
;
return
status
;
}
}
...
@@ -176,7 +169,8 @@ static GMSQliteManager *squliteManager = nil;
...
@@ -176,7 +169,8 @@ static GMSQliteManager *squliteManager = nil;
if
([
parameters
isKindOfClass
:[
NSDictionary
class
]])
{
if
([
parameters
isKindOfClass
:[
NSDictionary
class
]])
{
dict
=
parameters
;
dict
=
parameters
;
}
else
if
([
parameters
isKindOfClass
:[
NSObject
class
]])
{
}
else
if
([
parameters
isKindOfClass
:[
NSObject
class
]])
{
dict
=
[
self
getModelPropertyKeyValue
:
parameters
];
NSObject
*
object
=
(
NSObject
*
)
parameters
;
dict
=
object
.
mj_keyValues
;
}
else
{
}
else
{
return
NO
;
return
NO
;
}
}
...
@@ -208,7 +202,9 @@ static GMSQliteManager *squliteManager = nil;
...
@@ -208,7 +202,9 @@ static GMSQliteManager *squliteManager = nil;
objectClass
:
(
Class
)
cls
objectClass
:
(
Class
)
cls
whereFormat
:
(
NSString
*
)
format
{
whereFormat
:
(
NSString
*
)
format
{
NSDictionary
*
modlDict
=
[
self
modelToDictionary
:
cls
excludePropertyName
:
filterArray
];
NSDictionary
*
modlDict
=
[
self
modelToDictionary
:
cls
excludePropertyName
:
filterArray
];
return
[
self
gm_lookupTable
:
tableName
keyArray
:
modlDict
.
allKeys
whereFormat
:
format
];
NSArray
*
array
=
[
self
gm_lookupTable
:
tableName
keyArray
:
modlDict
.
allKeys
whereFormat
:
format
];
NSMutableArray
*
modelArray
=
[
cls
mj_objectArrayWithKeyValuesArray
:
array
];
return
modelArray
;
}
}
-
(
NSArray
*
)
gm_lookupTable
:
(
NSString
*
)
tableName
keyArray
:
(
NSArray
*
)
keyArray
whereFormat
:
(
NSString
*
)
format
{
-
(
NSArray
*
)
gm_lookupTable
:
(
NSString
*
)
tableName
keyArray
:
(
NSArray
*
)
keyArray
whereFormat
:
(
NSString
*
)
format
{
...
@@ -312,45 +308,27 @@ static GMSQliteManager *squliteManager = nil;
...
@@ -312,45 +308,27 @@ static GMSQliteManager *squliteManager = nil;
}];
}];
}
}
#pragma mark - 模型转字典
-
(
NSDictionary
*
)
getModelPropertyKeyValue
:
(
id
)
model
{
NSMutableDictionary
*
mDic
=
[[
NSMutableDictionary
alloc
]
init
];
unsigned
int
outCount
;
objc_property_t
*
properties
=
class_copyPropertyList
([
model
class
],
&
outCount
);
for
(
int
i
=
0
;
i
<
outCount
;
i
++
)
{
NSString
*
name
=
[
NSString
stringWithCString
:
property_getName
(
properties
[
i
])
encoding
:
NSUTF8StringEncoding
];
id
value
=
[
model
valueForKey
:
name
];
if
(
value
)
{
[
mDic
setObject
:
value
forKey
:
name
];
}
}
free
(
properties
);
return
mDic
;
}
#pragma mark - 通过类对象获取对象的Property的字典 key 是属性名称, value是属性的类型
#pragma mark - 通过类对象获取对象的Property的字典 key 是属性名称, value是属性的类型
-
(
NSDictionary
*
)
modelToDictionary
:
(
Class
)
cls
excludePropertyName
:
(
NSArray
*
)
nameArr
-
(
NSDictionary
*
)
modelToDictionary
:
(
Class
)
cls
excludePropertyName
:
(
NSArray
*
)
nameArr
{
{
if
(
cls
==
[
NSObject
class
])
{
return
[
NSMutableDictionary
dictionary
];
}
NSMutableDictionary
*
mDic
=
[[
NSMutableDictionary
alloc
]
init
];
NSMutableDictionary
*
mDic
=
[[
NSMutableDictionary
alloc
]
init
];
unsigned
int
outCount
;
unsigned
int
outCount
;
objc_property_t
*
properties
=
class_copyPropertyList
(
cls
,
&
outCount
);
objc_property_t
*
properties
=
class_copyPropertyList
(
cls
,
&
outCount
);
for
(
int
i
=
0
;
i
<
outCount
;
i
++
)
{
for
(
int
i
=
0
;
i
<
outCount
;
i
++
)
{
NSString
*
name
=
[
NSString
stringWithCString
:
property_getName
(
properties
[
i
])
encoding
:
NSUTF8StringEncoding
];
NSString
*
name
=
[
NSString
stringWithCString
:
property_getName
(
properties
[
i
])
encoding
:
NSUTF8StringEncoding
];
if
([
nameArr
containsObject
:
name
])
continue
;
if
([
nameArr
containsObject
:
name
])
continue
;
NSString
*
type
=
[
NSString
stringWithCString
:
property_getAttributes
(
properties
[
i
])
encoding
:
NSUTF8StringEncoding
];
NSString
*
type
=
[
NSString
stringWithCString
:
property_getAttributes
(
properties
[
i
])
encoding
:
NSUTF8StringEncoding
];
id
value
=
[
self
propertTypeConvert
:
type
];
id
value
=
[
self
propertTypeConvert
:
type
];
if
(
value
)
{
if
(
value
)
{
[
mDic
setObject
:
value
forKey
:
name
];
[
mDic
setObject
:
value
forKey
:
name
];
}
}
}
}
free
(
properties
);
free
(
properties
);
NSDictionary
*
subDict
=
[
self
modelToDictionary
:[
cls
superclass
]
excludePropertyName
:
nameArr
];
[
mDic
addEntriesFromDictionary
:
subDict
];
return
mDic
;
return
mDic
;
}
}
...
...
GMPhobos/Classes/PhobosDataStorage/PhobosDataManager.m
View file @
4a58871b
This diff is collapsed.
Click to expand it.
GMPhobos/Classes/PhobosDataStorage/PhobosSendManager.m
View file @
4a58871b
...
@@ -55,21 +55,8 @@
...
@@ -55,21 +55,8 @@
}
}
+
(
void
)
sendDataWithEntities
:
(
NSArray
<
GMPhobosSqulitModel
*>
*
)
sendDataEntities
completion
:
(
void
(
^
)(
NSArray
<
GMPhobosSqulitModel
*>
*
_Nonnull
,
NSInteger
))
completion
{
+
(
void
)
sendDataWithEntities
:
(
NSArray
<
GMPhobosSqulitModel
*>
*
)
sendDataEntities
completion
:
(
void
(
^
)(
NSArray
<
GMPhobosSqulitModel
*>
*
_Nonnull
,
NSInteger
))
completion
{
if
(
sendDataEntities
.
count
==
0
)
{
if
(
sendDataEntities
.
count
==
0
)
return
;
return
;
}
else
if
(
sendDataEntities
.
count
>
PhobosMaxSendCount
)
{
/** 如果数据超过 PhobosMaxSendCount 数据规模,进行拆分,分批发送,默认100条 */
NSMutableArray
*
temp
=
[
NSMutableArray
arrayWithCapacity
:
PhobosMaxSendCount
];
[
sendDataEntities
enumerateObjectsUsingBlock
:
^
(
GMPhobosSqulitModel
*
_Nonnull
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
if
(
temp
.
count
>=
PhobosMaxSendCount
)
{
// 会调用当前方法,但数据规模不会满足 > PhobosMaxSendCount,不会让数据走到下面的发送,拆分完成 会执行return
[
self
sendDataWithEntities
:
temp
completion
:
completion
];
[
temp
removeAllObjects
];
}
[
temp
addObject
:
obj
];
}];
return
;
}
NSMutableDictionary
*
sendDataMap
=
[
NSMutableDictionary
new
];
NSMutableDictionary
*
sendDataMap
=
[
NSMutableDictionary
new
];
// 将相同api的数据合并
// 将相同api的数据合并
[
sendDataEntities
enumerateObjectsUsingBlock
:
^
(
GMPhobosSqulitModel
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
sendDataEntities
enumerateObjectsUsingBlock
:
^
(
GMPhobosSqulitModel
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
...
...
GMPhobos/Classes/UIResponder+PhobosPV.m
View file @
4a58871b
...
@@ -242,11 +242,11 @@
...
@@ -242,11 +242,11 @@
}
}
-
(
void
)
setMessageId
:
(
NSString
*
)
messageId
{
-
(
void
)
setMessageId
:
(
NSString
*
)
messageId
{
objc_setAssociatedObject
(
self
,
@selector
(
messageId
),
messageId
,
OBJC_ASSOCIATION_COPY_NONATOMIC
);
objc_setAssociatedObject
(
self
,
@selector
(
messageI
temI
d
),
messageId
,
OBJC_ASSOCIATION_COPY_NONATOMIC
);
}
}
-
(
NSString
*
)
messageId
{
-
(
NSString
*
)
messageId
{
NSString
*
messageId
=
objc_getAssociatedObject
(
self
,
@selector
(
messageId
));
NSString
*
messageId
=
objc_getAssociatedObject
(
self
,
@selector
(
messageI
temI
d
));
return
messageId
==
nil
?
@""
:
messageId
;
return
messageId
==
nil
?
@""
:
messageId
;
}
}
...
...
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