Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

FileManager.url(forUbiquityContainerIdentifier:) should not be called from main thread #12

Open
aamct2 opened this issue Mar 22, 2018 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@aamct2
Copy link

aamct2 commented Mar 22, 2018

Summary

FileManager.url(forUbiquityContainerIdentifier:) is currently being called on the main thread, against Apple's guidance.

Details

At the moment you are instantiating the shared DocumentManager in the DocumentBrowserViewController.viewDidLoad (), which is happening on the main thread.

class DocumentBrowserViewController: UIDocumentBrowserViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Makes sure everything is initialized
_ = DocumentManager.shared

When you step through the initialisation of the DocumentManager, you eventually get to a call for the cloudDocumentsURL property which is where the call to FileManager.url(forUbiquityContainerIdentifier:) happens.

private var cloudDocumentsURL: URL? {
guard iCloudAvailable else {
return nil
}
let ubiquityContainerURL = fileManager.url(forUbiquityContainerIdentifier: ICLOUD_IDENTIFIER)

This goes against Apple's guidance for FileManager.url(forUbiquityContainerIdentifier:) that it should not be called from the main thread.

Important

Do not call this method from your app’s main thread. Because this method might take a nontrivial amount of time to set up iCloud and return the requested URL, you should always call it from a secondary thread. To determine if iCloud is available, especially at launch time, check the value of the ubiquityIdentityToken property instead.

Link to full Apple documentation: https://developer.apple.com/documentation/foundation/filemanager/1411653-url

@louisdh louisdh added the bug Something isn't working label Mar 22, 2018
@louisdh
Copy link
Owner

louisdh commented Mar 22, 2018

Thanks for pointing this out, I'll take a look.

@louisdh louisdh self-assigned this Mar 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants