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

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

@aamct2

Description

@aamct2

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions