iPhone X機型判斷

2021-09-14 01:13:16 字數 3935 閱讀 3908

兩種方法判斷iphone的機型:

一、根據螢幕高度判斷

swift版本:

switch uiscreen.main.nativebounds.height 

}

objective c版本:

switch ((int)[[uiscreen mainscreen] nativebounds].size.height) 

}

二、根據sys/utsname.h的uname獲得的型號數字判斷

swift版本:

var modelname: string 

return identifier + string(unicodescalar(uint8(value)))

}return identifier

}}使用uidevice.current.modelname獲得手機型號

objective c版本:

nsstring* devicename()

輸出的結果及型號對應如下:

//simultor

@"i386" on 32-bit simulator

@"x86_64" on 64-bit simulator

//iphone

@"iphone1,1" on iphone

@"iphone1,2" on iphone 3g

@"iphone2,1" on iphone 3gs

@"iphone3,1" on iphone 4 (gsm)

@"iphone3,3" on iphone 4 (cdma/verizon/sprint)

@"iphone4,1" on iphone 4s

@"iphone5,1" on iphone 5 (model a1428, at&t/canada)

@"iphone5,2" on iphone 5 (model a1429, everything else)

@"iphone5,3" on iphone 5c (model a1456, a1532 | gsm)

@"iphone5,4" on iphone 5c (model a1507, a1516, a1526 (china), a1529 | global)

@"iphone6,1" on iphone 5s (model a1433, a1533 | gsm)

@"iphone6,2" on iphone 5s (model a1457, a1518, a1528 (china), a1530 | global)

@"iphone7,1" on iphone 6 plus

@"iphone7,2" on iphone 6

@"iphone8,1" on iphone 6s

@"iphone8,2" on iphone 6s plus

@"iphone8,4" on iphone se

@"iphone9,1" on iphone 7 (cdma)

@"iphone9,3" on iphone 7 (gsm)

@"iphone9,2" on iphone 7 plus (cdma)

@"iphone9,4" on iphone 7 plus (gsm)

@"iphone10,1" on iphone 8 (cdma)

@"iphone10,4" on iphone 8 (gsm)

@"iphone10,2" on iphone 8 plus (cdma)

@"iphone10,5" on iphone 8 plus (gsm)

@"iphone10,3" on iphone x (cdma)

@"iphone10,6" on iphone x (gsm)

//ipad 1

@"ipad1,1" on ipad - wifi (model a1219)

@"ipad1,1" on ipad - wifi + cellular (model a1337)

//ipad 2

@"ipad2,1" - wifi (model a1395)

@"ipad2,2" - gsm (model a1396)

@"ipad2,3" - 3g (model a1397)

@"ipad2,4" - wifi (model a1395)

// ipad mini

@"ipad2,5" - wifi (model a1432)

@"ipad2,6" - wifi + cellular (model a1454)

@"ipad2,7" - wifi + cellular (model a1455)

//ipad 3

@"ipad3,1" - wifi (model a1416)

@"ipad3,2" - wifi + cellular (model a1403)

@"ipad3,3" - wifi + cellular (model a1430)

//ipad 4

@"ipad3,4" - wifi (model a1458)

@"ipad3,5" - wifi + cellular (model a1459)

@"ipad3,6" - wifi + cellular (model a1460)

//ipad air

@"ipad4,1" - wifi (model a1474)

@"ipad4,2" - wifi + cellular (model a1475)

@"ipad4,3" - wifi + cellular (model a1476)

// ipad mini 2

@"ipad4,4" - wifi (model a1489)

@"ipad4,5" - wifi + cellular (model a1490)

@"ipad4,6" - wifi + cellular (model a1491)

// ipad mini 3

@"ipad4,7" - wifi (model a1599)

@"ipad4,8" - wifi + cellular (model a1600)

@"ipad4,9" - wifi + cellular (model a1601)

// ipad mini 4

@"ipad5,1" - wifi (model a1538)

@"ipad5,2" - wifi + cellular (model a1550)

//ipad air 2

@"ipad5,3" - wifi (model a1566)

@"ipad5,4" - wifi + cellular (model a1567)

// ipad pro 12.9"

@"ipad6,3" - wifi (model a1673)

@"ipad6,4" - wifi + cellular (model a1674)

@"ipad6,4" - wifi + cellular (model a1675)

//ipad pro 9.7"

@"ipad6,7" - wifi (model a1584)

@"ipad6,8" - wifi + cellular (model a1652)

//ipod touch

@"ipod1,1" on ipod touch

@"ipod2,1" on ipod touch second generation

@"ipod3,1" on ipod touch third generation

@"ipod4,1" on ipod touch fourth generation

@"ipod7,1" on ipod touch 6th generation

Unity判斷機型iPad iPhone

public static bool ispad else if type.substring 0 3 ipa else 參考鏈結 同時適配ipad和iphone,記得修改 other setting target device iphone ipad 弄乙個豎屏小遊戲,在iphone上對寬適配比較...

iPhone X全屏適配

當你的專案執行於iphone x模擬器的時候是否會出現以下這種情況?不能全屏,上下出現了大黑邊,受到以前在設定了啟動頁,把啟動頁刪除出現的上下黑框的啟發,於是想到只要給給iphone x設定乙個對應的啟動頁,就會實現全屏顯示。實現方法如下,首先開啟launchimage 我這裡啟動頁使用的launc...

IPHONE X前端適配

cover 使頁面佔滿螢幕。auto 和 contain 選項表現一樣 safe area inset left 安全區域距離左邊邊界距離 safe area inset right 安全區域距離右邊邊界距離 safe area inset top 安全區域距離頂部邊界距離 safe area in...