Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Dev/iOSAgentExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
72109EBF23E178EC00441D87 /* iosAgent */ = {isa = PBXFileReference; lastKnownFileType = folder; name = iosAgent; path = ..; sourceTree = "<group>"; };
7247F62523E200970064CA8D /* Webserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Webserver.swift; path = ../../tools/Webserver/Webserver.swift; sourceTree = "<group>"; };
728CF9DB2387F01200BEE2F9 /* iOSAgentExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSAgentExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
72B5BA7A249A98BD00B7F261 /* iOSAgentExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = iOSAgentExample.entitlements; sourceTree = "<group>"; };
72C7A9D723E049FF00041782 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
72C7A9D823E049FF00041782 /* JSONViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONViewController.swift; sourceTree = "<group>"; };
72C7A9D923E049FF00041782 /* Icon.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Icon.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -103,6 +104,7 @@
72C7A9D623E049FF00041782 /* iOSAgentExample */ = {
isa = PBXGroup;
children = (
72B5BA7A249A98BD00B7F261 /* iOSAgentExample.entitlements */,
72C7A9D723E049FF00041782 /* ViewController.swift */,
72C7A9D823E049FF00041782 /* JSONViewController.swift */,
72C7A9D923E049FF00041782 /* Icon.xcassets */,
Expand Down Expand Up @@ -471,6 +473,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
CODE_SIGN_ENTITLEMENTS = iOSAgentExample/iOSAgentExample.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1578416283;
Expand All @@ -484,6 +487,7 @@
PRODUCT_BUNDLE_IDENTIFIER = net.tapwork.instana.sdkexample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -494,6 +498,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
CODE_SIGN_ENTITLEMENTS = iOSAgentExample/iOSAgentExample.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1578416283;
Expand All @@ -507,6 +512,7 @@
PRODUCT_BUNDLE_IDENTIFIER = net.tapwork.instana.sdkexample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "Instana Demo Project";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
2 changes: 1 addition & 1 deletion Dev/iOSAgentExample/ImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ImageViewViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Instana.setView(name: "ImageView")
Instana.reportEvent(name: "Custom Event", duration: 1001, backendTracingID: nil, error: NSError(domain: "Domain", code: 0, userInfo: nil), meta: ["Key": "Val"], viewName:"Image")
Instana.reportEvent(name: "Custom Event", duration: "1001", backendTracingID: nil, error: NSError(domain: "Domain", code: 0, userInfo: nil), meta: ["Key": "Val"], viewName:"Image")
}

@objc func downloadImage() {
Expand Down
10 changes: 10 additions & 0 deletions Dev/iOSAgentExample/iOSAgentExample.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Sources/InstanaAgent/Beacons/Reporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Reporter {

init(_ session: InstanaSession,
batterySafeForNetworking: @escaping () -> Bool = { InstanaSystemUtils.battery.safeForNetworking },
networkUtility: NetworkUtility = NetworkUtility(),
networkUtility: NetworkUtility = NetworkUtility.shared,
queue: InstanaPersistableQueue<CoreBeacon>? = nil,
send: @escaping NetworkLoader = InstanaNetworking().send(request:completion:)) {
self.networkUtility = networkUtility
Expand Down
5 changes: 3 additions & 2 deletions Sources/InstanaAgent/Monitors/HTTP/HTTPMarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ extension HTTPMarker {

internal convenience init(_ response: URLResponse) {
var headerBytes: Instana.Types.Bytes = 0
if let headerFields = (response as? HTTPURLResponse)?.allHeaderFields {
headerBytes = Instana.Types.Bytes(NSKeyedArchiver.archivedData(withRootObject: headerFields).count)
if let headerFields = (response as? HTTPURLResponse)?.allHeaderFields,
let data = try? NSKeyedArchiver.archivedData(withRootObject: headerFields, requiringSecureCoding: false) {
headerBytes = Instana.Types.Bytes(data.count)
}
self.init(header: headerBytes, body: response.expectedContentLength, bodyAfterDecoding: 0)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/InstanaAgent/Utils/InstanaSystemUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class InstanaSystemUtils {
return identifier
}()

static var networkUtility = { NetworkUtility() }()
static var networkUtility = { NetworkUtility.shared }()

/// Returns iOS version (for ex. "12.1")
static var systemVersion: String = { UIDevice.current.systemVersion }()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class NetworkUtility {
}

var connectionUpdateHandler: (ConnectionType) -> Void = { _ in }

private let reachability: Reachability?

static let shared = NetworkUtility()

init(reachability: Reachability? = nil) {
let reachability = reachability ?? (try? Reachability())
self.reachability = reachability
Expand All @@ -37,6 +38,19 @@ class NetworkUtility {
}

extension NetworkUtility {
enum ConnectionType: String, CustomStringConvertible {
case undetermined, none, wifi, cellular
var cellular: CellularType { CellularType.current }
var description: String {
switch self {
case .none: return "None"
case .wifi: return "Wifi"
case .cellular: return CellularType.current.rawValue
case .undetermined: return "Unknown"
}
}
}

enum CellularType: String {
case none, twoG, threeG, fourG, unknown
var rawValue: String {
Expand All @@ -50,53 +64,48 @@ extension NetworkUtility {
}

var carrierName: String {
var name = "None"
if ProcessInfo.isRunningDebugSessionSimulator {
return "Simulator"
name = "Simulator"
} else {
let networkInfo = CTTelephonyNetworkInfo()
let carrier = networkInfo.subscriberCellularProvider
return carrier?.carrierName ?? "None"
#if os(iOS) && !targetEnvironment(macCatalyst)
let networkInfo = CTTelephonyNetworkInfo()
let carrier = networkInfo.subscriberCellularProvider
name = carrier?.carrierName ?? name
#endif
}
return name
}

static var current: CellularType {
if ProcessInfo.isRunningDebugSessionSimulator {
return .none
} else {
guard let radioAccessTechnology = CTTelephonyNetworkInfo().currentRadioAccessTechnology else {
#if os(iOS) && !targetEnvironment(macCatalyst)
guard let radioAccessTechnology = CTTelephonyNetworkInfo().currentRadioAccessTechnology else {
return .none
}
switch radioAccessTechnology {
case CTRadioAccessTechnologyGPRS,
CTRadioAccessTechnologyEdge,
CTRadioAccessTechnologyCDMA1x:
return .twoG
case CTRadioAccessTechnologyWCDMA,
CTRadioAccessTechnologyHSDPA,
CTRadioAccessTechnologyHSUPA,
CTRadioAccessTechnologyCDMAEVDORev0,
CTRadioAccessTechnologyCDMAEVDORevA,
CTRadioAccessTechnologyCDMAEVDORevB,
CTRadioAccessTechnologyeHRPD:
return .threeG
case CTRadioAccessTechnologyLTE:
return .fourG
default:
return .unknown
}
#else
return .none
}
switch radioAccessTechnology {
case CTRadioAccessTechnologyGPRS,
CTRadioAccessTechnologyEdge,
CTRadioAccessTechnologyCDMA1x:
return .twoG
case CTRadioAccessTechnologyWCDMA,
CTRadioAccessTechnologyHSDPA,
CTRadioAccessTechnologyHSUPA,
CTRadioAccessTechnologyCDMAEVDORev0,
CTRadioAccessTechnologyCDMAEVDORevA,
CTRadioAccessTechnologyCDMAEVDORevB,
CTRadioAccessTechnologyeHRPD:
return .threeG
case CTRadioAccessTechnologyLTE:
return .fourG
default:
return .unknown
}
}
}
}

enum ConnectionType: String, CustomStringConvertible {
case undetermined, none, wifi, cellular
var cellular: CellularType { CellularType.current }
var description: String {
switch self {
case .none: return "None"
case .wifi: return "Wifi"
case .cellular: return CellularType.current.rawValue
case .undetermined: return "Unknown"
#endif
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public enum ReachabilityError: Error {
}

@available(*, unavailable, renamed: "Notification.Name.reachabilityChanged")
public let ReachabilityChangedNotification = NSNotification.Name("ReachabilityChangedNotification")
public let reachabilityChangedNotification = NSNotification.Name("ReachabilityChangedNotification")

public extension Notification.Name {
static let reachabilityChanged = Notification.Name("reachabilityChanged")
Expand Down Expand Up @@ -277,6 +277,8 @@ private extension Reachability {
}
}

// swiftlint:disable identifier_name

extension SCNetworkReachabilityFlags {
typealias Connection = Reachability.Connection

Expand Down