Networking error on Independent Apple Watch Apps

I created a project with "watch-only App" template in XCode, running on Apple Watch Series 6, the console output network error: ErrorDomain =NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." However, It works fine on the Apple watch Ultra. I try the following:

  1. I added the following code, but doesn't work.
configuration.allowsCellularAccess = true
configuration.waitsForConnectivity = true
  1. Tried using the Alamofire framework, but it didn't work.
import Alamofire
var body: some View {
        VStack {
            Text("hello world")
                .task {
                    URLCache.shared.removeAllCachedResponses()
                    AF.request("https://api.thecatapi.com/v1/images/search?limit=1").response { response in print( response)
                    }
                }
        }
}
  1. Turn off the Wi-Fi and Bluetooth of the mobile phone. The Watch Series 6 can successfully request through Wi-Fi. But that's not an option. I can't ask my users to turn off Wi-Fi and Bluetooth before using my app.

Here is my code:

VStack {
      Text("hello world") 
}
.onAppear {
            guard let url = URL(string: "https://api.thecatapi.com/v1/images/search?limit=1") else {
                print("Invalid URL")
                self.error = "Invalid URL"
                return
            }
            let dataTask = URLSession.shared.dataTask(with: url) {(data, response, error) in

                guard error == nil else {
                    print(error)
                    return
                }

                print(data)
            }
            dataTask.resume()
}

What can I do? My Apple Watch Series 6 version is watchOS 9.0. I noticed when lauching my app first time on the Apple Watch Series 6. It doesn't ask for 'allow "Settings" to use wireless data’.But I was asked about it on the Apple Watch Ultra.

Your watchOS app should be able to use networking resources from the tethered iOS device. As a first step I would try the HTTP request and if it fails then the first things I would do in your app is let the user know what is happening so they can do some more investigation on their end.

Also, make sure that when you are testing your networking code on watchOS that Wi-Fi and Bluetooth are enabled from the iOS Control Center. See the difference from turning this off in Control Center compared to Settings here.

This is not a user device issue. I have checked other apps and tested that other apps can use the Internet over wireless networks. The only difference with these apps is that mine is a independent watch app, they're "dependent apps".

Can't "watch-only App" use the network on Watch Series 6 devices? Will Watch Series 6 devices have to rely on the iOS app to request a "allow" setting to use wireless data?

Can't "watch-only App" use the network on Watch Series 6 devices?

Yes, see the article on Keeping your watchOS content up to date, specifically the section on Test your update code with different configurations.

Networking error on Independent Apple Watch Apps
 
 
Q