ios開發 獲取手機相關資訊

2021-06-29 02:39:12 字數 3776 閱讀 9778

今天在做客戶端的時候,裡面有個意見反饋功能。

呼叫系統帶的郵件功能,傳送郵件到指定郵箱。

於是,學習了相關的知識,在這裡與大家分享。

在次之前,補充個內容。uidevice是無法獲得具體的裝置型號的。

要獲得裝置型號,比如(iphone 4s, iphone5)這樣的,要通過這樣的辦法。

1.引入標頭檔案。

#include 

#include 

2.獲取型號

//手機型號。

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

這裡得到的

platform是個裝置型號。  比如iphone5,2.

所以如果想更完美點,可以自己根據字串判斷。

比如:if ([platform isequaltostring:@"iphone3,1"])    return @"iphone 4";

uidevice提供了多

種屬性、類函式及狀態通知,幫助我們全方位了解裝置狀況。從檢測電池電量到定位裝置與臨近感應,uidevice所做的工作就是為應用程式提供使用者及裝置的一些資訊。uidevice類還能夠收集關於裝置的各種具體細節,例如機型及ios版本等。其中大部分屬性都對開發工作具有積極的輔助作用。下面的**簡單的使用uidevice獲取手機屬性。

[cpp]view plain

copy

//    [[uidevice currentdevice] systemname]; // 系統名

//    [[uidevice currentdevice] systemversion]; //版本號

//    [[uidevice currentdevice] model]; //型別,模擬器,真機

//    [[uidevice currentdevice] uniqueidentifier]; //唯一識別碼

//    [[uidevice currentdevice] name]; //裝置名稱

//    [[uidevice currentdevice] localizedmodel]; // 本地模式

//裝置相關資訊的獲取

nsstring *strname = [[uidevice currentdevice] name];  

nslog(@"裝置名稱:%@"

, strname);

"my iphone"

nsstring *strid = [[uidevice currentdevice] uniqueidentifier];  

nslog(@"裝置唯一標識:%@"

, strid);

//uuid,5.0後不可用

nsstring *strsysname = [[uidevice currentdevice] systemname];  

nslog(@"系統名稱:%@"

, strsysname);

// e.g. @"ios"

nsstring *strsysversion = [[uidevice currentdevice] systemversion];  

nslog(@"系統版本號:%@"

, strsysversion);

// e.g. @"4.0"

nsstring *strmodel = [[uidevice currentdevice] model];  

nslog(@"裝置模式:%@"

, strmodel);

// e.g. @"iphone", @"ipod touch"

nsstring *strlocmodel = [[uidevice currentdevice] localizedmodel];  

nslog(@"本地裝置模式:%@"

, strlocmodel);

// localized version of model //地方型號  (國際化區域名稱)

nsstring* phonemodel = [[uidevice currentdevice] model];  

nslog(@"手機型號: %@"

,phonemodel );   

//手機型號

bundle是乙個目錄,其中包含了程式會使用到的資源. 這些資源包含了如影象,聲音,編譯好的**,nib檔案(使用者也會把bundle稱為plug-in). 對應bundle,cocoa提供了類nsbundle.乙個應用程式看上去和其他檔案沒有什麼區別. 但是實際上它是乙個包含了nib檔案,編譯**,以及其他資源的目錄. 我們把這個目錄叫做程式的main bundle。通過這個路徑可以獲取到應用的資訊,例如應用名、版本號等。

[cpp]view plain

copy

nsdictionary *dicinfo = [[nsbundle mainbundle] infodictionary];  

// cfshow(dicinfo);

];  

// 當前應用名稱

];  

// 當前應用軟體版本  比如:1.0.1  

];  

// 當前應用版本號碼   int型別

nslocale可以獲取使用者的本地化資訊設定,例如貨幣型別,國家,語言,數字,日期格式的格式化,提供正確的地理位置顯示等等。下面的**獲取機器當前語言和國家**。

[cpp]view plain

copy

//getting the user』s language

nsarray *languagearray = [nslocale preferredlanguages];  

nsstring *language = [languagearray objectatindex:0];  

nslog(@"語言:%@"

, language);

//en

nslocale *locale = [nslocale currentlocale];  

nsstring *country = [locale localeidentifier];  

nslog(@"國家:%@"

, country); 

//en_us

具體的可以自己移植到真機去試試。

下面是傳送郵件**:

[cpp]view plain

copy

//選中傳送郵件形式

if(buttonindex == 0)  

else

}  下面是執行截圖。

學習的路上,與君共勉。

ios開發 獲取手機相關資訊

今天在做客戶端的時候,裡面有個意見反饋功能。呼叫系統帶的郵件功能,傳送郵件到指定郵箱。於是,學習了相關的知識,在這裡與大家分享。在次之前,補充個內容。uidevice是無法獲得具體的裝置型號的。要獲得裝置型號,比如 iphone 4s,iphone5 這樣的,要通過這樣的辦法。1.引入標頭檔案。in...

iOS 獲取手機裝置資訊

1,獲取裝置唯一識別符號 nsstring identifierstr uidevice currentdevice identifierforvendor uuidstring nslog 裝置唯一識別符號 identifierstr 裝置唯一識別符號 c2017f37 1c67 40a5 a35...

iOS獲得裝置相關資訊,獲取app相關資訊

裝置所有者名稱 device.name 裝置所有者名稱 nslog 裝置類別 device.model 裝置leibie nslog 本地化版本 device.localizedmodel 本地化版本 nslog 當前系統版本 device.systemversion 當期版本 nslog 當前系統...