-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
383 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/swift,xcode,swiftpackagemanager,cocoapods | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=swift,xcode,swiftpackagemanager,cocoapods | ||
|
||
### CocoaPods ### | ||
## CocoaPods GitIgnore Template | ||
|
||
# CocoaPods - Only use to conserve bandwidth / Save time on Pushing | ||
# - Also handy if you have a large number of dependant pods | ||
# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE | ||
Pods/ | ||
|
||
### Swift ### | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## User settings | ||
xcuserdata/ | ||
|
||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) | ||
*.xcscmblueprint | ||
*.xccheckout | ||
|
||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) | ||
build/ | ||
DerivedData/ | ||
*.moved-aside | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
|
||
## App packaging | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
# Package.resolved | ||
# *.xcodeproj | ||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata | ||
# hence it is not needed unless you have added a package configuration file to your project | ||
# .swiftpm | ||
|
||
.build/ | ||
|
||
# CocoaPods | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# Pods/ | ||
# Add this line if you want to avoid checking in source code from the Xcode workspace | ||
# *.xcworkspace | ||
|
||
# Carthage | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build/ | ||
|
||
# Accio dependency management | ||
Dependencies/ | ||
.accio/ | ||
|
||
# fastlane | ||
# It is recommended to not store the screenshots in the git repo. | ||
# Instead, use fastlane to re-generate the screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
# Code Injection | ||
# After new code Injection tools there's a generated folder /iOSInjectionProject | ||
# https://github.com/johnno1962/injectionforxcode | ||
|
||
iOSInjectionProject/ | ||
|
||
### SwiftPackageManager ### | ||
Packages | ||
xcuserdata | ||
*.xcodeproj | ||
|
||
|
||
### Xcode ### | ||
|
||
## Xcode 8 and earlier | ||
|
||
### Xcode Patch ### | ||
*.xcodeproj/* | ||
!*.xcodeproj/project.pbxproj | ||
!*.xcodeproj/xcshareddata/ | ||
!*.xcworkspace/contents.xcworkspacedata | ||
/*.gcno | ||
**/xcshareddata/WorkspaceSettings.xcsettings | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/swift,xcode,swiftpackagemanager,cocoapods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import UIKit | ||
import Combine | ||
import UIHangDetector | ||
|
||
@main | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
var window: UIWindow? | ||
|
||
private let hangDetector = UIHangDetector( | ||
warningCriteria: 500(.milliseconds), | ||
criticalCriteria: 1(.seconds), | ||
healthSignalInterval: 500(.milliseconds), | ||
healthSignalCheckInterval: 100(.milliseconds) | ||
) | ||
|
||
private var cancellableBag: Set<AnyCancellable> = [] | ||
|
||
func application( | ||
_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
) -> Bool { | ||
self.window = UIWindow().then { | ||
$0.backgroundColor = .black | ||
$0.rootViewController = MainViewController() | ||
} | ||
self.window?.makeKeyAndVisible() | ||
|
||
self.hangDetector.healthStream | ||
.sink { print("[\(Date())]\t\($0)") } | ||
.store(in: &self.cancellableBag) | ||
self.hangDetector.start() | ||
|
||
// _ = Timer.scheduledTimer(withTimeInterval: 10.0, repeats: true) { _ in | ||
// self.hangDetector.stop() | ||
// } | ||
// | ||
// _ = Timer.scheduledTimer(withTimeInterval: 15.0, repeats: true) { _ in | ||
// self.hangDetector.start() | ||
// } | ||
|
||
return true | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Demo/UIHangDetectorDemo/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
Demo/UIHangDetectorDemo/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "83.5x83.5" | ||
}, | ||
{ | ||
"idiom" : "ios-marketing", | ||
"scale" : "1x", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Demo/UIHangDetectorDemo/Base.lproj/LaunchScreen.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="EHf-IW-A2E"> | ||
<objects> | ||
<viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> | ||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="53" y="375"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict/> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import UIKit | ||
import Combine | ||
import Then | ||
import SnapKit | ||
import UIHangDetector | ||
|
||
class MainViewController: UIViewController { | ||
private let nonBlockingFreezeButton: UIButton = UIButton(type: .system).then { | ||
$0.setTitle("Run Non-Blocking", for: .normal) | ||
$0.setTitle("Stopped", for: .disabled) | ||
$0.sizeToFit() | ||
} | ||
|
||
private let blockingFreezeButton: UIButton = UIButton(type: .system).then { | ||
$0.setTitle("Run Blocking", for: .normal) | ||
$0.setTitle("Stopped", for: .disabled) | ||
$0.sizeToFit() | ||
} | ||
|
||
private let timerLabel: UILabel = UILabel().then { | ||
$0.textColor = .white | ||
$0.textAlignment = .center | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.view.backgroundColor = .white | ||
|
||
self.nonBlockingFreezeButton.addTarget(self, action: #selector(self.nonBlockingButtonDidTap), for: .touchUpInside) | ||
self.blockingFreezeButton.addTarget(self, action: #selector(self.blockingButtonDidTap), for: .touchUpInside) | ||
|
||
let stack = UIStackView(arrangedSubviews: [ | ||
self.nonBlockingFreezeButton, | ||
self.blockingFreezeButton, | ||
self.timerLabel, | ||
]) | ||
stack.axis = .vertical | ||
self.view.addSubview(stack) | ||
stack.snp.makeConstraints { | ||
$0.center.equalToSuperview() | ||
} | ||
|
||
self.timerDidFire( | ||
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true, block: self.timerDidFire) | ||
) | ||
} | ||
|
||
@objc | ||
private func nonBlockingButtonDidTap(_ sender: UIButton) { | ||
print("[\(Date())]\tButtonClicked") | ||
Task { | ||
sender.isEnabled = false | ||
try await Task.sleep(forDuration: 5(.seconds)) | ||
sender.isEnabled = true | ||
} | ||
} | ||
|
||
@objc | ||
private func blockingButtonDidTap(_ sender: UIButton) { | ||
print("[\(Date())]\tButtonClicked") | ||
sender.isEnabled = false | ||
Thread.sleep(forDuration: 5(.seconds)) | ||
sender.isEnabled = true | ||
} | ||
|
||
private func timerDidFire(_ timer: Timer) { | ||
let dateFormatter = DateFormatter().then { | ||
$0.dateFormat = "hh:mm:ss" | ||
$0.timeZone = TimeZone.current | ||
} | ||
self.timerLabel.text = dateFormatter.string(from: Date()) | ||
|
||
switch (Int(Date().timeIntervalSince1970) % 3) { | ||
case 0: self.timerLabel.backgroundColor = UIColor.red | ||
case 1: self.timerLabel.backgroundColor = UIColor.green | ||
case 2: self.timerLabel.backgroundColor = UIColor.blue | ||
default: fatalError() | ||
} | ||
} | ||
} |