Swift 3 Alamofire request crashes on app review?

So I have a MacOS app with a “Find IP” button, that calls a funciton to get a json from a webserver that should contain an IP address for a Hue bridge.  Every time I submit this for app review, it is rejected because the “Find IP” button is causing the app to crash.  The crash logs I am sent reference EXC_BAD_INSTRUCTION (SIGILL).

I am unable to replicate this crash on any of 4 computers in my home.  On all of my own systems, the button successfully runs the function and returns an IP address.  What is wrong here? :

func findhueip() {

        Alamofire.request(“https://www.meethue.com/api/nupnp“, method: .get).responseJSON { response in

            // craziness to prevent crash that apple says is happening but i cannot see on any of my computers

            if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {

                let testString = utf8Text.matchingStrings(regex: “internalipaddress”)

                if testString[0][0] != “internalipaddress” {

                    self.hueBridgeIPtextfield.stringValue = “no bridge found”

                    self.updateConnectButtonState()

                    return

                }

            }

            if let result = response.result.value {

                guard let json = result as? [[String: Any]] else {

                    self.hueBridgeIPtextfield.stringValue = “no bridge found”

                    self.updateConnectButtonState()

                    return

                }

                // try to prevent crashes when this doesn’t return an ip address… apple got a crash somewhere here

                var foundip = false

                let test = json[0].map { $0.0 }

                for keyname in test {

                    if keyname == “internalipaddress” {

                        foundip = true

                        break

                    }

                }

                if foundip {

                    let bridgeip = json[0][“internalipaddress”]

                    self.hueBridgeIPtextfield.stringValue = bridgeip as! String

                } else {

                    self.hueBridgeIPtextfield.stringValue = “no bridge found”

                }

            }

            self.updateConnectButtonState()

        }

   

    }

 

Can anyone help me figure out why this function is crashing for apple?  All I can think is that it must be related to the testers not having a Hue Bridge and the json being empty.  But I check for that and do a return if the content doesn’t have what I am looking for.  I have no idea.  I have so many checks in there.  What am I missing?  If anyone can provide any kind of help as to where this could be causing a crash for Apple testers, but not for me, then please give me a hint.

Powered by WPeMatico

About

You may also like...

Comments are closed.