Tag Archives: iCloud

Why am I not seeing iCloud Store Log Messages in Xcode 7

Screen Shot 2015-09-19 at 11.05.12

I was trying my hand at a new Core Data app with iCloud support today. To my surprise, none of those ubiquitous log messages appeared! You know, the ones that say “Using local storage: 1” and “Using local storage: 0” to indicate which store file is being used. I remember this working flawlessly in Xcode 5 not too long ago.

Turns out that it has to do with the user’s iCloud account, and in what way the App ID is setup. Let me save you some grey hairs and point out the following:

  • an App ID compatible with Xcode 5 will work no matter if the user has upgraded to iCloud Drive or not
  • an App ID compatible with Xcode 6 and above will ONLY work if the user HAS upgraded to iCloud Drive

You can change the behaviour of the App ID in Member Center, under Identifiers – App ID (see screenshot above). If the App ID is setup for iCloud Drive, and the user’s iCloud account has not been upgraded yet, no notifications will show up in your log files.

Upgrading to iCloud Drive

Note that you must upgrade to iCloud Drive on each device that’s currently in use. Although logic dictates that this upgrade happens on a server somewhere, and upgrading one device would be reflected on all others connected to the same iCloud account, in practice this is not the case: a second device may still not show those notifications unless you head over to Settings – iCloud and explicitly hit the “upgrade” button.


Kudos to Zhang and his findings on this subject:

FAIL: iOS 9 can’t restore iCloud Backups from iOS 8


I thought I’d give the new iOS 9 Beta 1 a spin on my ageing iPad 3. I’ve hit a few stumbling blocks and thought I’d tell you about them.

The first attempt to add the new beta using iTunes didn’t work and turned my poor iPad into a coaster. Very disappointing. Thankfully a DFU restore did the trick, and iOS 9 was starting fine. Things were looking up.

I thought it would make sense to restore the latest iCloud Backup I had made just minutes before, thinking that testing with existing data would make sense. But restoring my iCloud Backup didn’t work: I picked one, the restore started, counted down the minutes, and shortly before it was due to finish, it comes up with the message in the screenshot above. Nothing doing.

I had three backups in total from various dates to choose from. I tried them all, multiple times, but to no avail: none of them could be restored. All I could do was to setup my device as a “new iPad” (after all, that was its launch title). It did make me wonder if all my iCloud Backups were broken or if it was just this particular iOS 9 Beta.

So I went on to explore a bit, being particularly intrigued by the Slide Over feature: apparently you slide in from the right hand side with one finger and bring up a second app. Doesn’t work of course. Turns out none of these new features work on my iPad 3, nor on the iPad 2: all you can do is use two fingers on the keyboard and move the cursor (no text selection either).

It was my understanding that Slide Over was supported on all devices, and that only the arbitrary split view and picture-in-picture required this week’s hardware. But since there’s no actual documentation on this topic, your guess is as good as mine. I didn’t even look at the News app, mainly because I’ve un-installed Flipbook and Zite many years ago and have never looked back.

The new Notes features are a nice touch, 4 years late in my opinion, but better late than never. The interface reminds mea little of 53 Paper. It is required to upgrade existing notes for use with iOS 9, much like the upgrade to iCloud Drive. You can choose not to do it, and the app tells you that upgrading means you can no longer exchange notes with older devices.

Apple want to make absolutely sure nobody is using old devices anymore: this is the another step in making sure there will be no more data exchange with iOS 5 and iOS 6 devices. It’s top priority for them. Please throw that iPhone 3GS and iPod Touch 4 and iPad 1 away once and for all. We should all go to the store and drop $1000 a month or more just to be able to write a shopping list that works on all our devices.

I had secretly hoped that iOS 9 would bring performance improvements. My device has been severely crippled with the arrival of iOS 8, and rumour has it that iOS 9 might remedy that. It’s too early to tell I must say: while the keyboard now reflects capital and non-capital letters depending on the shift key, it does take nearly a second for the font to change when you press said shift key or the symbol key. Nothing much has changed there. This could be because betas usually aren’t as fluid as release versions.

But because I no longer expect anything “nice” from the Cupertino Fruit Co. of late, I wasn’t even disappointed. iOS 9 looks and feels exactly like iOS 8 on my current device, and for me there is no benefit in having it on my device: I don’t intend to roll out any new apps in the near future, so I went back to exploring the iCloud Backup situation.

I’ve downloaded the iOS 8.3 release version, quickly wiped my iPad and tried to restore my backup again. No problem at all. Phew! Relieved that my backups were still intact, I try my best to forget this plethora of disappointment with iOS 9.

It’s a bit like how Apple must feel when they’re trying to forget that last year’s OS (or hardware) was ever released.

How to reset your iCloud Ubiquitous Container

In this screencast I’ll show you how to reset your iCloud Ubiquity Container from an iOS device. This will clear up anything you’ve saved in iCloud Documents and iCloud Core Data and also simulates “first installation”.

Sometimes when you test the same app over and over the container can get corrupted, error messages start flooding in and ultimately your app doesn’t behave as expected – making you doubt your sanity, alienating your friends and family and giving you more grey hair then you need.

