ms2138 / ONVIFDiscovery

Discover ONVIF based devices on your local network
MIT License
7 stars 2 forks source link

Project builds and runs but doesn't work on IOS 14 with Xcode 12 #3

Open PlasmaSoftUK opened 4 years ago

PlasmaSoftUK commented 4 years ago

I've tried in the Simulator and on a real device neither can discover my ONVIF devices.

Real device shows:

"UDP connection failed to send data: No route to host" 18:42:50:676 {UI} DiscoveryViewController.swift getDevice(completion:)[67]: "Failed to perform UDP broadcast" "Closing UDP socket"

Simulator looks to work but doesn't return any results:

"UDP connection sent 767 bytes"

Does it need any special plist settings with the privacy changes in IOS 14?

Plasma

cdf1982 commented 1 year ago

I'm testing today on iOS 16 with similar results: on an iPhone I get the UDP connection failed to send data: No route to host message, while on an iPad it shows multiple UDP connection received X bytes from XXX.XXX.XXX.XXX, one for Onvif camera in my network, but nothing else is is logged and the UI remains stuck on Loading.

This library would be so helpful, any suggestions? Thanks in advance

mariano-mix commented 9 months ago

I'm facing same issue as above, anyone has some insights on it?

simonsturge commented 5 months ago

I think there's maybe a couple things going on here. I might need this lib soon so I looked into this a little.

  1. Since iOS 14.5 you now need the multicast networking entitlement for UDP networking. Unless you have this entitlement, I don't think you'll be able to get this working on a device (https://stackoverflow.com/a/67617314/2237587)
  2. I think there may be an issue in 'OnvifQueryService' regarding the 'never finding a device' issue. I logged out the xml result and perhaps the keys have changed?
let accessor = xml["s:Envelope", "s:Body", "d:ProbeMatches", "d:ProbeMatch"]
                // Get the url for the devices ONVIF service
                if let serviceURL = accessor["d:XAddrs"].url {
                    // Get the first scope where the ONVIF link contains hardware and then
                    // get the last path component that contains the devices model
                    if let hardwareScope = accessor["d:Scopes"].text?.split(separator: " ")
                        .first(where: { $0.contains("hardware") }),
                        let model = URL(string: String(hardwareScope))?.lastPathComponent {
                        discoveredDevice = ONVIFDiscovery(model: model,
                                                          ipAddress: ipAddress,
                                                          deviceService: serviceURL)
                    }
                }

I changed some of the keys and I was able to successfully search for devices:

let accessor = xml["SOAP-ENV:Envelope", "SOAP-ENV:Body", "wsdd:ProbeMatches", "wsdd:ProbeMatch"]
                // Get the url for the devices ONVIF service
                if let serviceURL = accessor["wsdd:XAddrs"].url {
                    // Get the first scope where the ONVIF link contains hardware and then
                    // get the last path component that contains the devices model
                    if let hardwareScope = accessor["wsdd:Scopes"].text?.split(separator: " ")
                        .first(where: { $0.contains("hardware") }),
                        let model = URL(string: String(hardwareScope))?.lastPathComponent {
                        discoveredDevice = ONVIFDiscovery(model: model,
                                                          ipAddress: ipAddress,
                                                          deviceService: serviceURL)
                    }
                }

I don't know if I need this lib yet. If I end up using it, I will create a fork / put in a PR for these things

cdf1982 commented 5 months ago

Since iOS 14.5 you now need the multicast networking entitlement for UDP networking. Unless you have this entitlement, I don't think you'll be able to get this working on a device

It's a really good call, @simonsturge.

Since my previous post, I've obtained the multicast entitlement for my app, but haven't thought about Onvif in months. I'll confirm your likely hypothesis as soon as I have a moment (might be a while) and report back.

Thanks!