为什么从iPhone模拟器向watchOS2模拟器发送文件不起作用?

时间:2015-08-18 12:03:56

标签: ios objective-c iphone ios9 watch-os-2

我正在尝试将数据库从iOS 9 iPhone复制到watchOS 2 Apple Watch(两个模拟器),什么都没有。文件/文件无处可寻。 (到处搜索)

我想在从iPhone到Apple Watch的应用程序中输入数据库,即使只有iPhone上的应用程序打开(watchOS2上的应用程序关闭)。 我究竟做错了什么?

+(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;
}

0 个答案:

没有答案