-(float)getFreeDiskspace {
float totalSpace = 0.0f;
float totalFreeSpace = 0.0f;
NSError *error = nil; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) { NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize]; NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes floatValue];
totalFreeSpace = [freeFileSystemSizeInBytes floatValue];
NSLog(@"Memory Capacity of %f MiB with %f MiB Free memory available.", ((totalSpace/1024.0f)/1024.0f), ((totalFreeSpace/1024.0f)/1024.0f));
} else { NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]); }
return totalFreeSpace;
}
2011年12月21日 星期三
偵測iOS還剩下多少記憶體的程式碼(iOS - detect total available/free disk space on the iPhone/iPad device)
2011年11月1日 星期二
用zlib來解壓縮資料
//uncompress data
- (void)uncompress:(char*)compressData uncompressData:(char*)uncompressData compressSize:(uint32_t)compressSize uncompressSize:(uint32_t) uncompressSize
{
uLongf ld = uncompressSize;
uLong sl = compressSize;
int _ret = uncompress((Bytef*)uncompressData, &ld,(const Bytef *)compressData, sl);
if( _ret == Z_OK)
{
DEBUG(@"Z_OK");
}
}
2011年10月12日 星期三
char * <-> NSData
char* to NSData
[NSData dataWithBytes:myImageData length:myImageDataLength]
NSData to char*
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSUInteger len = [data length];
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [data bytes], len);
訂閱:
文章 (Atom)