Why sending file to watchOS2 simulator from iPhone simulator won't work?

混江龙づ霸主 提交于 2019-12-21 19:47:26

问题


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

来源:https://stackoverflow.com/questions/32071924/why-sending-file-to-watchos2-simulator-from-iphone-simulator-wont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!