У меня есть приложение, которое импортирует потенциально большой объем данных из Интернета после того, как пользователь явно нажимает кнопку синхронизации, и сохраняет эти данные с помощью Core Data. Поскольку я хочу показать отзыв и не хочу, чтобы пользователь взаимодействовал с остальной частью приложения, пока это происходит, нажатие кнопки «Синхронизировать» вызывает модальное диалоговое окно. Поскольку я хочу, чтобы операция выполнялась немедленно, она выполняется в методе viewDidAppear. Я уверен, что это осуждается.
Сейчас есть куча проблем с подходом:
- Everything happens in the main thread. The user kind of gets feedback because there is an activity indicator that continues to animate, but there's no way to indicate progress or show intermediate messages. This is not the right way to do things.
- But, I am told that when using Core Data, everything has to use the main thread, so breaking off the work into another thread does not seem like it will be straightforward.
- If the app enters the background state (user hits Home button or iPad falls sleep), it's game over - the operation dies. It's clear to me from the documentation why this is the case.
- I know there are "I'm about to enter the background" events that you can handle, but it's not as though I can move execution of code from one place to another in the middle of a file download. Whatever solution I use has to be a continuous action that executes in the same way both before and after the transitions to/from the background.
- Я хочу, чтобы операция выполнялась на переднем плане для пользователя. Им не имеет смысла взаимодействовать с другими частями приложения, пока выполняется эта операция.
Я читаю документацию Apple по этому вопросу, но я спрашиваю об этом в надежде найти более краткое руководство по этой конкретной комбинации потребностей. Спасибо.