01 Dec 2013, 07:31
Generic-user-small

David Wilson (11 posts)

I’ve found a comment about this on the Apple devforums

https://devforums.apple.com/message/889721#889721

Not that I understand it.

  • David
01 Dec 2013, 07:11
Generic-user-small

David Wilson (11 posts)

I’m using Xcode 5.1, developing for Mavericks.

I’ve converted my Mac OS application to use Core Data and it has been going well. Next on my list is to add iCloud support. So I added the entitlement, and added the extra code for the persistent store so that iCloud is supported.

So the code looks like thus…


	dispatch_queue_t queue = NULL;
	queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
	dispatch_async(queue, ^{	
		NSMutableDictionary * options = [[NSMutableDictionary alloc] init];
		[options setValue:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
		[options setValue:[NSNumber numberWithBool:YES] forKey:NSInferMappingModelAutomaticallyOption];
		
		NSFileManager *fileManager = [NSFileManager defaultManager];
		NSURL * cloudURL = [fileManager URLForUbiquityContainerIdentifier:nil];
		if (cloudURL)
		{
			NSLog(@"%@ iCloud enabled: %@\n\n", NSStringFromSelector(_cmd), cloudURL);
			cloudURL = [cloudURL URLByAppendingPathComponent:@"TrafficCamNZ"];
			[options setValue:[[NSBundle mainBundle] bundleIdentifier] forKey:NSPersistentStoreUbiquitousContentNameKey];
			[options setValue:cloudURL forKey:NSPersistentStoreUbiquitousContentURLKey];
		} else
		{
			NSLog(@"%@ iCloud is not enabled\n\n", NSStringFromSelector(_cmd));
		}
		
		NSURL *storeURL = nil;
		NSArray *directoryArray = [fileManager URLsForDirectory:NSApplicationSupportDirectory
													  inDomains:NSUserDomainMask];
		storeURL = [directoryArray lastObject];
		NSString * applicationIdentifier = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleIdentifier"];
		storeURL = [storeURL URLByAppendingPathComponent:applicationIdentifier];
		storeURL = [storeURL URLByAppendingPathComponent:@"TrafficCamNZ.sqlite"];
		
		NSError *error = nil;
		NSPersistentStore *store = nil;
		
		store = [psc addPersistentStoreWithType:NSSQLiteStoreType
								  configuration:nil
											URL:storeURL
										options:options
										  error:&error];
		if (!store) {
			NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:@"Error adding persistent store to coordinator %@\n%@", [error localizedDescription], [error userInfo]]);
			[[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__
																							encoding:NSUTF8StringEncoding]
																	file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding]
															  lineNumber:__LINE__
															 description:@"Error adding persistent store to coordinator"];
			//Present a user facing error
#pragma mark TODO: Present a user facing error
		}

And when it runs… I get the following error…

2013-12-01 13:41:22.060 TrafficCamNZ[82471:1307] initializeCoreDataStack iCloud enabled: file:///Users/dgwilson/Library/Mobile%20Documents/ZNVB52L2P6~nz~co~catch22~TrafficCamNZ/

2013-12-01 13:41:22.082 TrafficCamNZ[82471:1307] -[PFUbiquitySetupAssistant validateOptionsWithError:](332): CoreData: Ubiquity:  Invalid option: the value for NSPersistentStoreUbiquitousContentNameKey should not contain periods: nz.co.catch22.TrafficCamNZ
2013-12-01 13:41:22.139 TrafficCamNZ[82471:1307] -[PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](760): CoreData: Ubiquity:  dgwilson~7F0F69DF-F898-585E-B663-8B4A929688C6:nz.co.catch22.TrafficCamNZ
Using local storage: 1

So this means there’s an issue using the CFBundleIdentifier…

What should I do now?

  • David
09 Dec 2013, 20:21
Avatarsmall_pragsmall

Marcus S. Zarra (253 posts)

This was changed recently (Mavericks). Fortunately for you, since you are just now adding iCloud, the impact is minimal.

You need to change the following line of code:

[options setValue:[[NSBundle mainBundle] bundleIdentifier] forKey:NSPersistentStoreUbiquitousContentNameKey];

To something else. What is that something else? I would recommend something descriptive to your application. I have been using class name like structures recently. So I would change it to be the name of your app perhaps or simply “DataStorage”.

The name is unique to your application so the actual value is not important as long as it is understood by you.

03 Feb 2014, 10:18
Generic-user-small

David Wilson (11 posts)

Wonderful. This change has worked.

[Wish these forums would e-mail when a post is made… - didn’t return to check here for 2 months!].

I’m very happy this is working… I can complete testing and changes to move forward for AppStore… Thank you.

  • David
23 Mar 2014, 16:18
Generic-user-small

Paul Linsay (1 post)

While updating an app I came across this warning too. If I remove the period the old content gets lost, which I don’t want to do to my customers. What’s a good way to deal with this problem? Is leaving it untouched acceptable since it’s only a warning?

Thanks,

Paul–

01 Jul 2014, 20:18
Avatarsmall_pragsmall

Marcus S. Zarra (253 posts)

For now yes, I would leave it alone. Just make sure you test for the issue with each version of your app in case Apple changes things. When/if they do then you are looking at a potential migration situation to get the data over to a new key.

  You must be logged in to comment