Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CRMNetDetect
Overview
Overview
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
oc
CRMNetDetect
Commits
e169a434
Commit
e169a434
authored
Oct 21, 2024
by
GuoJianPeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
f530f5e7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
13 deletions
+92
-13
CRMNetDetect/Classes/CRMNetDetectService.m
+39
-9
CRMNetDetect/Classes/CRMNetDetectView.m
+52
-4
Example/CRMNetDetect/ASViewController.m
+1
-0
No files found.
CRMNetDetect/Classes/CRMNetDetectService.m
View file @
e169a434
...
...
@@ -6,6 +6,7 @@
//
#import "CRMNetDetectService.h"
#import <sys/time.h>
@interface
CRMNetDetectService
()
<
ASPingServiceDelegate
,
ASReachabilityDelegate
>
{
...
...
@@ -87,18 +88,47 @@
#pragma mark - Ping
-
(
void
)
_readHostAndPing
{
if
(
!
_pingService
){
_pingService
=
[[
ASPingService
alloc
]
initWithDelegate
:
self
];
NSString
*
host
=
_pingingHostList
.
firstObject
;
NSInteger
index
=
[
_businessHostList
indexOfObject
:
host
];
NSMutableURLRequest
*
request
=
[
NSMutableURLRequest
requestWithURL
:[
NSURL
URLWithString
:[
@"https://"
stringByAppendingString
:
_pingingHostList
.
firstObject
]]];
request
.
HTTPMethod
=
@"HEAD"
;
CFTimeInterval
startTime
=
CACurrentMediaTime
();
__typeof
(
self
)
__weak
weakSelf
=
self
;
[[[
NSURLSession
sharedSession
]
dataTaskWithRequest
:
request
completionHandler
:
^
(
NSData
*
_Nullable
data
,
NSURLResponse
*
_Nullable
response
,
NSError
*
_Nullable
error
)
{
__typeof
(
weakSelf
)
__strong
self
=
weakSelf
;
if
(
!
self
){
return
;}
CFTimeInterval
endTime
=
CACurrentMediaTime
();
NSTimeInterval
duration
=
0
;
if
(
endTime
<
startTime
){
endTime
=
startTime
+
1
;
}
duration
=
(
endTime
-
startTime
)
*
1000
;
[
self
->
_pingingHostList
removeObjectAtIndex
:
0
];
[
self
.
delegate
didGotBusinessServiceState
:
!
error
host
:
host
hostIndex
:
index
millionSeconds
:
duration
];
if
(
!
error
){
self
->
_successPingHostCount
++
;
}
if
(
!
_pingingHostList
.
count
){
[
self
.
delegate
didFinishedBusinessService
:
_successPingHostCount
==
_
businessHostList
.
count
];
if
(
!
self
->
_pingingHostList
.
count
){
[
self
.
delegate
didFinishedBusinessService
:
self
->
_successPingHostCount
==
self
.
businessHostList
.
count
];
[
self
stopDetecting
];
return
;
}
else
{
[
self
_readHostAndPing
];
}
_pingService
.
targetHost
=
_pingingHostList
.
firstObject
;
_pingService
.
pingCount
=
1
;
_pingService
.
timeoutSeconds
=
1
;
[
_pingService
starts
];
}]
resume
];
// if(!_pingService){
// _pingService = [[ASPingService alloc] initWithDelegate:self];
// }
// if (!_pingingHostList.count){
// [self.delegate didFinishedBusinessService:_successPingHostCount == _businessHostList.count];
// [self stopDetecting];
// return;
// }
// _pingService.targetHost = _pingingHostList.firstObject;
// _pingService.pingCount = 1;
// _pingService.timeoutSeconds = 1;
// [_pingService starts];
}
-
(
void
)
_stopPingService
{
...
...
CRMNetDetect/Classes/CRMNetDetectView.m
View file @
e169a434
...
...
@@ -18,6 +18,7 @@
@property
(
nonatomic
,
strong
)
UIButton
*
checkButton
;
@property
(
nonatomic
,
strong
)
UIImageView
*
signalImageView
;
@property
(
nonatomic
,
strong
)
NSMutableArray
<
CRMNetDetectCellData
*>*
cellDatas
;
@property
(
nonatomic
,
strong
)
UIActivityIndicatorView
*
checkingIndicateView
;
@end
@implementation
CRMNetDetectView
...
...
@@ -108,6 +109,7 @@
_signalStrengthData
.
rightText
=
(
strength
==
CRMNetSignalStrengthStrong
)?
@"强"
:
@"弱"
;
}
[
self
.
tableView
reloadData
];
[
self
.
tableView
setTableFooterView
:[
self
_footView
]];
}
-
(
void
)
didGotIPState
:
(
BOOL
)
isNormal
{
...
...
@@ -116,15 +118,29 @@
}
-
(
void
)
didGotBusinessServiceState
:
(
BOOL
)
isNormal
host
:
(
nonnull
NSString
*
)
host
hostIndex
:
(
NSInteger
)
hostIndex
millionSeconds
:
(
NSTimeInterval
)
millionSeconds
{
CRMNetDetectCellData
*
data
=
_cellDatas
[
hostIndex
+
_staticCellDataCount
];
__typeof
(
self
)
__weak
weakSelf
=
self
;
dispatch_async
(
dispatch_get_main_queue
(),
^
{
__typeof
(
weakSelf
)
__strong
self
=
weakSelf
;
if
(
!
self
){
return
;}
CRMNetDetectCellData
*
data
=
self
.
cellDatas
[
hostIndex
+
self
->
_staticCellDataCount
];
data
.
state
=
isNormal
?
CRMNetDetectCellStateNormal
:
CRMNetDetectCellStateNotNormal
;
data
.
rightText
=
isNormal
?
[
NSString
stringWithFormat
:
@"正常 %ld ms"
,(
NSInteger
)
millionSeconds
]
:
@"异常"
;
[
self
.
tableView
reloadData
];
});
}
-
(
void
)
didFinishedBusinessService
:
(
BOOL
)
isNormal
{
_serverConnectData
.
state
=
isNormal
?
CRMNetDetectCellStateNormal
:
CRMNetDetectCellStateNotNormal
;
__typeof
(
self
)
__weak
weakSelf
=
self
;
dispatch_async
(
dispatch_get_main_queue
(),
^
{
__typeof
(
weakSelf
)
__strong
self
=
weakSelf
;
if
(
!
self
){
return
;}
self
->
_serverConnectData
.
state
=
isNormal
?
CRMNetDetectCellStateNormal
:
CRMNetDetectCellStateNotNormal
;
[
self
.
tableView
reloadData
];
[
self
.
tableView
setTableFooterView
:[
self
_footView
]];
});
}
#pragma mark - Getters
-
(
UIButton
*
)
checkButton
...
...
@@ -135,19 +151,51 @@
_checkButton
.
backgroundColor
=
[
UIColor
colorWithRed
:
238
/
255
.
0
green
:
131
/
255
.
0
blue
:
68
/
255
.
0
alpha
:
1
];
[
_checkButton
setTitle
:
@"重新检测"
forState
:
UIControlStateNormal
];
[
_checkButton
setTitleColor
:
UIColor
.
whiteColor
forState
:
UIControlStateNormal
];
[
_checkButton
.
titleLabel
setFont
:[
UIFont
systemFontOfSize
:
1
4
]];
[
_checkButton
.
titleLabel
setFont
:[
UIFont
systemFontOfSize
:
1
5
]];
[
_checkButton
addTarget
:
self
action
:
@selector
(
startsChecking
)
forControlEvents
:
UIControlEventTouchUpInside
];
}
return
_checkButton
;
}
-
(
UIActivityIndicatorView
*
)
checkingIndicateView
{
if
(
!
_checkingIndicateView
){
if
(
@available
(
iOS
13
.
0
,
*
))
{
_checkingIndicateView
=
[[
UIActivityIndicatorView
alloc
]
initWithActivityIndicatorStyle
:
UIActivityIndicatorViewStyleMedium
];
}
else
{
_checkingIndicateView
=
[[
UIActivityIndicatorView
alloc
]
initWithActivityIndicatorStyle
:
UIActivityIndicatorViewStyleWhite
];
}
_checkingIndicateView
.
translatesAutoresizingMaskIntoConstraints
=
false
;
_checkingIndicateView
.
color
=
UIColor
.
whiteColor
;
}
return
_checkingIndicateView
;
}
-
(
UIView
*
)
_footView
{
CGFloat
marginTop
=
50
;
CGFloat
marginBottom
=
20
;
CGFloat
btnHeight
=
4
0
;
CGFloat
btnHeight
=
4
5
;
UIButton
*
btn
=
self
.
checkButton
;
UIView
*
view
=
[[
UIView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
width
,
marginTop
+
marginBottom
+
btnHeight
)];
[
view
addSubview
:
btn
];
btn
.
frame
=
CGRectMake
(
20
,
marginTop
,
view
.
bounds
.
size
.
width
-
40
,
btnHeight
);
if
(
_service
.
isDetecting
){
[
btn
setTitle
:
@"正在检测"
forState
:
UIControlStateNormal
];
btn
.
titleEdgeInsets
=
UIEdgeInsetsMake
(
0
,
0
,
0
,
-
35
);
btn
.
enabled
=
false
;
btn
.
backgroundColor
=
[
UIColor
colorWithRed
:
248
/
255
.
0
green
:
218
/
255
.
0
blue
:
195
/
255
.
0
alpha
:
1
];
[
self
.
checkingIndicateView
setHidden
:
false
];
[
view
addSubview
:
_checkingIndicateView
];
[[
_checkingIndicateView
.
centerYAnchor
constraintEqualToAnchor
:
btn
.
centerYAnchor
]
setActive
:
true
];
[[
_checkingIndicateView
.
centerXAnchor
constraintEqualToAnchor
:
btn
.
centerXAnchor
constant
:
-
35
]
setActive
:
true
];
[[
_checkingIndicateView
.
widthAnchor
constraintEqualToConstant
:
20
]
setActive
:
true
];
[[
_checkingIndicateView
.
heightAnchor
constraintEqualToConstant
:
20
]
setActive
:
true
];
[
_checkingIndicateView
startAnimating
];
}
else
{
btn
.
alpha
=
1
;
[
btn
setTitle
:
@"重新检测"
forState
:
UIControlStateNormal
];
btn
.
backgroundColor
=
[
UIColor
colorWithRed
:
238
/
255
.
0
green
:
131
/
255
.
0
blue
:
68
/
255
.
0
alpha
:
1
];
btn
.
enabled
=
true
;
btn
.
titleEdgeInsets
=
UIEdgeInsetsZero
;
}
return
view
;
}
-
(
UIView
*
)
_headView
...
...
Example/CRMNetDetect/ASViewController.m
View file @
e169a434
...
...
@@ -33,6 +33,7 @@
@"host"
:
@"my-uat1.orangebank.com.cn"
}
]];
[
_detectView
startsChecking
];
// Do any additional setup after loading the view, typically from a nib.
}
...
...
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