iOS 设备基本信息

1、获取设备类型 (Iphone/ipad 几?)

#import <sys/utsname.h>

-(NSString*)getDeviceVersion
{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    return deviceString;
}

2、获取系统时间

NSDate* date = [NSDate date]; 
    NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
    [formatter stringFromDate:date];

3、获取应用版本 手机系统版本信息

UIDevice* uiDevice = [UIDevice currentDevice];
    NSBundle* nsBundle = [NSBundle mainBundle];
    NSDictionary *infoDictionary = [nsBundle infoDictionary];
    NSString* crashInfo = [NSString stringWithFormat:@"Identifier:%@\nVersion:%@\nOS Version:%@     %@\n",
                           [nsBundle bundleIdentifier],
                           [infoDictionary objectForKey:@"CFBundleVersion"],
                           [uiDevice systemName],
                           [uiDevice systemVersion]];

4、获取应用程序目录

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cacheDir = [paths objectAtIndex: 0];

5、创建应用程序内部文件夹

NSFileManager *fm = [NSFileManager defaultManager];
        NSDictionary *attributes = [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedLong: 0755] forKey: NSFilePosixPermissions];
        if(![fm fileExistsAtPath:@"文件路径"]){
            
            [fm createDirectoryAtPath:@"文件路径"withIntermediateDirectories:YES attributes:attributes error:NULL];
        }

6、获取某个文件夹下所有文件 及删除以某后缀名结尾文件

NSFileManager *fm = [NSFileManager defaultManager];
    NSArray *contents = [fm contentsOfDirectoryAtPath:path error:NULL];
    NSEnumerator *e = [contents objectEnumerator];
    NSString *filename;
    while ((filename = [e nextObject])) {
        NSLog(@"file Name = %@",filename);
        if ([[filename pathExtension] isEqualToString:@"txt"]||[[filename pathExtension] isEqualToString:@"plcrash"]) {
           [path stringByAppendingPathComponent:filename];
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,338评论 19 139
  • 文章来源:http://www.cocoachina.com/ios/20170921/20619.html (一...
    紫荆逸阅读 349评论 0 0
  • 《爱上了寂寞》 文/白传英 当日头在西天滑落 才发现你已经走过 我想要说些什么 泪水已坠落 抬起头的那一刻...
    白清风阅读 173评论 0 1
  • 今天是周二。早上去了周亦卿楼上UML课,这似乎是倒数第二节了,忙碌的一个学期进入了最后的收尾阶段,时间真是飞快。 ...
    焦大仙阅读 291评论 0 0
  • ‌ 2017的特岗们,还记得吗?8月7号出成绩,几家欢喜几家愁。总是担心自己考不上,加群,报面试班。有人信...
    蔡耀华阅读 629评论 1 0

友情链接更多精彩内容