1.自定义导航栏按钮,设置了按钮frame,但是如果按钮图片本身大小比按钮大,导航栏的按钮就会被撑开,如下图

解决方法:
[leftBtn.widthAnchor constraintEqualToConstant: 20 ].active = YES;
[leftBtn.heightAnchor constraintEqualToConstant: 20].active = YES;

2.IphoneX 网络类型获取报错
一直以来都是通过以下这种方式进行网络方式的获取
UIApplication * app = [UIApplication sharedApplication];
NSArray * subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
在ios11系统除IPhoneX上都能正常运行,在iphoneX报错如下:
this class is not key value coding-compliant for the key foregroundView.'

解决方式:
其实打断点一层一层的点击查看,可以看出在iphoneX上的statusBar上下又套了一层,所以在没有取到的时候再取一次就可以了
if ([[app valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
subviews = [[[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
} else {
subviews = [[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
}

最后想说一点就是:其实网络方式的获取最好更换成苹果官方演示demo的方式,这样才能确保不会出现问题;方法如下:
点击这个链接,然后点击Download Sample Code下载整个代码,将下载的demo中的Reachability.h和.m复制到自己的项目中,再导入SystemConfiguration.framework框架,导入步骤:点击项目名-Build Phases-展开Link Binary With Libraries-点击加号,找到这个框架添加即可;框架添加完毕后在自己需要的文件中import Reachability.h,代码如下:
+(void)dataNetworkTypeFromStatusBar{
Reachability *reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
NetworkStatus internetStatus = [reachability currentReachabilityStatus];
NSString *net = @"WIFI";
switch (internetStatus) {
case ReachableViaWiFi:
net = @"WIFI";
[UserDefault setInteger:1 forKey:NetOfKey];
break;
case ReachableViaWWAN:
net = @"蜂窝数据";
[UserDefault setInteger:1 forKey:NetOfKey];
//net = [self getNetType]; //判断具体类型
break;
case NotReachable:
net = @"无网络";
[UserDefault setInteger:0 forKey:NetOfKey];
default:
break;
}
}
如果想要判断网络的具体类型就要用到CoreTelephony.framework框架,还按照上面的步骤导入这个框架,然后在需要用的地方#import <CoreTelephony/CTTelephonyNetworkInfo.h>
具体代码如下:
+ (NSString *)getNetType
{
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
NSString *currentStatus = info.currentRadioAccessTechnology;
NSString *netconnType = @"4G";
if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyGPRS"]) {
netconnType = @"GPRS";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyEdge"]) {
netconnType = @"2.75G EDGE";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyWCDMA"]){
netconnType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyHSDPA"]){
netconnType = @"3.5G HSDPA";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyHSUPA"]){
netconnType = @"3.5G HSUPA";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMA1x"]){
netconnType = @"2G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORev0"]){
netconnType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevA"]){
netconnType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevB"]){
netconnType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyeHRPD"]){
netconnType = @"HRPD";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyLTE"]){
netconnType = @"4G";
}
return netconnType;
}