iOS 开发中的那些坑(1)

来源:互联网 发布:如何更新mac os系统 编辑:程序博客网 时间:2024/05/20 22:31

今天在用fmdb对数据库进行操作的时候 一直无法在表中插入数据 最后才发现 NSBundle中的db文件是read-only属性  不能进行写操作!需要先拷贝到应用文件夹中

#define DBPATH [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:@"/word.db"]

NSFileManager *fileManager=[NSFileManagerdefaultManager];

    if (![fileManagerfileExistsAtPath:DBPATH]) {

        [fileManager copyItemAtPath:[[NSBundlemainBundle]pathForResource:@"word"ofType:@"db"]toPath:DBPATHerror:nil];

    }


计算手机磁盘剩余空间的大小

 NSDictionary *systemAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
    NSString *diskFreeSize = [systemAttributes objectForKey:@"NSFileSystemFreeSize"];
    NSLog(@"可用空间:%.2f GB", [diskFreeSize floatValue]/1024/1024/1024);

0 0
原创粉丝点击