Contact Provider Extension "enumerateContent" Method Called Multiple Times

I'm facing an issue with the enumerateContent method in my Contact Provider extension. The method is being called multiple times before I call the first observer.didEnumerate..

Here's a sample of my code:

class TestContactProviderRootContainerEnumerator : ContactItemEnumerator {
    let handler = TestContactProviderUsecaseHandler()

    func configure(for domain: ContactProviderDomain) {
        log.error("---> configure")
    }

    func enumerateContent(in page: ContactItemPage, for observer: ContactItemContentObserver) {
        let requestPage = getPageIndex(from: page.offset, pageSize: observer.suggestedPageSize)
        log.error("---> Begin Enumerate Content page=\(requestPage)  pageSize =\(observer.suggestedPageSize)")

        func completion(items: [ContactItem], hasMore: Bool) {
            observer.didEnumerate(items)
            do {
                let generationMarker = try getGenerationMarker(page: page)
                if hasMore {
                    let nextPage = ContactItemPage(generationMarker: generationMarker, offset: page.offset + items.count)
                    log.error("---> nextPage set offset \(page.offset + items.count) nextPage: \(getPageIndex(from: page.offset + items.count, pageSize: observer.suggestedPageSize))")
                    observer.didFinishEnumeratingPage(upTo: nextPage)
                }else {
                    observer.didFinishEnumeratingContent(upTo: generationMarker)
                }
            }catch {
                observer.didFinishEnumeratingContentWithError(error)
                return
            }
        }

        log.error("---> Start Request page=\(requestPage)  pageSize =\(observer.suggestedPageSize)")
        handler.requestForRecordsList(page: requestPage, perPage: observer.suggestedPageSize, sortBy: Field.Contact.lastName, modifiedSince: nil, completion: { contactItems, hasMore, error in
            log.error("---> Finish Request page=\(requestPage)  pageSize =\(observer.suggestedPageSize)")
            if let error {
                log.error("---> Error: \(error)")
                observer.didFinishEnumeratingContentWithError(error)
                return
            }
            completion(items: contactItems, hasMore: hasMore)
            log.error("---> End Enumerate Content page=\(requestPage)  pageSize =\(observer.suggestedPageSize)")
        })
    }
}

Below are the logs that I'm seeing:

---> configure
---> Begin Enumerate Content page=1  pageSize =20
---> Start Request page=1  pageSize =20
---> Begin Enumerate Content page=1  pageSize =20
---> Begin Enumerate Content page=1  pageSize =20
---> Begin Enumerate Content page=1  pageSize =20
....10+times
---> Begin Enumerate Content page=1  pageSize =20
---> Finish Request page=1 pageSize =20
---> Begin Enumerate Content page=1  pageSize =20​​
​---> nextPage set offset 20 nextPage: 2​​
​---> Begin Enumerate Content page=1 pageSize =20
---> Begin Enumerate Content page=1 pageSize =20​
​---> Begin Enumerate Content page=2 pageSize =20
---> Begin Enumerate Content page=2 pageSize =20​
​---> Start Request page=2 pageSize =20​
​---> Begin Enumerate Content page=2 pageSize =20
---> Begin Enumerate Content page=2 pageSize =20​
​....10+times
---> Begin Enumerate Content page=2 pageSize =20
---> Begin Enumerate Content page=2 pageSize =20

Has anyone else experienced this issue? Any ideas on why this is happening or how to fix it.

I'm facing an issue with the enumerateContent method in my Contact Provider extension. The method is being called multiple times before I call the first observer.didEnumerate..

The system basically calls "enumerateContent" as a synchronous method, so returning immediately means the system ends up retrying immediately.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

so it's not possible to return it immediately. Is there a way to use the Contact Provider extension asynchronously?

Your issue sounds like a bug. Please file a bug report then post the Feedback number here.

Contact Provider Extension "enumerateContent" Method Called Multiple Times
 
 
Q