Skip to content

Commit

Permalink
update notification
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonHu committed Jun 27, 2022
1 parent 825aae0 commit cb41fd3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion HDPingTools.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'HDPingTools'
s.swift_version = '5.0'
s.version = '1.2.5'
s.version = '1.2.6'
s.license= { :type => "MIT", :file => "LICENSE" }
s.summary = "iOS Ping tool, based on Apple's simplePing project"
s.homepage = 'https://github.com/DamonHu/HDPingTools'
Expand Down
14 changes: 9 additions & 5 deletions pod/HDPingTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ open class HDPingTools: NSObject {
pinger = SimplePing(hostName: host)
super.init()
pinger.delegate = self
//切到后台
NotificationCenter.default.addObserver(self, selector: #selector(_didEnterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
//切到前台
NotificationCenter.default.addObserver(self, selector: #selector(_didBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
}

public convenience init(url: URL?) {
Expand All @@ -114,6 +110,11 @@ open class HDPingTools: NSObject {
/// - complete: 请求的回调
public func start(pingType: SimplePingAddressStyle = .any, interval: HDPingTimeInterval = .second(0), complete: PingComplete? = nil) {
self.stop()
//切到后台
NotificationCenter.default.addObserver(self, selector: #selector(_didEnterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
//切到前台
NotificationCenter.default.addObserver(self, selector: #selector(_didBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
//
self.pingInterval = interval
self.complete = complete
self.pinger.addressStyle = pingType
Expand All @@ -135,7 +136,10 @@ open class HDPingTools: NSObject {
//停止发送ping
sendTimer?.invalidate()
sendTimer = nil


//移除消息订阅
NotificationCenter.default.removeObserver(self)

#if canImport(ZXKitCore)
ZXKit.resetFloatButton()
ZXKit.textField?.placeholder = self.hostName ?? "www.apple.com"
Expand Down

0 comments on commit cb41fd3

Please # to comment.