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

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中UILabel实现长按复制功能实例代码

    iOS中UILabel实现长按复制功能实例代码

    在iOS开发过程中,有时候会用到UILabel展示的内容,那么就设计到点击UILabel复制它上面展示的内容的功能,也就是Label长按复制功能,下面这篇文章主要给大...

    devilx12792021-04-02
  • IOSiOS开发技巧之状态栏字体颜色的设置方法

    iOS开发技巧之状态栏字体颜色的设置方法

    有时候我们需要根据不同的背景修改状态栏字体的颜色,下面这篇文章主要给大家介绍了关于iOS开发技巧之状态栏字体颜色的设置方法,文中通过示例代码...

    梦想家-mxj8922021-05-10
  • IOSiOS自定义UICollectionViewFlowLayout实现图片浏览效果

    iOS自定义UICollectionViewFlowLayout实现图片浏览效果

    这篇文章主要介绍了iOS自定义UICollectionViewFlowLayout实现图片浏览效果的相关资料,需要的朋友可以参考下...

    jiangamh8882021-01-11
  • IOSiOS实现控制屏幕常亮不变暗的方法示例

    iOS实现控制屏幕常亮不变暗的方法示例

    最近在工作中遇到了要将iOS屏幕保持常亮的需求,所以下面这篇文章主要给大家介绍了关于利用iOS如何实现控制屏幕常亮不变暗的方法,文中给出了详细的...

    随风13332021-04-02
  • IOSiOS中MD5加密算法的介绍和使用

    iOS中MD5加密算法的介绍和使用

    MD5加密是最常用的加密方法之一,是从一段字符串中通过相应特征生成一段32位的数字字母混合码。对输入信息生成唯一的128位散列值(32个字符)。这篇文...

    LYSNote5432021-02-04
  • IOSiOS中滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和Masonry简单使用)

    iOS中滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和

    这篇文章主要介绍了iOS中滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和Masonry简单使用)的相关资料,需要的朋友可以参考下...

    CodingFire13652021-02-26
  • IOS详解iOS中多个网络请求的同步问题总结

    详解iOS中多个网络请求的同步问题总结

    这篇文章主要介绍了详解iOS中多个网络请求的同步问题总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    liang199111312021-03-15
  • IOSiOS开发之视图切换

    iOS开发之视图切换

    在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单。在iOS开发中常用的视图切换有三种,今天我们将...

    执着丶执念5282021-01-16