cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iOS Web Requests : is async / await supported?

Kanduvisla
Newcomer

I'm just dipping my toes in Dynatrance, and I'm wondering if what I am observing is expected behaviour, a misconfiguration from my side, or... a bug?

Basically I'm testing to see if web requests are being logged to Dynatrace, and I noticed that if I do a network call with a completion handler it shows up in the dashboard, but if I use async / await it does not. Code samples:

 

 

 

    /// Do a network call "the traditional way"
    private func doWebRequest() {
        isLoading = true
        let task = URLSession.shared.dataTask(
            with: URLRequest(url: URL(string: "https://www.example.com/nl")!),
            completionHandler: { data, response, error in
                if let response = response as? HTTPURLResponse {
                    print("Got response with status code \(response.statusCode)")
                    print("Expected content length: \(response.expectedContentLength)")
                }
                isLoading = false
            }
        )
        task.resume()
    }
    
    /// Do a network call using async / await
    private func doWebRequest() async {
        isLoading = true
        do {
            let (_, response) = try await URLSession.shared.data(
                for: URLRequest(url: URL(string: "https://www.example.com/en")!)
            )
            if let response = response as? HTTPURLResponse {
                print("Got response with status code \(response.statusCode)")
                print("Expected content length: \(response.expectedContentLength)")
            }
            isLoading = false
        } catch {
            isLoading = false
        }
    }

 

 

 

The first example gets logged (the /nl/) call, but the second doesn't (/en/).

Any thoughts on this?

1 REPLY 1

Patrick_H
Dynatrace Champion
Dynatrace Champion

This seems to be the same as this RFE: Add support for Swift Concurrency

iOS help: https://www.dynatrace.com/support/help/shortlink/ios-hub

Featured Posts