Original address: http://www.cnblogs.com/U-tansuo/p/ios_basis_info.html
1, get the device type (Iphone/ipad? )
#import "Sys/utsname.h"
-(nsstring*) getdeviceversion
{
struct Utsname systemInfo;
Uname (&systeminfo);
NSString *devicestring = [NSString stringWithCString:systemInfo.machine encoding:nsutf8stringencoding];
return devicestring;
}
2. Get the system time
nsdate* date = [NSDate date];
nsdateformatter* formatter = [[[[NSDateFormatter alloc] init] autorelease];
[Formatter setdateformat:@ "Yyyy-mm-dd HH:MM:SS"];
[Formatter stringfromdate:date];
3. Get the app version of the phone system version information
uidevice* Uidevice = [Uidevice currentdevice];
nsbundle* nsbundle = [NSBundle mainbundle];
Nsdictionary *infodictionary = [NSBundle infodictionary];
nsstring* crashInfo = [NSString stringwithformat:@ "Identifier:%@\nversion:%@\nos version:%@%@\ndate/time:%@\ Nhardware model:%@ ",
[NSBundle Bundleidentifier],
[Infodictionary objectforkey:@ "Cfbundleversion"],
[Uidevice SystemName],
[Uidevice Systemversion],
[Self getonlytime],
[Self devicestring]];
4. Get the application directory
Nsarray *paths = Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES);
NSString *cachedir = [Paths objectatindex:0];
5. Create an internal application Folder
Nsfilemanager *FM = [Nsfilemanager Defaultmanager];
Nsdictionary *attributes = [nsdictionary dictionarywithobject: [NSNumber numberwithunsignedlong:0755] ForKey: Nsfileposixpermissions];
if (![ FM fileexistsatpath: "File path"]) {
[FM createdirectoryatpath: "File path" Withintermediatedirectories:yes attributes:attributes Error:null];
}
6. Get all files under a folder and delete the file ending with a suffix name
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];
}
}