Во время загрузки, как справиться с падением приложения iOS после сна? - PullRequest
0 голосов
/ 12 июля 2019

Я загружаю файл в ячейку таблицы в ComicListViewcontroller, когда запускаю popViewController, затем получаю ComicListViewcontroller, а затем снова возвращаю popViewController в ComicViewcontroller.Если он спит, приложение вылетает, когда я иду домой

func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {

        PublicClass.isFinishDownloading = false

        if let downloadUrl = downloadTask.originalRequest?.url?.absoluteString,
            let downloader = PublicClass.downloadFileLink[downloadUrl] {

            downloader.progress = Float(totalBytesWritten) / Float(totalBytesExpectedToWrite)

            self.totalItems = "\(PublicClass.downloadInProcess.count) Items"
            self.taskdownload = downloadTask

            DispatchQueue.main.async {
                print(downloader.progress)
                if(String(format: "%.1f%%", downloader.progress * 100) == "100.0%"){
                    print(String(format: "%.1f%%", downloader.progress * 100))
                    self.presenter.getComicList()
                    self.root.tableView.reloadData()
                }
            }
        }
    }

2019-07-12 10: 02: 55.617104 + 0700 Сарипутта [2186: 66954] - [Sariputta.ComicListViewController originalRequest]: нераспознанный селектор отправлен в экземпляр 0x7fe184599f30 2019-07-12 10: 02: 55.630284 + 0700 Sariputta [2186: 66954] Завершение работы приложения из-за невыполненного исключения «NSInvalidArgumentException», причина: '- [Sariputta.ComicListViewControllerэкземпляр 0x7fe184599f30 'Стек вызовов первого выброса: (0 CoreFoundation 0x000000011058e1bb exceptionPreprocess + 331 1 libobjc.A.dylib 0x000000010f6b0735 objc_exception_throw + 48 2 CoreFoundation
0x0000000100000000B0B0NB0SB2BB0502SB2BB0502SB0406BB0406B064BeB0SB0402Seb_sb_b_b_b_b_b_b_b_b_b_p_b_b_b_b_b_p_b_p_0_2)UIResponder hasNotRecognizeSelector:] + 287 4 CoreFoundation 0x0000000110592ed6 ___ forwarding_
+ 1446 5 CoreFoundation
0x0000000110594da8 _CF_forwarding_prep_0 + 120 6 Sariputta
0500000000000000000000000000000000000000000000000omicListViewControllerC10urlSession_12downloadTask12didWriteData17totalBytesWritten0mn10ExpectedToK0ySo12NSURLSessionC_So0r8DownloadI0Cs5Int64VA2NtF + 233 7 Сарипутта 0x000000010b34d8b9 $ S9Sariputta23ComicListViewControllerC10urlSession_12downloadTask12didWriteData17totalBytesWritten0mn10ExpectedToK0ySo12NSURLSessionC_So0r8DownloadI0Cs5Int64VA2NtFTo + 105 8 CoreFoundation 0x00000001104cdbac CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 12 9 CoreFoundation 0x00000001104cd02f _CFXRegistrationPost + 447 10 CoreFoundation 0x00000001104ccd71 _CFXNotificationPost_block_invoke + 225 11 CoreFoundation 0x00000001105b3ae2 - [_ CFXNotificationRegistrar найти: Объект: Наблюдатель: перечислитель:] + 1826 12 CoreFoundation 0x00000001104cc694 _CFXNotificationPost + 964 13 Foundation 0x000000010e0b6589 - [NSNotificationCenter postNotificationName: объект: userInfo:] + 66 14 UIKitCore
0x0000000118b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 все еще не защищенных от королей7159 - [__ UICanvasLifecycleMonitor_Compatability activateEventsOnly: withContext: завершение:] + 2742 16 UIKitCore
0x0000000118314cb5 __82 - [_ UIApplicationCanvas _transitionLifecycleStateWithTransitionContext: завершение:] _ block_invoke + 795 17 UIKitCore 0x000000011831495f - [_ UIApplicationCanvas _transitionLifecycleStateWithTransitionContext: завершение:] + 435 18 UIKitCore 0x0000000118319a90 __125- [_UICanvasLifecycleSettingsDiffAction performActionsForCanvas: withUpdatedScene: settingsDiff: fromSettings: transitionContext:] _ block_invoke + 584 19 UIKitCore 0x000000011831a80e _performActionsWithDelayForTransitionContext + 100 20 UIKitCore 0x00000001183197ef - [_ UICanvasLifecycleSettingsDiffAction performActionsForCanvas: withUpdatedScene: settingsDiff: fromSettings: transitionContext:] + 221 21 UIKitCore 0x000000011831e93a - [_ UICanvas сцена: didUpdateWithDiff:transitionContext: завершение:] + 392 22 UIKitCore 0x000000011869b1f5 - [UIApplicationSceneClientAgent сцена: handleEvent: withCompletion:] + 502 23 FrontBoardServices 0x000000011b876fdb __80- [FBSSceneImpl Updater: didUpdateSettings: withDiff: transitionContext: завершение:] _ block_invoke.359+ 213 24 libdispatch.dylib 0x00000001119de602 _dispatch_client_callout + 8 25 libdispatch.dylib 0x00000001119e1b78 _dispatch_block_invoke_direct + 301 26 FrontBoardServices 0x000000011b8b5ba8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK
30 + 27 FrontBoardServices 0x000000011b8b5860 - [FBSSerialQueue _performNext] + 457 28 FrontBoardServices 0x000000011b8b5e40 - [FBSSerialQueue _performNextFromRunLoopSource] + 45 29 CoreFoundation 0x00000001104f3721 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 30 CoreFoundation 0x00000001104f2f93 __CFRunLoopDoSources0 + 243 31 CoreFoundation 0x00000001104ed63f __CFRunLoopRun + 1 263 32 CoreFoundation * 1 018 * 0x00000001104ece11 CFRunLoopRunSpecific + 625 33 GraphicsServices
0x000000011621d1dd GSEventRunModal + 62 34 UIKitCore
0x0000000118af981d UIApplicationMain + 140 35 Сарипутта
0x000000010b47e3e7 main + 71 36 libdyld.dylib
0x0000000111a54575 start + 1 37 ???
0x0000000000000001 0x0 + 1) libc ++ abi.dylib: завершается с невостребованным исключением типа NSException

1 Ответ

0 голосов
/ 12 июля 2019

Я знаю ответ, в ComicListViewController viewDidLoad ()

if PublicClass.isDownloading == true {
            NotificationCenter.default.addObserver(self, selector: #selector(urlSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:)), name: UIApplication.willEnterForegroundNotification, object: nil)
            UIApplication.shared.isIdleTimerDisabled = true
        }

Если я удаляю этот код, он не падает, но мне нужен этот код для продолжения загрузки файла, когда в него попадаешь.

...