0

I am working on a file provider extension in Swift iOS, and I am able to load all the data in an API call, but this is causing a memory issue, and the app is crashing. To fix this problem, I am trying to add pagination to the same code and at some point, it is working fine, but after loading 10k files, it's not calling the enumerateItems method at all.

func enumerateItems(for observer: NSFileProviderEnumerationObserver, startingAt page: NSFileProviderPage) {
    self.fetchDataFromServer()
}

I have a separate variable called pageNumber, which I am keeping updated on every API response, and if the current response items are equal to the expected item response, then I am increasing the page number and enumerating the items as below in the API response delegate.

 if arrItems.count < self.pagination.limit {
            obsv.didEnumerate(arrItems)
            obsv.finishEnumerating(upTo: nil)
            self.observer = nil
        } else {
            self.currentPage += 1
            let providerPage = NSFileProviderPage("\(currentPage)".data(using: .utf8)!)
            obsv.didEnumerate(arrItems)
            obsv.finishEnumerating(upTo: providerPage)
        }

Till page 9, everything works fine, and it's loading around 10k files, but after that still the files are still there, but it's not calling the enumerator method.

I am following this article, but it's not using the pagination, so it's difficult to understand this concept. https://www.kodeco.com/697468-ios-file-provider-extension-tutorial

Also, I have checked Apple documentation and some sample code, but I am not sure what the use of these two methods is.

 func enumerateChanges(for observer: NSFileProviderChangeObserver, from anchor: NSFileProviderSyncAnchor) {
}

func currentSyncAnchor(completionHandler: @escaping (NSFileProviderSyncAnchor?) -> Void) {
        let data = "\(self.anchor)".data(using: .utf8)
        completionHandler(NSFileProviderSyncAnchor(data!))
    }

If anyone knows about this, I would appreciate it if you could share any ideas on this.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.