How to optimize the performance of Share Extension?

Hi, all

I developed an APP using Share Extension to import String from txt file into CoreData and synced by iCloud.

In the test of Simulator or device, the Share Extension will success once in about two or three trials.

When I test it in TestFlight, the Share Extension almost not work. After I import the same file 10 times continuously, waiting about 30 minutes, one or two files may be imported successfully. And the one or two files being successfully imported to CoreData are all created in a same time when I check them in CloudKit DashBoard.

How to improve the success rate of Share Extension in Simulator and TestFlight?

Thanks.
I find the bug when I debug Share Extension by Simulator. It is the same as this question. The answers is not very matching for me.

When I share the file the second time, it always crashes and saying the following:

Exception: "executeFetchRequest:error: <null> is not a valid NSFetchRequest."

In my code, the finished flag of Share Extension's each execution is the following:

self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)

Maybe it does not work. Then how to quit Share Extension after its operation finished?

Maybe it does not work. Then how to quit Share Extension after its operation finished?

The "returningItems" parameters are referring to the output object(s), including any changes written to it. If this doesn't apply to your extension and you want to exit cleanly, just return "nil":

self.extensionContext!.completeRequest(returningItems: nil, completionHandler: nil)

Andreas

How to optimize the performance of Share Extension?
 
 
Q