IOS 13 adaptation summary (recommended)

Time:2021-9-15

With the release of iPhone 11, IOS 13 adaptation has also been put on the agenda. Next, there are possible problems in developing and upgrading IOS 13 phones

Xcode: 11.0
iOS : 13.0

Uiviewcontroller modal pop-up interface

viewController.present(presentVC, animated: true, completion: nil)

When calling the modal pop-up view, you will find that the pop-up interface does not have a full screen. As shown in the figure

模态弹出界面

After many attempts, it was found that this would not happen in the lower version(iOS12And below), so I checked the latest development documents and found clues, mainly because we ignored it beforeUIViewControllerOne of the attributes is: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
}

By viewing the API, you can see that IOS 13 adds a new one:automaticType. This is the default, so the interface that is not full screen will pop up. If we want to change it to full screen

sure:presentVC.modalPresentationStyle = .fullScreenSet to full screen

KVC restrictions

After ios13, you can’t wantonly modify some unexposed attributes through KVC.

*** Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘Access to xxx’s _xxx ivar is prohibited. This is an application bug’

We often use

//Of uitextfield_ placeholderLabel
    let textField = UITextField.init()
    textField.setValue(UIColor.red, forKey: "_placeholderLabel.textColor")
    
    ///Of UISearchBar_ searchField
    [searchBar valueForKey:@"_searchField"]

Replace with the following method

///Set font size and color separately (rich text)
Textfield.attributedplaceholder = nsattributedstring.init (string: "please enter...", attributes: [nsattributedstring. Key. Foregroundcolor: uicolor. Red], [nsattributedstring. Key. Font: UIFont. Systemfont (ofsize: 15)])

 ///UISearchBar is replaced by searchfield
bar.value(forKey: "searchField") as! UITextField

Uisegmentedcontrol default style change

The default style changes to black characters on a white background. If the color setting has been modified, the page needs to be modified

UITabbar

If you previously set the red dot position through the picture position on the tabbar, you will find that the display position is on the far left on ios13. Traversing the subviews of the uitabbarbutton, it is found that the uitabbarswapableimageview can be obtained only when the tabbar is selected. The solution is to modify it to set the frame of the red dot through the position of the uitabbarbutton

During app startup, some views may not be able to get the frame in real time

//The correct value can be obtained only after the viewdidappear method of uiviewcontroller is executed. In viewdidload and other places, the frame size is 0, for example:
 UIApplication.shared.statusBarFrame

Discard uiwebview

Viewing the API, you can see: IOS 2.0 to IOS 11.0
It has been abandoned since 12.0. When some apps use WebView, the audit is rejected


@available(iOS, introduced: 2.0, deprecated: 12.0, message: "No longer supported; please adopt WKWebView.")
open class UIWebView : UIView, NSCoding, UIScrollViewDelegate {
	.........
	.........
	.........
}

CNCopyCurrentNetworkInfo

After ios13, only when access WiFi information capability is enabled can we obtain the use changes related to SSID and BSSID Wi Fi or WLAN
Recently, I received an email from Apple saying that cncopycurrentnetworkinfo, the interface for obtaining WiFi SSID, will no longer return the value of SSID. If you don’t look carefully, you’ll be really surprised. It’s a bomb for apps related to the Internet of things. Looking at the email carefully, it shows that you can obtain the user location permission before returning the SSID.
Note: if the location permission has been opened, you can obtain it directly

- (NSString*) getWifiSsid {
  if (@available(iOS 13.0, *)) {
    //If the user explicitly refuses, a pop-up window can prompt the user to manually open the permission in the setting
    if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
      NSLog(@"User has explicitly denied authorization for this application, or location services are disabled in Settings.");
      //Use the following interface to open the settings page of the current application
      //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
      return nil;
    }
    CLLocationManager* cllocation = [[CLLocationManager alloc] init];
    if(![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined){
      //A pop-up box will prompt the user whether to enable location permission
      [cllocation requestWhenInUseAuthorization];
      usleep(50);
      //Recursively waiting for user selection
      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;
}

Agreed to print as follows:

network info -> {
BSSID = "44:dd:fb:43:91:ff";
SSID = "Asus_c039";
SSIDDATA = <41737573 5f633033 39>;
}
disagree
network info -> {
BSSID = "00:00:00:00:00:00";
SSID = WLAN;
SSIDDATA = <574c414e>;
}

Updating continuously

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.

Recommended Today

Method of replacing parameters with variables in SQL with too many parameters

There is a requirement in the work, which requires many parameters, such as the following SQL, Copy codeThe code is as follows: select ff.fundsc||’-‘||ff.fundtzfs||’-‘||ff.fundcjfl||’-‘||ff.fundonefl||’-‘||ff.fundtowfl catagory, sf. Scode, replace (SF. Fund5, ‘type securities investment fund’, ”) fund5, SF fund4,sf. fund10,(select to_date(tradedate,’yyyy-MM-dd’) from sdc_fundnetassetvalue where scode=sf.scode and tradedate in (select max(tradedate) from sdc_fundnetassetvalue where scode=sf.scode and to_date(tradedate,’yyyyMMdd’)>=(to_date(20120801,’yyyyMMdd’)-10) […]