If the above still doesn’t work, turn your devices off and on again, restart Xcode and reboot your Mac – a useful tip often forgotten with pesky bugs that don’t make sense (thanks to Eric for reminding me of this).

In a nutshell:

  • remove your app from all devices – this is important because running apps, or existing apps launched will assume there’s data in iCloud and they will try to communicate with your (defunct) container
  • remote all data from the container as described in the video (on iOS, head over to Settings – iCloud – Manage Storage – find your app and select it, hit edit and delete all data)
  • now re-deploy the app to each device via Xcode

For Core Data: the first app that’s launched checks to see if data exists in iCloud, and if not will create the iCloud store. Subsequent apps will see this has been done and read the changes from those mysterious log files.

Removing the container in code

You can also call a method on the NSPersistentStoreCoordinator class to remove the entire ubiquity container. Here’s how to do that:

This does pretty much the same thing as the manual method, although it may take a moment. Works in iOS 7, but I’ve not had much luck in iOS 8 Beta 5 (in fact, I’ve not had much luck with anything in iOS 8 Beta 5).

Completing an iCloud Restore when it's stuck on apps deployed from Xcode

Screen Shot 2014-07-22 at 13.30.25

When you update a device with a new iOS Version (beta or not) and restore an iCloud Backup, said backup gets stuck while trying to bring back your own apps that you have deployed with Xcode. The iCloud backup is only saving your app’s data, but not the actual bundle. The idea is that iCloud can bring those back from the App Store.

This means that apps you’ve deployed from Xcode, say as test apps or those still in development, are not on the App Store and hence cannot be brought back. When iCloud restores, it tries really hard – and as a result gets stuck in an endless loop.

The implication is that you cannot deploy a new iOS version over the air when this happens – because the previous restore needs to finish first before applying the new one. However, getting rid of those non-existent apps is impossible – because the standard “tap wiggle and press x” method doesn’t work. Neither does any of the other methods. This leaves us developers stuck with darkened icons like these and a never ending restore loop:

Screen Shot 2014-07-22 at 13.31.00

How do we fix’er, Cap’m?

You can deal with this in several ways:

Option 1: deploy the new iOS Version via iTunes and do not restore an iCloud backup. This however leaves you with lost data and is probably only good as a last resort, of if you don’t care about existing data.

Alternatively you can restore an iCloud backup, but you’ll be stuck in the restore loop again – albeit with a new version of iOS.

Option 2: re-deploy your old apps from Xcode to the device so the restore can finish. As soon as the last app is installed, the new iOS Version can be applied over the air.

If you no longer have access to the old apps fear not: as long as you can remember the Bundle ID, just create a new dummy app with said Bundle ID and deploy that – it’ll make the app on the device “deletable” again. iCloud doesn’t care and will finish the restore.

Note that you must bring back every old app and get rid of any dark icon you have on your springboard for this to work.

Option 3:
By far the simplest thing is to cancel the restore. I’ve only just found out in December 2014 that this option even exists: Settings – iCloud – Backup – Cancel Restore

Screen Shot 2014-07-22 at 13.31.11

What if I don’t remember the Bundle ID’s?

That’ll be a problem… You’ll have to guess. Usually when you deploy something with a title like “Test App”, then spaces in your Bundle ID will be replaced with a dash (as in com.yourdomain.Test-App). Capitalisation is important here: com.yourdomain.Test-App is seen as a different app than com.yourdomain.test-app.

If you’re not sure about the title of your “dark apps” (because usually it says “Waiting” during the restore attempt), try to hold one down, then press the x as if you’re deleting them. The deletion will silently fail, but the standard iOS Alert View will be displayed asking if you’re sure – and in doing so will display the title of this app.

iCloud in your iOS Apps – Part 5: Initial Import Hack

In this final part of the series I’ll let you in on a little secret that will help our app synchronise iCloud Core Data for the first time when it’s installed on another device.

Some devices it appears don’t display existing iCloud results upon first launch. To remedy this, I’ll show you how to re-fetch the Fetched Results Controller in your sample app.

Watch the whole series


Watch the full course in one convenient playlist:
Catch this episode on my iOS Dev Diary Podcast:

How to test why your iCloud Core Data store was changed

When you’re using iCloud with Core Data you need to subscribe and react to the NSPersistentStoreCoordinatorStoresDidChange notification. This will tell you when Core Data was able to transition off the “fake” store and is using the “real” store. It will coincide with the log entry “Using local storage: 0”.

Sometimes you need to know why this has happened so you can react accordingly. Here’s how:

When you react to the above, bring the notification object into your even handler method. This will let you query its userInfo dictionary which will hold the key to why the stores have been changed:

Here we grab the NSPersistentStoreTransitionKeyType entry from the userInfo dictionary. It’s an NSNumber, enumerated to four keys. To test those with a switch statement I’m converting the NSNumber into an int.

Use this to check if an iCloud account has been changed, or if this is the first time an iCloud store has been started on the current device.

I’m explaining this as part of my screencast about using iCloud and Core Data: