Skip to content

Commit 4436b56

Browse files
Hongyan JiangGitHub Enterprise
authored andcommitted
fix InstanaExample issues on iOS 12
1 parent 0ea9f54 commit 4436b56

File tree

6 files changed

+130
-42
lines changed

6 files changed

+130
-42
lines changed

Dev/InstanaAgentExample.xcodeproj/project.pbxproj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 52;
6+
objectVersion = 54;
77
objects = {
88

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

@@ -69,6 +70,7 @@
6970
727AF73A263AA0FA00B9C59B /* EventListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventListViewController.swift; sourceTree = "<group>"; };
7071
72976A992681C45800A284F6 /* Webserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Webserver.swift; path = "../../Tests/InstanaAgentTests/Test helpers/Webserver.swift"; sourceTree = "<group>"; };
7172
72FBE8A7263AACDB00CF2CDE /* InstanaAgentExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = InstanaAgentExample.entitlements; sourceTree = "<group>"; };
73+
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; };
7274
CE322E482A6E3CEF00414F37 /* TopRatedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopRatedViewController.swift; sourceTree = "<group>"; };
7375
/* End PBXFileReference section */
7476

@@ -85,6 +87,7 @@
8587
isa = PBXFrameworksBuildPhase;
8688
buildActionMask = 2147483647;
8789
files = (
90+
A4EFD6A12A9983FB00B9A9A3 /* WebKit.framework in Frameworks */,
8891
729C88B8270DF13700492486 /* Alamofire in Frameworks */,
8992
727AF748263AA16A00B9C59B /* InstanaAgent in Frameworks */,
9093
729C88B5270DE98200492486 /* AFNetworking in Frameworks */,
@@ -160,6 +163,7 @@
160163
727AF710263A9FC800B9C59B /* Frameworks */ = {
161164
isa = PBXGroup;
162165
children = (
166+
A4EFD6A02A9983FB00B9A9A3 /* WebKit.framework */,
163167
);
164168
name = Frameworks;
165169
sourceTree = "<group>";
@@ -355,6 +359,7 @@
355359
};
356360
72FBE8AC263AAD0900CF2CDE /* Import secure variables */ = {
357361
isa = PBXShellScriptBuildPhase;
362+
alwaysOutOfDate = 1;
358363
buildActionMask = 2147483647;
359364
files = (
360365
);
@@ -373,6 +378,7 @@
373378
};
374379
72FBE8AD263AAD2000CF2CDE /* SwiftLint & SwiftFormat */ = {
375380
isa = PBXShellScriptBuildPhase;
381+
alwaysOutOfDate = 1;
376382
buildActionMask = 2147483647;
377383
files = (
378384
);
@@ -391,6 +397,7 @@
391397
};
392398
72FBE8AE263AAD4C00CF2CDE /* Reset */ = {
393399
isa = PBXShellScriptBuildPhase;
400+
alwaysOutOfDate = 1;
394401
buildActionMask = 2147483647;
395402
files = (
396403
);
@@ -650,8 +657,9 @@
650657
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
651658
CODE_SIGN_ENTITLEMENTS = InstanaAgentExample/InstanaAgentExample.entitlements;
652659
CODE_SIGN_STYLE = Automatic;
653-
DEVELOPMENT_TEAM = D5PCJAP39R;
660+
DEVELOPMENT_TEAM = 6K4C9F3Z9X;
654661
INFOPLIST_FILE = InstanaAgentExample/Info.plist;
662+
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
655663
LD_RUNPATH_SEARCH_PATHS = (
656664
"$(inherited)",
657665
"@executable_path/Frameworks",
@@ -671,8 +679,9 @@
671679
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
672680
CODE_SIGN_ENTITLEMENTS = InstanaAgentExample/InstanaAgentExample.entitlements;
673681
CODE_SIGN_STYLE = Automatic;
674-
DEVELOPMENT_TEAM = D5PCJAP39R;
682+
DEVELOPMENT_TEAM = 6K4C9F3Z9X;
675683
INFOPLIST_FILE = InstanaAgentExample/Info.plist;
684+
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
676685
LD_RUNPATH_SEARCH_PATHS = (
677686
"$(inherited)",
678687
"@executable_path/Frameworks",
@@ -690,6 +699,7 @@
690699
buildSettings = {
691700
CODE_SIGN_STYLE = Automatic;
692701
INFOPLIST_FILE = iOSAgentUITests/Info.plist;
702+
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
693703
LD_RUNPATH_SEARCH_PATHS = (
694704
"$(inherited)",
695705
"@executable_path/Frameworks",
@@ -708,6 +718,7 @@
708718
buildSettings = {
709719
CODE_SIGN_STYLE = Automatic;
710720
INFOPLIST_FILE = iOSAgentUITests/Info.plist;
721+
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
711722
LD_RUNPATH_SEARCH_PATHS = (
712723
"$(inherited)",
713724
"@executable_path/Frameworks",

Dev/InstanaAgentExample/EventListViewController.swift

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ class EventListViewController: UITableViewController {
2828

2929
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
3030
super.init(style: style, reuseIdentifier: reuseIdentifier)
31-
32-
rateButton.setImage(UIImage(systemName: "star"), for: .normal)
33-
rateButton.setImage(UIImage(systemName: "star.fill"), for: .selected)
31+
if #available(iOS 13.0, *) {
32+
rateButton.setImage(UIImage(systemName: "star"), for: .normal)
33+
rateButton.setImage(UIImage(systemName: "star.fill"), for: .selected)
34+
}
3435
accessoryView = rateButton
3536
}
3637

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

4849

4950

51+
@available(iOS 13.0, *)
5052
private var publisher: AnyCancellable?
53+
5154
lazy var session = { URLSession(configuration: URLSessionConfiguration.default) }()
5255

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

7174
func loadJSON() {
7275
let url = URL(string: "https://api.mygigs.tapwork.de/eventsnearby?radius=80.0&latitude=52.52&longitude=13.410&apitoken=xQ3vdfKVIF")!
73-
publisher = session.dataTaskPublisher(for: url)
74-
.receive(on: RunLoop.main)
75-
.map { $0.data }
76-
.decode(type: DataSource.self, decoder: JSONDecoder())
77-
.sink(receiveCompletion: { _ in }, receiveValue: {[weak self] model in
78-
guard let self = self else { return }
79-
dataSource = model
80-
self.tableView.reloadData()
81-
self.refreshControl?.endRefreshing()
82-
})
76+
if #available(iOS 13.0, *) {
77+
publisher = session.dataTaskPublisher(for: url)
78+
.receive(on: RunLoop.main)
79+
.map { $0.data }
80+
.decode(type: DataSource.self, decoder: JSONDecoder())
81+
.sink(receiveCompletion: { _ in }, receiveValue: {[weak self] model in
82+
guard let self = self else { return }
83+
dataSource = model
84+
self.tableView.reloadData()
85+
self.refreshControl?.endRefreshing()
86+
})
87+
} else {
88+
let task = session.dataTask(with: url) { data, response, error in
89+
guard let data = data else {
90+
print("Empty data. error: ", error ?? "nil")
91+
return
92+
}
93+
do {
94+
let model: DataSource? = try JSONDecoder().decode(DataSource.self, from: data)
95+
DispatchQueue.main.async {
96+
dataSource = model
97+
self.tableView.reloadData()
98+
self.refreshControl?.endRefreshing()
99+
}
100+
} catch {
101+
print("Error ", error)
102+
}
103+
}
104+
task.resume()
105+
}
83106
}
84107

85108
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@@ -128,6 +151,8 @@ class DetailViewController: UIViewController {
128151
let label = UILabel()
129152
let imageView = UIImageView()
130153
let event: DataSource.Event
154+
155+
@available(iOS 13.0, *)
131156
private var publisher: AnyCancellable?
132157

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

145-
view.backgroundColor = UIColor.systemBackground
170+
if #available(iOS 13.0, *) {
171+
view.backgroundColor = UIColor.systemBackground
172+
}
146173

147174
view.addSubview(imageView)
148175
imageView.translatesAutoresizingMaskIntoConstraints = false
149176
imageView.contentMode = .scaleAspectFill
150177

151178
imageView.addSubview(label)
152-
label.backgroundColor = UIColor.systemBackground
179+
if #available(iOS 13.0, *) {
180+
label.backgroundColor = UIColor.systemBackground
181+
label.textColor = UIColor.secondaryLabel
182+
}
153183
label.text = event.name
154184
label.numberOfLines = 0
155-
label.textColor = UIColor.secondaryLabel
156185
label.textAlignment = .center
157186
label.translatesAutoresizingMaskIntoConstraints = false
158187

@@ -178,12 +207,26 @@ class DetailViewController: UIViewController {
178207
guard let url = URL(string: event.image_url ?? "") else {
179208
return
180209
}
181-
publisher = URLSession.shared.dataTaskPublisher(for: url)
182-
.receive(on: RunLoop.main)
183-
.map { UIImage(data: $0.data) }
184-
.sink(receiveCompletion: { _ in }, receiveValue: {[weak self] image in
185-
guard let self = self else { return }
186-
self.imageView.image = image
187-
})
210+
if #available(iOS 13.0, *) {
211+
publisher = URLSession.shared.dataTaskPublisher(for: url)
212+
.receive(on: RunLoop.main)
213+
.map { UIImage(data: $0.data) }
214+
.sink(receiveCompletion: { _ in }, receiveValue: {[weak self] image in
215+
guard let self = self else { return }
216+
self.imageView.image = image
217+
})
218+
} else {
219+
let task = URLSession.shared.dataTask(with: url) { data, response, error in
220+
guard let data = data else {
221+
print("Empty data. error: ", error ?? "nil")
222+
return
223+
}
224+
let image = UIImage(data: data)
225+
DispatchQueue.main.async {
226+
self.imageView.image = image
227+
}
228+
}
229+
task.resume()
230+
}
188231
}
189232
}

Dev/InstanaAgentExample/ImageViewController.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class ImageViewViewController: UIViewController {
1515

1616
lazy var imageView = UIImageView()
1717
lazy var session = { URLSession(configuration: URLSessionConfiguration.default) }()
18+
19+
@available(iOS 13.0, *)
1820
private var publisher: AnyCancellable?
21+
1922
private var timer: Timer?
2023

2124
override func viewDidLoad() {
@@ -55,11 +58,25 @@ class ImageViewViewController: UIViewController {
5558
}
5659

5760
func downloadViaCombine(_ url: URL) {
58-
publisher = session.dataTaskPublisher(for: url)
59-
.receive(on: RunLoop.main)
60-
.map { UIImage(data: $0.data) }
61-
.replaceError(with: UIImage())
62-
.assign(to: \.image, on: self.imageView)
61+
if #available(iOS 13.0, *) {
62+
publisher = session.dataTaskPublisher(for: url)
63+
.receive(on: RunLoop.main)
64+
.map { UIImage(data: $0.data) }
65+
.replaceError(with: UIImage())
66+
.assign(to: \.image, on: self.imageView)
67+
} else {
68+
let task = session.dataTask(with: url) { data, response, error in
69+
guard let data = data else {
70+
print("Empty data. error: ", error ?? "nil")
71+
return
72+
}
73+
let image = UIImage(data: data)
74+
DispatchQueue.main.async {
75+
self.imageView.image = image
76+
}
77+
}
78+
task.resume()
79+
}
6380
}
6481

6582
func downloadWViaAFN(_ url: URL) {

Dev/InstanaAgentExample/JSONViewController.swift

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ class JSONViewController: UIViewController {
1313

1414
@IBOutlet var searchTextField: UITextField!
1515
@IBOutlet var textView: UITextView!
16+
17+
@available(iOS 13.0, *)
1618
private var publisher: AnyCancellable?
19+
1720
lazy var session = { URLSession(configuration: URLSessionConfiguration.default) }()
1821

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

2428
@IBAction func loadJSON() {
@@ -27,16 +31,30 @@ class JSONViewController: UIViewController {
2731
showAlert(message: "URL is invalid")
2832
return
2933
}
30-
publisher = session.dataTaskPublisher(for: url)
31-
.receive(on: RunLoop.main)
32-
.map { String(data: $0.data, encoding: .ascii) }
33-
.sink(receiveCompletion: { complete in
34-
if let errorMessage = complete.localizedError {
35-
self.showAlert(message: errorMessage)
34+
if #available(iOS 13.0, *) {
35+
publisher = session.dataTaskPublisher(for: url)
36+
.receive(on: RunLoop.main)
37+
.map { String(data: $0.data, encoding: .ascii) }
38+
.sink(receiveCompletion: { complete in
39+
if let errorMessage = complete.localizedError {
40+
self.showAlert(message: errorMessage)
41+
}
42+
}, receiveValue: {[weak self] result in
43+
self?.textView.text = result
44+
})
45+
} else {
46+
let task = session.dataTask(with: url) { data, response, error in
47+
guard let data = data else {
48+
print("Empty data. error: ", error ?? "nil")
49+
return
3650
}
37-
}, receiveValue: {[weak self] result in
38-
self?.textView.text = result
39-
})
51+
let str = String(data: data, encoding: .utf8)
52+
DispatchQueue.main.async {
53+
self.textView.text = str
54+
}
55+
}
56+
task.resume()
57+
}
4058
}
4159

4260
func showAlert(message: String) {

Dev/InstanaAgentExample/WebViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class WebViewController: UIViewController {
1616
override func viewDidLoad() {
1717
super.viewDidLoad()
1818
webView.navigationDelegate = self
19-
load(url: URL(string: "https://www.instana.com")!)
19+
load(url: URL(string: "https://www.ibm.com/cn-zh")!)
2020
}
2121

2222
func load(url: URL) {

Tests/InstanaAgentTests/Utils_Tests/InstanaPersistableQueueTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class InstanaPersistableQueueTests: InstanaTestCase {
4848
// Given
4949
let sessionID = UUID()
5050
let id = UUID()
51-
let userSessionID = UUID()
5251
let beacon1 = CoreBeacon.createDefault(viewName: "View_1", key: "Key_1", timestamp: 0,
5352
sid: sessionID, usi: session.usi, id: id, mobileFeatures: "c")
5453
let beacon2 = CoreBeacon.createDefault(viewName: "View_2", key: "Key_2", timestamp: 0,

0 commit comments

Comments
 (0)