Get basic information about iOS devices

Source: Internet
Author: User

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];
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.