Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-23-2012, 02:25 PM   #1 (permalink)
Registered Member
 
Whitehk's Avatar
 
Join Date: Feb 2010
Posts: 119
Whitehk is on a distinguished road
Default iCloud Core Data Crash?

Hi. I recently incorporated the new NSManagedDocument into my core data library-style app, and now I'm trying to implement iCloud. I enabled entitlements, created an iCloud enabled provisioning profile, started observing NSMetadataQueryDidFinishGatheringNotification and NSMetadataQueryDidUpdateNotification with the passed object being my iCloud query, and set the persistent store options (NSPersistentStoreUbiquitousContentURLKey and NSPersistentStoreUbiquitousContentNameKey). Something odd to note is that I must put a call to the method that sets my persistent store options in the setter of the UIManagedDocument in order for my app to appear in iCloud. The app won't show up in iCloud if I put the call to the method that sets the options in viewdidload or viewwillappear.

Here is the setter for my UIManagedDocument:

Code:
 -(void)coreDataDatabase_ManagedDocument:(UIManagedDocument *)coreDataDatabase_ManagedDocument
{
    [[NSFileManager defaultManager] fileExistsAtPath:[self.coreDataDatabase_ManagedDocument.fileURL path]];
    
    if (_coreDataDatabase_ManagedDocument != coreDataDatabase_ManagedDocument) {
        _coreDataDatabase_ManagedDocument = coreDataDatabase_ManagedDocument;
        [self setPersistentStoreOptions];
        [self useDocument]; //Open the document and setup the fetched results controller upon completion
    }
}
Here is the callback method for both the notifications:

Code:
-(void)processCloudQueryResults:(NSNotification *)notification
{
	[self.iCloudQuery disableUpdates]; //Stop updates so we can't receive any while we're updating everything
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self.coreDataDatabase_ManagedDocument.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
    });

	[self.iCloudQuery enableUpdates]; //re-enable updates
}
Whenever I run this on one device everything works as expected. However when I load it up on the second device, it works fine on the second device, but it then crashes on the first device with the error
Quote:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFArray objectAtIndex:]: index (3) beyond bounds (3)'
Any ideas?

Last edited by Whitehk; 01-23-2012 at 02:27 PM. Reason: forgot some details
Whitehk is offline   Reply With Quote
Reply

Bookmarks

Tags
core data, icloud, nsmanageddocument, persistent store options

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 378
10 members and 368 guests
7twenty7, Atatator, FrankWeller, glenn_sayers, iphonedevshani, MAMN84, mraalex, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0