1、獲取設(shè)備類型 (Iphone/ipad 幾?)
#import <sys/utsname.h>
-(NSString*)getDeviceVersion
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
return deviceString;
}
2、獲取系統(tǒng)時(shí)間
NSDate* date = [NSDate date];
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
[formatter stringFromDate:date];
3、獲取應(yīng)用版本 手機(jī)系統(tǒng)版本信息
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、獲取應(yīng)用程序目錄
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDir = [paths objectAtIndex: 0];
5、創(chuàng)建應(yīng)用程序內(nèi)部文件夾
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、獲取某個(gè)文件夾下所有文件 及刪除以某后綴名結(jié)尾文件
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];
}
}