diff --git a/Datadog/Datadog.xcodeproj/project.pbxproj b/Datadog/Datadog.xcodeproj/project.pbxproj index 38fd4a9511..39104df47e 100644 --- a/Datadog/Datadog.xcodeproj/project.pbxproj +++ b/Datadog/Datadog.xcodeproj/project.pbxproj @@ -266,6 +266,7 @@ 617B954224BF4E7600E6F443 /* RUMMonitorConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617B954124BF4E7600E6F443 /* RUMMonitorConfigurationTests.swift */; }; 617CD0DD24CEDDD300B0B557 /* RUMUserActionScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617CD0DC24CEDDD300B0B557 /* RUMUserActionScopeTests.swift */; }; 617CEB392456BC3A00AD4669 /* TracingUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617CEB382456BC3A00AD4669 /* TracingUUID.swift */; }; + 618236892710560900125326 /* DebugWebviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618236882710560900125326 /* DebugWebviewViewController.swift */; }; 6182374325D3DFD5006A375B /* CrashReportingWithRUMIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6182374225D3DFD5006A375B /* CrashReportingWithRUMIntegrationTests.swift */; }; 6184751526EFCF1300C7C9C5 /* DatadogTestsObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6184751426EFCF1300C7C9C5 /* DatadogTestsObserver.swift */; }; 6184751826EFD03400C7C9C5 /* DatadogTestsObserverLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6184751726EFD03400C7C9C5 /* DatadogTestsObserverLoader.m */; }; @@ -909,6 +910,7 @@ 617B954124BF4E7600E6F443 /* RUMMonitorConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMMonitorConfigurationTests.swift; sourceTree = ""; }; 617CD0DC24CEDDD300B0B557 /* RUMUserActionScopeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMUserActionScopeTests.swift; sourceTree = ""; }; 617CEB382456BC3A00AD4669 /* TracingUUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingUUID.swift; sourceTree = ""; }; + 618236882710560900125326 /* DebugWebviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugWebviewViewController.swift; sourceTree = ""; }; 6182374225D3DFD5006A375B /* CrashReportingWithRUMIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashReportingWithRUMIntegrationTests.swift; sourceTree = ""; }; 6184751426EFCF1300C7C9C5 /* DatadogTestsObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatadogTestsObserver.swift; sourceTree = ""; }; 6184751726EFD03400C7C9C5 /* DatadogTestsObserverLoader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DatadogTestsObserverLoader.m; sourceTree = ""; }; @@ -2206,6 +2208,7 @@ 61441C932461A649003D8BB8 /* DebugTracingViewController.swift */, 61E5333724B84EE2003D6C4E /* DebugRUMViewController.swift */, 61F74AF326F20E4600E5F5ED /* DebugCrashReportingWithRUMViewController.swift */, + 618236882710560900125326 /* DebugWebviewViewController.swift */, ); path = Debugging; sourceTree = ""; @@ -4165,6 +4168,7 @@ 61163C37252DDD60007DD5BF /* RUMMVSViewController.swift in Sources */, 61441C952461A649003D8BB8 /* ConsoleOutputInterceptor.swift in Sources */, 61D50C5A2580EFF3006038A3 /* URLSessionScenarios.swift in Sources */, + 618236892710560900125326 /* DebugWebviewViewController.swift in Sources */, 614CADCE250FCA0200B93D2D /* TestScenarios.swift in Sources */, 6111542525C992F8007C84C9 /* CrashReportingScenarios.swift in Sources */, 61F74AF426F20E4600E5F5ED /* DebugCrashReportingWithRUMViewController.swift in Sources */, diff --git a/Datadog/Example/Base.lproj/Main.storyboard b/Datadog/Example/Base.lproj/Main.storyboard index da6c479f16..7be1531e1c 100644 --- a/Datadog/Example/Base.lproj/Main.storyboard +++ b/Datadog/Example/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -18,7 +18,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -66,7 +66,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -105,6 +105,26 @@ + + + + + + + + + + + + + + @@ -764,7 +784,6 @@ - @@ -811,7 +830,6 @@ - @@ -840,7 +858,7 @@ - + @@ -1309,6 +1327,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Datadog/Example/Debugging/DebugWebviewViewController.swift b/Datadog/Example/Debugging/DebugWebviewViewController.swift new file mode 100644 index 0000000000..220160726b --- /dev/null +++ b/Datadog/Example/Debugging/DebugWebviewViewController.swift @@ -0,0 +1,109 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-2020 Datadog, Inc. + */ + +import UIKit +import Datadog +import WebKit + +class DebugWebviewViewController: UIViewController { + @IBOutlet weak var rumServiceNameTextField: UITextField! + + /// When `true`, a native RUM Session between `DebugWebviewViewController` and `WebviewViewController` will be tracked. + private var useNativeRUMSession = false + + override func viewDidLoad() { + super.viewDidLoad() + rumServiceNameTextField.text = (appConfiguration as? ExampleAppConfiguration)?.serviceName + + webviewURLTextField.placeholder = webviewURL + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + if useNativeRUMSession { + Global.rum.startView(viewController: self) + } + } + + override func viewDidDisappear(_ animated: Bool) { + if useNativeRUMSession { + Global.rum.stopView(viewController: self) + } + } + + // MARK: - Starting native RUM session + + @IBAction func didTapStartNativeRUMSession(_ sender: Any) { + useNativeRUMSession = true + Global.rum.startView(viewController: self) + } + + // MARK: - Starting webview + + @IBOutlet weak var webviewURLTextField: UITextField! + + private var webviewURL: String { + guard let text = webviewURLTextField.text, !text.isEmpty else { + return "https://www.datadoghq.com" + } + return text + } + + @IBAction func didTapOpenURLInWebview(_ sender: Any) { + if let url = URL(string: webviewURL), url.scheme != nil, url.host != nil { // basic validation + webviewURLTextField.textColor = .black + let webviewVC = WebviewViewController() + + webviewVC.request = URLRequest( + url: url, + cachePolicy: .reloadIgnoringLocalCacheData // no cache + ) + webviewVC.navigationItem.title = "\(url.absoluteString)" + webviewVC.useNativeRUMSession = useNativeRUMSession + + show(webviewVC, sender: nil) + } else { + webviewURLTextField.textColor = .red + } + } +} + +// MARK: - Webview view controller + +class WebviewViewController: UIViewController { + /// The request to load in webview + var request: URLRequest! + /// When `true`, a native RUM Session between `DebugWebviewViewController` and `WebviewViewController` will be tracked. + var useNativeRUMSession: Bool! + + private var webView: WKWebView! + + override func viewDidLoad() { + super.viewDidLoad() + + let configuration = WKWebViewConfiguration() + webView = WKWebView(frame: UIScreen.main.bounds, configuration: configuration) + view.addSubview(webView) + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + webView.load(request) + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + if useNativeRUMSession { + Global.rum.startView(viewController: self) + } + } + + override func viewDidDisappear(_ animated: Bool) { + if useNativeRUMSession { + Global.rum.stopView(viewController: self) + } + } +}