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:
- I added the following code, but doesn't work.
configuration.allowsCellularAccess = true
configuration.waitsForConnectivity = true
- 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)
}
}
}
}
- 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.