Is it possible to write new file to bundle resource directory in iOS app?

后端 未结 2 1109
时光说笑
时光说笑 2021-01-02 14:38

Is it possible to write new file to bundle resource directory in iOS app?

2条回答
  •  心在旅途
    2021-01-02 15:15

    Or you can copy the resources needed and then operate on files with writing permission.

    NSArray  *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *documentsDir = dirPaths[0];
    
    NSString *databasePath = [documentsDir stringByAppendingString:@"/TwigitDatabase.db"];
    
    NSFileManager *fm = [NSFileManager defaultManager];
    
    if(![fm fileExistsAtPath:databasePath]) {   // Checking whether the my database was copied earlier, though it could be saved in some preferences property.
        NSError *error;
            NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"TwigitDatabase" ofType:@"db"];
        [[NSFileManager defaultManager] copyItemAtPath:soundFilePath toPath:databasePath error:&error];
    
        NSLog(@"%@", error);
    
    
    }
    

提交回复
热议问题