iOS 13适配汇总(推荐)
随着iphone 11的发布,ios 13适配也提上了日程,接下来就开发中升级ios13的手机可能出现的问题
xcode: 11.0
ios : 13.0
uiviewcontroller 模态弹出界面
viewcontroller.present(presentvc, animated: true, completion: nil)
在调用模态弹出视图,会发现弹出的界面没有全屏。如图
通过多次的尝试,发现在低版本里面不会发生这种情况(ios12及以下),于是我查阅了最新的开发文档,发现了端倪,主要还是因为我们之前忽略了uiviewcontroller里面的一个属性,即:modalpresentationstyle
defines the presentation style that will be used for this view controller when it is presented modally. set this property on the view controller to be presented, not the presenter. if this property has been set to uimodalpresentationautomatic, reading it will always return a concrete presentation style. by default uiviewcontroller resolves uimodalpresentationautomatic to uimodalpresentationpagesheet, but other system-provided view controllers may resolve uimodalpresentationautomatic to other concrete presentation styles. defaults to uimodalpresentationautomatic on ios starting in ios 13.0, and uimodalpresentationfullscreen on previous versions. defaults to uimodalpresentationfullscreen on all other platforms. public enum uimodalpresentationstyle : int { case fullscreen @available(ios 3.2, *) case pagesheet @available(ios 3.2, *) case formsheet @available(ios 3.2, *) case currentcontext @available(ios 7.0, *) case custom @available(ios 8.0, *) case overfullscreen @available(ios 8.0, *) case overcurrentcontext @available(ios 8.0, *) case popover @available(ios 7.0, *) case none @available(ios 13.0, *) case automatic }
通过查看api 可以看到,ios 13 新增一个:automatic类型,默认情况下就是这个所以才会弹出不是全屏的界面。如果我们想要修改为全屏的话
可以:presentvc.modalpresentationstyle = .fullscreen设置为全屏即可
kvc 限制
ios13以后已经不能肆无忌惮的通过 kvc来修改一些没有暴露出来的属性了。
*** terminating app due to uncaught exception 'nsgenericexception', reason: 'access to xxx's _xxx ivar is prohibited. this is an application bug'
我们常用的有
// uitextfield 的 _placeholderlabel let textfield = uitextfield.init() textfield.setvalue(uicolor.red, forkey: "_placeholderlabel.textcolor") /// uisearchbar 的 _searchfield [searchbar valueforkey:@"_searchfield"]
下面方法替换
///分别设置字体大小和颜色(富文本) textfield.attributedplaceholder = nsattributedstring.init(string: "请输入....", attributes: [nsattributedstring.key.foregroundcolor: uicolor.red], [nsattributedstring.key.font: uifont.systemfont(ofsize: 15)]) /// uisearchbar 用 searchfield代替 bar.value(forkey: "searchfield") as! uitextfield
uisegmentedcontrol 默认样式改变
默认样式变为白底黑字,如果设置修改过颜色的话,页面需要修改
uitabbar
如果之前有通过tabbar上图片位置来设置红点位置,在ios13上会发现显示位置都在最左边去了。遍历uitabbarbutton的subviews发现只有在tabbar选中状态下才能取到uitabbarswappableimageview,解决办法是修改为通过uitabbarbutton的位置来设置红点的frame
app启动过程中,部分view可能无法实时获取到frame
// 只有等执行完 uiviewcontroller 的 viewdidappear 方法以后,才能获取到正确的值,在viewdidload等地方 frame size 为 0,例如: uiapplication.shared.statusbarframe
废弃uiwebview
查看api可以看到:ios 2.0 到 ios 11.0
在12.0就已经被废弃,部分app使用webview时, 审核被拒
@available(ios, introduced: 2.0, deprecated: 12.0, message: "no longer supported; please adopt wkwebview.") open class uiwebview : uiview, nscoding, uiscrollviewdelegate { ......... ......... ......... }
cncopycurrentnetworkinfo
ios13 以后只有开启了 access wifi information capability,才能获取到 ssid 和 bssid wi-fi or wlan 相关使用变更
最近收到了苹果的邮件,说获取wifi ssid的接口cncopycurrentnetworkinfo 不再返回ssid的值。不仔细看还真会被吓一跳,对物联网的相关app简直是炸弹。仔细看邮件还好说明了可以先获取用户位置权限才能返回ssid。
注意:目本身已经打开位置权限,则可以直接获取
- (nsstring*) getwifissid { if (@available(ios 13.0, *)) { //用户明确拒绝,可以弹窗提示用户到设置中手动打开权限 if ([cllocationmanager authorizationstatus] == kclauthorizationstatusdenied) { nslog(@"user has explicitly denied authorization for this application, or location services are disabled in settings."); //使用下面接口可以打开当前应用的设置页面 //[[uiapplication sharedapplication] openurl:[nsurl urlwithstring:uiapplicationopensettingsurlstring]]; return nil; } cllocationmanager* cllocation = [[cllocationmanager alloc] init]; if(![cllocationmanager locationservicesenabled] || [cllocationmanager authorizationstatus] == kclauthorizationstatusnotdetermined){ //弹框提示用户是否开启位置权限 [cllocation requestwheninuseauthorization]; usleep(50); //递归等待用户选选择 return [self getwifissidwithcallback:callback]; } } nsstring *wifiname = nil; cfarrayref wifiinterfaces = cncopysupportedinterfaces(); if (!wifiinterfaces) { return nil; } nsarray *interfaces = (__bridge nsarray *)wifiinterfaces; for (nsstring *interfacename in interfaces) { cfdictionaryref dictref = cncopycurrentnetworkinfo((__bridge cfstringref)(interfacename)); if (dictref) { nsdictionary *networkinfo = (__bridge nsdictionary *)dictref; nslog(@"network info -> %@", networkinfo); wifiname = [networkinfo objectforkey:(__bridge nsstring *)kcnnetworkinfokeyssid]; cfrelease(dictref); } } cfrelease(wifiinterfaces); return wifiname; }
同意打印:如下
network info -> { bssid = "44:dd:fb:43:91:ff"; ssid = "asus_c039"; ssiddata = <41737573 5f633033 39>; } 不同意 network info -> { bssid = "00:00:00:00:00:00"; ssid = wlan; ssiddata = <574c414e>; }
持续更新中…
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: iOs迁至WKWebView跨过的一些坑