0

I'm developing new app for WatchOS while app works normally on simulator it crashes on actual device without any error log. First I thought that it may be to my watch and submitted app to review and it got rejected since it crashes on actual device. The code of watch is really simple, it just sends HTTP request and that's all.

override func willActivate() {
        // This method is called when watch view controller is about to be visible to user

        let request = NSURL(string: "[MY SERVER URL]")
        var response = try! String(contentsOfURL: request!)

        if response == "X"{
            response = ":D"
        }

        watch_text.setText(response)

        super.willActivate()
    }
user897234
  • 47
  • 1
  • 7
  • just guessing, do you have internet connection? maybe response is invalid if not initialized correctly, so you are assigning "nil" as text in `watch_text` and for this reason it will crash – ddb Jul 14 '16 at 10:15
  • Yes I have, also I guess that Apple Review team also has Internet connection – user897234 Jul 14 '16 at 10:45

1 Answers1

0

Two issues at hand:

  • Blocking the app

    You're making a synchronous network request in willActivate(), and blocking the UI. The user is waiting for your app to load, but they may have to wait a long time for the network request to complete or fail.

    In addition to this being a negative experience, you're not considering how the operating system can kill your process if it thinks it is hung.

    You should use NSURLSession to load your URL, and set the label in its completion handler.

  • Force unwrapping and ignoring errors

    You should handle errors and nil optionals, instead of ignoring errors and force-unwrapping optionals.

    Anytime you see a !, think of it as an opportunity for your code to crash when something unexpected happens which you didn't handle.

I thought that it may be to my watch

If it doesn't work on your watch, it likely won't work on another watch.

When something doesn't work (the way you expect), it's far more likely that it's a software issue (with your code), rather than a hardware issue with the watch.

Community
  • 1
  • 1
  • I changed my code to asynchronous, I'll let you know if app gets accepted – user897234 Jul 14 '16 at 12:45
  • Please understand that Apple reviewers aren't there to beta test your app. You should use testflight or another service to let users provide feedback *before* you submit it to the App Store. –  Jul 14 '16 at 12:50