uidevice提供了多種屬性、類函式及狀態通知,可以幫助我們全方位了解裝置狀況。從檢測電池電量到定位裝置與臨近感應,uidevice所做的工作就是為應用程式提供使用者及裝置的一些資訊。uidevice類還能夠收集關於裝置的各種具體細節,例如機型及ios版本等。其中大部分屬性都對開發工作具有積極的輔助作用。
使用uidevice獲取手機屬性:
//獲取手機資訊
nsstring *stringname =
[[uidevice currentdevice] name]
;nslog
(@"裝置名稱:%@"
,strname)
; nsstring *stringid =
[[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)
;//
bundle是乙個目錄,其中包含了程式會使用到的資源。 這些資源包含了如影象、聲音、編譯好的**、nib檔案(使用者也會把bundle稱為plug-in)。對應bundle,cocoa提供了類nsbundle。乙個應用程式看上去和其他檔案沒有什麼區別,但是實際上它是乙個包含了nib檔案,編譯**,以及其他資源的目錄。 我們把這個目錄叫做程式的main bundle。通過這個路徑可以獲取到應用的資訊,例如應用名、版本號等。
nsdictionary *dicinfo =
[[nsbundle mainbundle] infodictionary]
;// cfshow(dicinfo);
[dicinfo objectforkey:
@"cfbundledisplayname"];
nslog(;
[dicinfo objectforkey:
@"cfbundleshortversionstring"];
nslog(;
[dicinfo objectforkey:
@"cfbundleversion"];
nslog(;
nslocale可以獲取使用者的本地化資訊設定,例如貨幣型別,國家,語言,數字,日期格式的格式化,提供正確的地理位置顯示等等。下面的**獲取機器當前語言和國家**。
//獲取使用者當前使用的語言
nsarray *languagearray =
[nslocale preferredlanguages]
; nsstring *language =
[languagearray objectatindex:0]
;nslog
(@"語言:%@"
, language)
;//獲取使用者所在國家資訊
nslocale *locale =
[nslocale currentlocale]
; nsstring *country =
[locale localeidentifier]
;nslog
(@"國家:%@"
, country)
;
注意:
uidevice是無法獲得具體的裝置型號的,要獲得裝置型號,比如(iphone 4s, iphone5),要通過這樣的辦法:
引入標頭檔案:
#include #include
獲取型號:
// 手機型號
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"
;
iOS 之獲取APP與手機 資訊
nsdictionary infodictionary nsbundle mainbundle infodictionary cfshow cfbridgingretain infodictionary version版本 build版本 手機序列號 nsuuid identifiernumber ...
ios開發 獲取手機相關資訊
今天在做客戶端的時候,裡面有個意見反饋功能。呼叫系統帶的郵件功能,傳送郵件到指定郵箱。於是,學習了相關的知識,在這裡與大家分享。在次之前,補充個內容。uidevice是無法獲得具體的裝置型號的。要獲得裝置型號,比如 iphone 4s,iphone5 這樣的,要通過這樣的辦法。1.引入標頭檔案。in...
ios開發 獲取手機相關資訊
今天在做客戶端的時候,裡面有個意見反饋功能。呼叫系統帶的郵件功能,傳送郵件到指定郵箱。於是,學習了相關的知識,在這裡與大家分享。在次之前,補充個內容。uidevice是無法獲得具體的裝置型號的。要獲得裝置型號,比如 iphone 4s,iphone5 這樣的,要通過這樣的辦法。1.引入標頭檔案。in...