Image in WatchKit

Could anyone help me? If push view app crashed only on real Apple Watch, not Crashed in Watch simulator.

 override func awake(withContext context: Any?) {

        super.awake(withContext: context)

  let imageUrlStringQR = "http://192.168.x.x/Image/MainCollection/MainBG.png"

        let imageUrlQR = URL(string: imageUrlStringQR)

        let imageDataQR = try! Data(contentsOf: imageUrlQR!)

        let imageQR2 = UIImage(data: imageDataQR)

        QRImage.setImage(imageQR2)

    }

 let imageUrlStringQR = "http://192.168.x.x/Image/MainCollection/MainBG.png"

that's an image on your internal network. Simulator (in fact, the Mac) can access it, but your Watch probably has not access to you local network.

Did you try loading an image on a server on the web ?

How I allow permission for access to local network in WatchKit?

    let imageDataQR = try! Data(contentsOf: imageUrlQR!)

problem is in ,,try!” If I use ,,try?” Application work correct without crashed, but image is nil.

Error Log from real device

2022-02-15 08:09:19.814542+0100 WatchAppQR Extension[987:557750] [connection] nw_endpoint_fallback_get_timeout_nanos [C1 amc.radimambroz.cz:443 waiting fallback (unsatisfied (Path was denied by NECP policy), interface: en0, ipv4, fallback: {interface: ipsec0, agent: AB2583A1-8D31-40EE-9621-955B3A43F825, weak, generation: 2592)] No RTT information for fallback interface, will use a default value 200ms

2022-02-15 08:09:20.243082+0100 WatchAppQR Extension[987:557750] Connection 1: received failure notification

2022-02-15 08:09:20.243984+0100 WatchAppQR Extension[987:557750] Connection 1: failed to connect 1:50, reason -1

2022-02-15 08:09:20.244115+0100 WatchAppQR Extension[987:557750] Connection 1: encountered error(1:50)

2022-02-15 08:09:20.285431+0100 WatchAppQR Extension[987:557755] Error getting network data status Error Domain=NSPOSIXErrorDomain Code=19 "Operation not supported by device"

2022-02-15 08:09:20.285795+0100 WatchAppQR Extension[987:557755] Task <69AB4258-A674-4EDB-8FF4-554CEC249F0E>.<0> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])

2022-02-15 08:09:20.286523+0100 WatchAppQR Extension[987:557754] NSURLConnection finished with error - code -1009

2022-02-15 08:09:20.334845+0100 WatchAppQR Extension[987:557750] Connection 2: received failure notification

2022-02-15 08:09:20.334924+0100 WatchAppQR Extension[987:557750] Connection 2: failed to connect 1:50, reason -1

2022-02-15 08:09:20.334947+0100 WatchAppQR Extension[987:557750] Connection 2: encountered error(1:50)

2022-02-15 08:09:20.345489+0100 WatchAppQR Extension[987:557754] Task .<0> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])

2022-02-15 08:09:20.345637+0100 WatchAppQR Extension[987:557754] NSURLConnection finished with error - code -1009

Image in WatchKit
 
 
Q