error 1009 on Apple Watch when I used URLSession

118 views Asked by At

I have the error 1009 "it seems network was disconnected" when I used URLSession.shard.data(from: URL) on my Apple Watch S7(watchOS9.1_20S75), no cellar edition but really connected to wi-fi.

I have committed a Technical Support Incident (TSI), and replied by Quinn “The Eskimo!” (Apple Developer Relations, Developer Technical Support, Core OS/Hardware) He gave me an example project that works on his own device in his office, this is the code, but the project really not works on my watch!

import SwiftUI

struct ContentView: View {
    @State private var dataStr: String = "..."

    var body: some View {
        Button("start") {
            Task {
                do {
                    dataStr = "..."
                    let (data, response) = try await URLSession.shared.data(from: URL(string: "https://www.baidu.com")!)
                    let httpResponse = response as! HTTPURLResponse
                    dataStr = "status: \(httpResponse.statusCode), count: \(data.count)"
                } catch {
                    dataStr = error.localizedDescription.description
                }
            }
        }
        Text(dataStr)
    }
}

I guess that it's the local wi-fi configuration that makes our difference, I even failed to visit the local http server with http://(myMacIpInTheSameLocalNetwork) when I open "Allow Arbitrary Loads" Setting.

It frustrated me, that means I have to think it's the only solution I can adapt to use Bonjour Service just like the TicTacToe sample project provided by Apple Development Document, when my watch needs to communicate with other device nearby.

However, I realized that some standalone watch apps like uBrowser could work successfully on my watch under my wi-fi environment! Could any one tell me how to make it?

0

There are 0 answers