приложение силы для завершения в iPhone

Поскольку, когда та одна одна строка выдает исключение, Вы не знали бы это.

С первым блоком кода, исключение просто будет , поглотил , программа продолжит выполняться, даже когда состояние программы могло бы быть неправильным.

Со вторым блоком, исключение будет брошено и пузыри , но эти reader.Close(), как все еще гарантируют, будет работать.

, Если исключение не ожидается, то не помещайте попытку.. блок выгоды именно так, будет трудно отладить позже, когда программа вошла в плохое состояние, и у Вас нет идеи почему.

5
задан Kara 1 September 2016 в 15:45
поделиться

7 ответов

Apple абсолютно ясна по поводу этой темы:

Для изящное завершение работы iPhone заявление. В ОС iPhone пользователь нажимает кнопку «Домой», чтобы закрыть Приложения. Если ваше приложение иметь условия, в которых он не может обеспечить свое предназначение, рекомендуемый подход - отобразить alert for the user that indicates the nature of the problem and possible actions the user could take - turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.

See Technical Q&A QA1561

17
ответ дан 18 December 2019 в 05:15
поделиться

I would advise you to reconsider for 3 reasons

  1. It may appear that your app crashed.
  2. The user may get an internet connection while your app is up. In this case a 'Retry' would be best.
  3. I think Apple may actually not accept the app if it does that. It is for sure not what they would do if an Apple application needed an internet connection, and they do test to see what an app will do without a connection.

If (for whatever reason)you do want to do it you can use.

exit(0);
6
ответ дан 18 December 2019 в 05:15
поделиться

You shouldn't do this. Take a look at "Stopping" in the Human Interface Guidelines as you could possibly fail for submitting an App that does this, or at the very least provide for a strange user experience.

The link also shows the correct way to handle this, as in the iTunes Music Store app.

2
ответ дан 18 December 2019 в 05:15
поделиться

Вы всегда можете просто разделить на ноль. В качестве бонуса реализация отразит, насколько это хорошая идея.

5
ответ дан 18 December 2019 в 05:15
поделиться

Your App will be rejected if you terminate when you cannot reach the Internet.

Sorry.

-t

1
ответ дан 18 December 2019 в 05:15
поделиться

You might consider informing the user that they cannot use your application without an active network connection. Just terminating the application outright seems like a very unfriendly way of doing this; the user will simply see the app "disappear".

Every well-behaved app I've seen will at least give a notification before terminating.

10
ответ дан 18 December 2019 в 05:15
поделиться

If you terminate it will look like your app has crashed!

Best to put up a message saying that there is no internet connection and give them an option to retry (in case they can get an internet connection), or choose to quite it themselves

2
ответ дан 18 December 2019 в 05:15
поделиться