Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network error on WatchOS Device #121

Open
dimix opened this issue May 5, 2023 · 3 comments
Open

Network error on WatchOS Device #121

dimix opened this issue May 5, 2023 · 3 comments

Comments

@dimix
Copy link

dimix commented May 5, 2023

On Apple Watch Device I've Network errors and the image is not loaded:

2023-05-05 12:02:52.574064+0200 Pin Vision Watch App[423:14134] Error getting network data status Error Domain=NSPOSIXErrorDomain Code=19 "Operation not supported by device"
2023-05-05 12:02:52.574407+0200 Pin Vision Watch App[423:14134] Task <C1C21836-E556-4D68-B493-977A1D301FB5>.<0> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
2023-05-05 12:02:52.574955+0200 Pin Vision Watch App[423:14131] NSURLConnection finished with error - code -1009

In simulator the image is loaded correctly without errors.

How can I load map images directly in Device?
Thanks!

@dimix
Copy link
Author

dimix commented May 5, 2023

The code used is:

let snapshot = Snapshot(options: options, accessToken: Self.token)
let image = snapshot.image

@dimix
Copy link
Author

dimix commented May 5, 2023

I found the issue.

The code is wrong on WatchOS:

Snapshot.swift line 174

@objc open var image: Image? {
        if let data = try? Data(contentsOf: url) {
            return Image(data: data)
        } else {
            return nil
        }
    }

Loading directly from Data is not allowed. You need to use URLSession instead.

@jatin19121990
Copy link

Extend Class Snapshot and implement new method using URLSession like:

extension Snapshot {
    func getImage() async throws -> UIImage? {
        let (data, _) = try await URLSession.shared.data(from: url)
        return UIImage(data: data)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants