iOS 13适配汇总(推荐)

 更新时间:2019年09月19日 10:13:56   作者:仰望星空01  
这篇文章主要介绍了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中监听UITextField值改变事件的方法实例

    iOS中监听UITextField值改变事件的方法实例

    UITextField 是一个用来处理文本输入和现实的控件,在我们的开发当中也是经常被用到。下面这篇文章主要给大家介绍了关于iOS中监听UITextField值改变事件的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下
    2018-07-07
  • 详解iOS Method Swizzling使用陷阱

    详解iOS Method Swizzling使用陷阱

    这篇文章主要介绍了详解iOS Method Swizzling使用陷阱,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-11-11
  • 清除WKWebView cookies的方法

    清除WKWebView cookies的方法

    下面小编就为大家带来一篇清除WKWebView cookies的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-04-04
  • ajax 三种实现方法实例代码

    ajax 三种实现方法实例代码

    这篇文章主要介绍了ajax 三种实现方法实例代码的相关资料,需要的朋友可以参考下
    2016-09-09
  • 详解iOS自定义UITabBar与布局

    详解iOS自定义UITabBar与布局

    本篇文章给大家详细分析了iOS自定义UITabBar与布局的实际操作过程以及相关代码分享,一起学习下。
    2018-02-02
  • 详解Xcode 9 设置 iOS无线真机调试

    详解Xcode 9 设置 iOS无线真机调试

    本篇文章主要介绍了详解Xcode 9 设置 iOS无线真机调试,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-12-12
  • iOS实现MJRefresh下拉刷新(上拉加载)使用详解

    iOS实现MJRefresh下拉刷新(上拉加载)使用详解

    本篇文章主要介绍了iOS实现MJRefresh下拉刷新(上拉加载)使用详解,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
    2017-01-01
  • ios的collection控件的自定义布局实现与设计

    ios的collection控件的自定义布局实现与设计

    这篇文章主要介绍了mac、iOS端支持自定义布局的collection控件的实现与设计,需要的朋友学习参考下吧。
    2017-12-12
  • IOS 指纹识别两种方式详解及实例

    IOS 指纹识别两种方式详解及实例

    这篇文章主要介绍了IOS 指纹识别两种方式详解及实例的相关资料,需要的朋友可以参考下
    2017-06-06
  • IOS开发自定义Button的外观和交互行为示例详解

    IOS开发自定义Button的外观和交互行为示例详解

    这篇文章主要为大家介绍了IOS开发自定义Button的外观和交互行为示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-02-02

最新评论