I am trying to copy database from iOS 9 iPhone to watchOS 2 Apple Watch (Both simulators) and, nothing. File/files is/are no where to found. (searched everywhere)
I want to transfer database when entering in the application from iPhone to Apple Watch even if only application on iPhone is on(app on watchOS2 is off). What am i doing wrong?
+(BOOL)initDatabase{
BOOL ok = NO;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *err;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"database.sqlite"];
ok = [fileManager fileExistsAtPath:writableDBPath];
if (!ok){
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.sqlite"];
ok = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&err];
if (!ok) {
NSAssert1(0, @"Failed to create writable database. Error: '%@'.", [err localizedDescription]);
}
}
if ([WCSession isSupported]) {
WCSession* session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
NSLog(@"watch url: %@",session.watchDirectoryURL);
// session.watchDirectoryURL;
}
[[WCSession defaultSession] transferFile:[NSURL fileURLWithPath:writableDBPath] metadata:nil];
[[Config sharedInstance] addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:writableDBPath]];
ok = [fileManager fileExistsAtPath:writableDBPath];
if (ok){
databasePath = writableDBPath;
database = [FMDatabase databaseWithPath:writableDBPath];
[database open];
NSLog(@"database path: %@",databasePath);
}
return ok;
}