Skip to content

Commit

Permalink
fix InstanaExample issues on iOS 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongyan Jiang authored and GitHub Enterprise committed Aug 29, 2023
1 parent 0ea9f54 commit 4436b56
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 42 deletions.
17 changes: 14 additions & 3 deletions Dev/InstanaAgentExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -29,6 +29,7 @@
72976A9A2681C45800A284F6 /* Webserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72976A992681C45800A284F6 /* Webserver.swift */; };
729C88B5270DE98200492486 /* AFNetworking in Frameworks */ = {isa = PBXBuildFile; productRef = 729C88B4270DE98200492486 /* AFNetworking */; };
729C88B8270DF13700492486 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 729C88B7270DF13700492486 /* Alamofire */; };
A4EFD6A12A9983FB00B9A9A3 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4EFD6A02A9983FB00B9A9A3 /* WebKit.framework */; };
CE322E492A6E3CEF00414F37 /* TopRatedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE322E482A6E3CEF00414F37 /* TopRatedViewController.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -69,6 +70,7 @@
727AF73A263AA0FA00B9C59B /* EventListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventListViewController.swift; sourceTree = "<group>"; };
72976A992681C45800A284F6 /* Webserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Webserver.swift; path = "../../Tests/InstanaAgentTests/Test helpers/Webserver.swift"; sourceTree = "<group>"; };
72FBE8A7263AACDB00CF2CDE /* InstanaAgentExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = InstanaAgentExample.entitlements; sourceTree = "<group>"; };
A4EFD6A02A9983FB00B9A9A3 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/iOSSupport/System/Library/PrivateFrameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; };
CE322E482A6E3CEF00414F37 /* TopRatedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopRatedViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -85,6 +87,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A4EFD6A12A9983FB00B9A9A3 /* WebKit.framework in Frameworks */,
729C88B8270DF13700492486 /* Alamofire in Frameworks */,
727AF748263AA16A00B9C59B /* InstanaAgent in Frameworks */,
729C88B5270DE98200492486 /* AFNetworking in Frameworks */,
Expand Down Expand Up @@ -160,6 +163,7 @@
727AF710263A9FC800B9C59B /* Frameworks */ = {
isa = PBXGroup;
children = (
A4EFD6A02A9983FB00B9A9A3 /* WebKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -355,6 +359,7 @@
};
72FBE8AC263AAD0900CF2CDE /* Import secure variables */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -373,6 +378,7 @@
};
72FBE8AD263AAD2000CF2CDE /* SwiftLint & SwiftFormat */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -391,6 +397,7 @@
};
72FBE8AE263AAD4C00CF2CDE /* Reset */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -650,8 +657,9 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = InstanaAgentExample/InstanaAgentExample.entitlements;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = D5PCJAP39R;
DEVELOPMENT_TEAM = 6K4C9F3Z9X;
INFOPLIST_FILE = InstanaAgentExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -671,8 +679,9 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = InstanaAgentExample/InstanaAgentExample.entitlements;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = D5PCJAP39R;
DEVELOPMENT_TEAM = 6K4C9F3Z9X;
INFOPLIST_FILE = InstanaAgentExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -690,6 +699,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = iOSAgentUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -708,6 +718,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = iOSAgentUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
89 changes: 66 additions & 23 deletions Dev/InstanaAgentExample/EventListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class EventListViewController: UITableViewController {

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

rateButton.setImage(UIImage(systemName: "star"), for: .normal)
rateButton.setImage(UIImage(systemName: "star.fill"), for: .selected)
if #available(iOS 13.0, *) {
rateButton.setImage(UIImage(systemName: "star"), for: .normal)
rateButton.setImage(UIImage(systemName: "star.fill"), for: .selected)
}
accessoryView = rateButton
}

