IOS笔记

来源:互联网 发布:网络机房消防应急预案 编辑:程序博客网 时间:2024/04/29 20:26

//应用程序目录

1 /Documents   2. /Library/Caches   3. /Library/Preferences   4. /tmp


//获取应用版本号

NSString *version = [[[NSBundlemainBundle]infoDictionary]objectForKey:@"CFBundleVersion"];


//判断对象是否为指定类型

[(id)object  isKindOfClass  [(id)object  class];


//判断设备类型

-(NSString*) getDeviceVersion{

    //方法1:判断所有设备

    if (0) {

        size_t size;

        sysctlbyname("hw.machine",NULL,&size,NULL,0);

        char *machine = (char*) malloc(size);

        sysctlbyname("hw.machine",machine,&size,NULL,0);

        NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];

        free(machine);

return platform;

    }

    //方法2 判断是iphone4还是iphone5

    CGRect rect = [[UIScreenmainScreen]bounds];

    if (rect.size.height ==1136 || rect.size.height ==568) {

        return @"iphone5";

    }else{

        return @"iphone4";

    }

}



分辨率:

CGRect rect = [[UIScreenmainScreen]bounds];

CGFloat scale = [UIScreen mainScreen].scale;

NSString *model = [UIDevice currentDevice].model


retaincount 的理解
http://blog.csdn.net/andypan1314/article/details/7055237

有关@property与retaincount
@property test* the test     retaincount 从来不加1
@property(retain)test* thetest  当被调用时retaincount加1
@property(nonatomic,retain)test* thetest  当被赋值时retaincount加1

URL请求:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

图片数据旋转: UIImage *changeImage = [[UIImage imageWithCGImage:image01.CGImage scale:1.0 orientation: UIImageOrientationRight];

路径:
资源包路径:

NSString* resourcePath = [[NSBundlemainBundle] resourcePath];

获取Documents文件路径
NSString* filePath = NSHomeDirectory();
NSString *DocumentsPath = [filePath stringByAppendingPathComponent:@"Documents"];

NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [pathsArray objectAtIndex:0];

绝对路径、相对路径:
NSString *path = @"~/aaa.txt";
NSString *absolutePath = [Path stringByExpendingTildeInPath];
NSString *relativePath = [absolutePath stringByAbbreviatingWithTildeInPath];


文件:
创建文件:
[[NSFileManager defaultManager] createFileAtPath:filePath];
创建文件夹:
[[NSFileManager defaultManager] createDirectoryAtPath:folerPath ......];
判断文件是否存在:
[[NSFileManager defaultManager] fileExistsAtPath:filePath];
删除文件(文件夹):
[[NSFileManager defaultManager] removeItemAtPath:filePath];
原创粉丝点击