服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - IOS - iOS 13适配汇总(推荐)

iOS 13适配汇总(推荐)

2021-05-27 16:22仰望星空01 IOS

这篇文章主要介绍了iOS 13适配汇总,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

随着iphone 11的发布,ios 13适配也提上了日程,接下来就开发中升级ios13的手机可能出现的问题

xcode: 11.0
ios : 13.0

uiviewcontroller 模态弹出界面

viewcontroller.present(presentvc, animated: true, completion: nil)

在调用模态弹出视图,会发现弹出的界面没有全屏。如图

iOS 13适配汇总(推荐)

通过多次的尝试,发现在低版本里面不会发生这种情况(ios12及以下),于是我查阅了最新的开发文档,发现了端倪,主要还是因为我们之前忽略了uiviewcontroller里面的一个属性,即:modalpresentationstyle

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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'

我们常用的有

?
1
2
3
4
5
6
// uitextfield 的 _placeholderlabel
    let textfield = uitextfield.init()
    textfield.setvalue(uicolor.red, forkey: "_placeholderlabel.textcolor")
    
    /// uisearchbar 的 _searchfield
    [searchbar valueforkey:@"_searchfield"]

下面方法替换

?
1
2
3
4
5
///分别设置字体大小和颜色(富文本)
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

?
1
2
// 只有等执行完 uiviewcontroller 的 viewdidappear 方法以后,才能获取到正确的值,在viewdidload等地方 frame size 为 0,例如:
 uiapplication.shared.statusbarframe

废弃uiwebview

查看api可以看到:ios 2.0 到 ios 11.0
在12.0就已经被废弃,部分app使用webview时, 审核被拒

?
1
2
3
4
5
6
@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。
注意:目本身已经打开位置权限,则可以直接获取

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
- (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;
}

同意打印:如下

?
1
2
3
4
5
6
7
8
9
10
11
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>;
}

持续更新中…

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/weixin_38735568/article/details/100850524

延伸 · 阅读

精彩推荐
  • IOSiOS常见的几个修饰词深入讲解

    iOS常见的几个修饰词深入讲解

    这篇文章主要给大家介绍了关于iOS常见的几个修饰词的相关资料,iOS修饰词包括assign、weak、strong、retain、copy、nonatomic、atomic、readonly、readwrite,文中通过示...

    郡王丶千夜7422021-05-10
  • IOSiOS逆向教程之logify跟踪方法的调用

    iOS逆向教程之logify跟踪方法的调用

    这篇文章主要给大家介绍了关于iOS逆向教程之logify跟踪方法调用的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学...

    Mr.Guo11472021-04-28
  • IOSIOS网络请求之AFNetWorking 3.x 使用详情

    IOS网络请求之AFNetWorking 3.x 使用详情

    本篇文章主要介绍了IOS网络请求之AFNetWorking 3.x 使用详情,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    总李写代码6892021-03-04
  • IOSiOS10 Xcode8适配7个常见问题汇总

    iOS10 Xcode8适配7个常见问题汇总

    这篇文章主要为大家详细汇总了iOS10 Xcode8适配7个常见问题,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    索马里猫10332021-02-01
  • IOSiOS中时间与时间戳的相互转化实例代码

    iOS中时间与时间戳的相互转化实例代码

    这篇文章主要介绍了iOS中时间与时间戳的相互转化实例代码,非常具有实用价值,需要的朋友可以参考下。...

    张无忌!4812021-03-09
  • IOSiOS APP实现微信H5支付示例总结

    iOS APP实现微信H5支付示例总结

    这篇文章主要介绍了iOS APP实现微信H5支付示例总结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下...

    一张小A11332021-06-01
  • IOSxcode8提交ipa失败无法构建版本问题的解决方案

    xcode8提交ipa失败无法构建版本问题的解决方案

    xcode升级到xcode8后发现构建不了新的版本。怎么解决呢?下面小编给大家带来了xcode8提交ipa失败无法构建版本问题的解决方案,非常不错,一起看看吧...

    Cinna丶7542021-02-03
  • IOS谈一谈iOS单例模式

    谈一谈iOS单例模式

    这篇文章主要和大家谈一谈iOS中的单例模式,单例模式是一种常用的软件设计模式,想要深入了解iOS单例模式的朋友可以参考一下...

    彭盛凇11872021-01-19