Expand All @@ -47,7 +48,9 @@ class EventListViewController: UITableViewController {



@available(iOS 13.0, *)
private var publisher: AnyCancellable?

lazy var session = { URLSession(configuration: URLSessionConfiguration.default) }()

override func viewDidLoad() {
Expand All @@ -70,16 +73,36 @@ class EventListViewController: UITableViewController {

func loadJSON() {
let url = URL(string: "https://api.mygigs.tapwork.de/eventsnearby?radius=80.0&latitude=52.52&longitude=13.410&apitoken=xQ3vdfKVIF")!
publisher = session.dataTaskPublisher(for: url)
.receive(on: RunLoop.main)
.map { $0.data }
.decode(type: DataSource.self, decoder: JSONDecoder())
.sink(receiveCompletion: { _ in }, receiveValue: {[weak self] model in
guard let self = self else { return }
dataSource = model
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
})
if #available(iOS 13.0, *) {
publisher = session.dataTaskPublisher(for: url)
.receive(on: RunLoop.main)
.map { $0.data }
.decode(type: DataSource.self, decoder: JSONDecoder())
.sink(receiveCompletion: { _ in }, receiveValue: {[weak self] model in
guard let self = self else { return }
dataSource = model
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
})
} else {
let task = session.dataTask(with: url) { data, response, error in
guard let data = data else {
print("Empty data. error: ", error ?? "nil")
return
}
do {
let model: DataSource? = try JSONDecoder().decode(DataSource.self, from: data)
DispatchQueue.main.async {
dataSource = model
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
}
} catch {
print("Error ", error)
}
}
task.resume()
}
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
Expand Down Expand Up @@ -128,6 +151,8 @@ class DetailViewController: UIViewController {
let label = UILabel()
let imageView = UIImageView()
let event: DataSource.Event

@available(iOS 13.0, *)
private var publisher: AnyCancellable?

init(event: DataSource.Event) {
Expand All @@ -142,17 +167,21 @@ class DetailViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.systemBackground
if #available(iOS 13.0, *) {
view.backgroundColor = UIColor.systemBackground
}

view.addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFill

imageView.addSubview(label)
label.backgroundColor = UIColor.systemBackground
if #available(iOS 13.0, *) {
label.backgroundColor = UIColor.systemBackground
label.textColor = UIColor.secondaryLabel
}
label.text = event.name
label.numberOfLines = 0
label.textColor = UIColor.secondaryLabel
label.textAlignment = .center
label.translatesAutoresizingMaskIntoConstraints = false

Expand All @@ -178,12 +207,26 @@ class DetailViewController: UIViewController {
guard let url = URL(string: event.image_url ?? "") else {
return
}
publisher = URLSession.shared.dataTaskPublisher(for: url)
.receive(on: RunLoop.main)
.map { UIImage(data: $0.data) }
.sink(receiveCompletion: { _ in }, receiveValue: {[weak self] image in
guard let self = self else { return }
self.imageView.image = image
})
if #available(iOS 13.0, *) {
publisher = URLSession.shared.dataTaskPublisher(for: url)
.receive(on: RunLoop.main)
.map { UIImage(data: $0.data) }
.sink(receiveCompletion: { _ in }, receiveValue: {[weak self] image in
guard let self = self else { return }
self.imageView.image = image
})
} else {
let task = URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data else {
print("Empty data. error: ", error ?? "nil")
return
}
let image = UIImage(data: data)
DispatchQueue.main.async {
self.imageView.image = image
}
}
task.resume()
}
}
}
27 changes: 22 additions & 5 deletions Dev/InstanaAgentExample/ImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class ImageViewViewController: UIViewController {

lazy var imageView = UIImageView()
lazy var session = { URLSession(configuration: URLSessionConfiguration.default) }()

@available(iOS 13.0, *)
private var publisher: AnyCancellable?

private var timer: Timer?

override func viewDidLoad() {
Expand Down Expand Up @@ -55,11 +58,25 @@ class ImageViewViewController: UIViewController {
}

func downloadViaCombine(_ url: URL) {
publisher = session.dataTaskPublisher(for: url)
.receive(on: RunLoop.main)
.map { UIImage(data: $0.data) }
.replaceError(with: UIImage())
.assign(to: \.image, on: self.imageView)
if #available(iOS 13.0, *) {
publisher = session.dataTaskPublisher(for: url)
.receive(on: RunLoop.main)
.map { UIImage(data: $0.data) }
.replaceError(with: UIImage())
.assign(to: \.image, on: self.imageView)
} else {
let task = session.dataTask(with: url) { data, response, error in
guard let data = data else {
print("Empty data. error: ", error ?? "nil")
return
}
let image = UIImage(data: data)
DispatchQueue.main.async {
self.imageView.image = image
}
}
task.resume()
}
}

func downloadWViaAFN(_ url: URL) {
Expand Down
36 changes: 27 additions & 9 deletions Dev/InstanaAgentExample/JSONViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ class JSONViewController: UIViewController {

@IBOutlet var searchTextField: UITextField!
@IBOutlet var textView: UITextView!

@available(iOS 13.0, *)
private var publisher: AnyCancellable?

lazy var session = { URLSession(configuration: URLSessionConfiguration.default) }()

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Instana.setView(name: "JSONView")
searchTextField.text = "https://www.ibm.com/de-de"
}

@IBAction func loadJSON() {
Expand All @@ -27,16 +31,30 @@ class JSONViewController: UIViewController {
showAlert(message: "URL is invalid")
return
}
publisher = session.dataTaskPublisher(for: url)
.receive(on: RunLoop.main)
.map { String(data: $0.data, encoding: .ascii) }
.sink(receiveCompletion: { complete in
if let errorMessage = complete.localizedError {
self.showAlert(message: errorMessage)
if #available(iOS 13.0, *) {
publisher = session.dataTaskPublisher(for: url)
.receive(on: RunLoop.main)
.map { String(data: $0.data, encoding: .ascii) }
.sink(receiveCompletion: { complete in
if let errorMessage = complete.localizedError {
self.showAlert(message: errorMessage)
}
}, receiveValue: {[weak self] result in
self?.textView.text = result
})
} else {
let task = session.dataTask(with: url) { data, response, error in
guard let data = data else {
print("Empty data. error: ", error ?? "nil")
return
}
}, receiveValue: {[weak self] result in
self?.textView.text = result
})
let str = String(data: data, encoding: .utf8)
DispatchQueue.main.async {
self.textView.text = str
}
}
task.resume()
}
}

func showAlert(message: String) {
Expand Down
2 changes: 1 addition & 1 deletion Dev/InstanaAgentExample/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WebViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
webView.navigationDelegate = self
load(url: URL(string: "https://www.instana.com")!)
load(url: URL(string: "https://www.ibm.com/cn-zh")!)
}

func load(url: URL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class InstanaPersistableQueueTests: InstanaTestCase {
// Given
let sessionID = UUID()
let id = UUID()
let userSessionID = UUID()
let beacon1 = CoreBeacon.createDefault(viewName: "View_1", key: "Key_1", timestamp: 0,
sid: sessionID, usi: session.usi, id: id, mobileFeatures: "c")
let beacon2 = CoreBeacon.createDefault(viewName: "View_2", key: "Key_2", timestamp: 0,
Expand Down

0 comments on commit 4436b56

Please sign in to comment.