最近用QT做了android的相关开发,虽然在界面端对手机、平板的适应性不高,但做项目的效率还是挺高,在IOS方面也尝试了下,有点盲人摸象的感觉,但是QT对IOS、MAC的支持还是挺好的,QT下的C++代码+OC的语言,实现一些功能还是不错的,下面把获取 IOS下的存取目录的代码贡献出来
// 获取沙盒主目录路径
NSString *homeDir = NSHomeDirectory();
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
//复制本地数据库文件到安装目录
NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentDirectory = [paths objectAtIndex:0];
//APP安装目录中的document目录路径
NSString *dbDir = [documentDirectory stringByAppendingPathComponent:@"/XX"];
NSString *dbPath = [documentDirectory stringByAppendingPathComponent:@"/XX/XX.sqlite"];
if([fileManager fileExistsAtPath:dbPath]==NO) {
//项目中的数据库文件路径
NSString *soudbPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"/XX/XX.sqlite"];
// NSString *soudbPath = [homeDir stringByAppendingPathComponent:@"/XX.app/XX/XX.sqlite"];
BOOL isDir = NO;
BOOL existed = [fileManager fileExistsAtPath:documentDirectory isDirectory:&isDir];
if(!(isDir == YES && existed == YES))
{
[fileManager createDirectoryAtPath:documentDirectory withIntermediateDirectories:YES attributes:nil error:&error];
NSLog(@"123");
}
NSLog(@"456");
existed = [fileManager fileExistsAtPath:dbDir isDirectory:&isDir];
if(!(isDir == YES && existed == YES))
{
[fileManager createDirectoryAtPath:dbDir withIntermediateDirectories:YES attributes:nil error:&error];
NSLog(@"789");
}
existed = [fileManager fileExistsAtPath:dbDir isDirectory:&isDir];
if(!(isDir == YES && existed == YES))
{
[fileManager createDirectoryAtPath:dbDir withIntermediateDirectories:YES attributes:nil error:&error];
NSLog(@"78910");
}
BOOL cp = [fileManager copyItemAtPath:soudbPath toPath:dbPath error:&error];
NSLog(@"cp = %d",cp);
// if (error != nil)
// {
// NSLog(@"[Database:Error] %@", error);
// }
// cp = [fileManager isReadableFileAtPath:dbPath];
// NSLog(@"isReadableFileAtPath = %d",cp);
NSLog(soudbPath);
}
else
{
NSLog(@"wucuowu");
}
void XXXXXX::copy()
{
void *copyfxxx = [[IOS_CPY alloc] init];
[XXXX copyfxfx];
}