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 11-16-2011, 04:43 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 14
treasure is on a distinguished road
Default addSkipBackupAttributeToItemAtURL - Am I doing the right thing here?

i was wondering if im implementing this the right way. Any help would be greatly appreciated

Intoduction:

I got two persistentStoreCoordinators (for my strange reasons)

One for the default and one for the User.

I keep both sqlites at the Documents folder.

What i want is to keep the user.sqlite in the iCloud and sync it,

and NOT to keep the default.sqlite - so NO Sync-ing with iCloud...

Here is my code:

Code:
//Apple provided snipet

#include <sys/xattr.h>


- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
const char* filePath = [[URL path] fileSystemRepresentation];

const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;

int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;

}


//------------
// My code now
//-------------


//Default persistentStore.....

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }

     NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"default.sqlite"];

     /*
      For the sake of illustration, provide a pre-populated default store.
      */

     NSFileManager *fileManager = [NSFileManager defaultManager];
     // If the expected store doesn't exist, copy the default store.
     if (![fileManager fileExistsAtPath:storePath]) {
          NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"default" ofType:@"sqlite"];
          if (defaultStorePath) {
               [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
          }
     }
}


     NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
//Added this to prevent default to be backed-up

[self addSkipBackupAttributeToItemAtURL:storeUrl];

     NSError *error;



 persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error])     
{

          NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
          abort();
    }    

    return persistentStoreCoordinator;
}



//User persistentStore....


- (NSPersistentStoreCoordinator *)userPersistentStoreCoordinator {

     if (userPersistentStoreCoordinator != nil) {
          return userPersistentStoreCoordinator;
     }

     NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"user.sqlite"]];

     // handle db upgrade
     NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                    [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

     NSError *error = nil;
     userPersistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self userManagedObjectModel]];
     if (![userPersistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
          // Handle error
     }

     return userPersistentStoreCoordinator;
}
is this the correct way to do it?

Thanks
treasure is offline   Reply With Quote
Reply

Bookmarks

Tags
backup, icloud, iphone, sdk

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: 394
17 members and 377 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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