Skip to content

Commit

Permalink
test: Add periodic work to sample app (#3422)
Browse files Browse the repository at this point in the history
Periodically read a file and perform a network request in the iOS-Swift
sample app, which will help test carrier transactions.
  • Loading branch information
philipphofmann committed Nov 17, 2023
1 parent 75ef4eb commit 7c69adf
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion Samples/iOS-Swift/iOS-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,52 @@ import UIKit
class ViewController: UIViewController {

private let dispatchQueue = DispatchQueue(label: "ViewController", attributes: .concurrent)
private var timer: Timer?

override func viewDidLoad() {
super.viewDidLoad()
SentrySDK.reportFullyDisplayed()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
periodicallyDoWork()
}

override func viewDidDisappear(_ animated: Bool) {
super .viewDidDisappear(animated)
self.timer?.invalidate()
}

private func periodicallyDoWork() {

self.timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { _ in
self.dispatchQueue.async {
self.loadSentryBrandImage()
Thread.sleep(forTimeInterval: 1.0)
self.readLoremIpsumFile()
}
}
RunLoop.current.add(self.timer!, forMode: .common)
self.timer!.fire()
}

@IBAction func uiClickTransaction(_ sender: UIButton) {
highlightButton(sender)

readLoremIpsumFile()
loadSentryBrandImage()
}

private func readLoremIpsumFile() {
dispatchQueue.async {
if let path = Bundle.main.path(forResource: "LoremIpsum", ofType: "txt") {
_ = FileManager.default.contents(atPath: path)
}
}

}

private func loadSentryBrandImage() {
guard let imgUrl = URL(string: "https://sentry-brand.storage.googleapis.com/sentry-logo-black.png") else {
return
}
Expand Down

0 comments on commit 7c69adf

Please sign in to comment.