記錄一下項目里面兩個 iPhoneX 適配的問題航闺。
1、整個APP 頂部和底部有黑色空白的區(qū)域榆浓。
原因:啟動頁面沒有適配iPhoneX
如圖:
解決辦法:添加iphone X啟動圖
//contents.json 圖片尺寸 1125 x 2436
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "2436h",
"filename" : "Default-2436h.png",
"minimum-system-version" : "11.0",
"orientation" : "portrait",
"scale" : "3x"
}
正常情況下的樣子:
2菩混、圖片尺寸太小導(dǎo)致圖片分層重疊
如圖:
分割線以上是完整的圖片,下面是多余的融求。這種情況只需要一個合適大小的圖片就行
ps:導(dǎo)航欄設(shè)置圖片也會出現(xiàn)這樣的情況咬像。
3、通過系統(tǒng)statusBar判斷網(wǎng)路狀態(tài)時生宛,導(dǎo)致Crash
解決方法:
+ (NSString *)currentNetworkType
{
NSArray *children;
UIApplication *app = [UIApplication sharedApplication];
NSString *state = [[NSString alloc] init];
//iPhone X
if ([[app valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
children = [[[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
for (UIView *view in children) {
for (id child in view.subviews) {
//wifi
if ([child isKindOfClass:NSClassFromString(@"_UIStatusBarWifiSignalView")]) {
state = @"wifi";
}
//2G 3G 4G
if ([child isKindOfClass:NSClassFromString(@"_UIStatusBarStringView")]) {
if ([[child valueForKey:@"_originalText"] containsString:@"G"]) {
state = [child valueForKey:@"_originalText"];
}
}
}
}
if (state.length <= 0) {
state = @"無網(wǎng)絡(luò)";
}
}else {
children = [[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
for (id child in children) {
if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
//獲取到狀態(tài)欄
switch ([[child valueForKeyPath:@"dataNetworkType"] intValue]) {
case 0:
state = @"無網(wǎng)絡(luò)";
//無網(wǎng)模式
break;
case 1:
state = @"2G";
break;
case 2:
state = @"3G";
break;
case 3:
state = @"4G";
break;
case 5:
state = @"wifi";
break;
default:
break;
}
}
}
}
return state;
}
如有不對的地方县昂,歡迎指出!