andybiochem
andybiochem

Reputation: 33

Storing iCloud Container URL

Can I store the NSURL returned from:

[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]

in the NSUserDefaults (or plist) to enable faster access to the iCloud container when my app starts?

Currently, the above code can take a good few seconds (sometimes 10 seconds plus) to return the container path. This results in a noticeable and annoying lag in loading up the user's data from iCloud as my app waits for the return.

I'm assuming that the NSURL path is exactly the same each time the app is launched and so it should be ok to store it for quick access later.

I have tried this on my own devices and it works fine, I am just wondering if there may be any problems doing this out in the 'wild'.

Ta

Upvotes: 1

Views: 142

Answers (1)

Tom Harrington
Tom Harrington

Reputation: 70976

That will probably work. But it doesn't solve a problem, it just moves it around. That method blocks like it does because internally it's getting iCloud up and running for your app (which might involve network calls). That's going to happen sooner or later, because it's part of the iCloud setup process for your app. You might avoid that call but you'll hit the delay somewhere else.

The only major gotcha is that the user might log out of iCloud while your app isn't running, or worse, log out of iCloud and in to a different iCloud account. If you save this URL, make sure you also save the value of ubiquityIdentityToken (which you can look up without blocking), and check whether its value has changed at app launch time. Also listen for NSUbiquityIdentityDidChangeNotification and, if it's ever posted, look up the URL again and save the new value.

Upvotes: 2

Related Questions