Implementation method of ios13 adaptation


1. Private KVC

[self setValue:baseTabBar forKey:@"tabBar"]; // normal

[_textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];/// collapse
[_textField setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];/// collapse

_ Textfield. Attributedplaceholder = [[nsattributedstring alloc] initwithstring: @ "name" attributes: @ {nsfontattributename: [UIFont systemfontofsize: 14], nsforegroundcolorattributename: [uicolor redcolor]}]/// New implementation

Compiling on xcode10 will not be a problem, but compiling on xcode11 will crash. And – (void) setValue: (nullable ID) value forkey: (nsstring *) key method is OK, – (void) setValue: (nullable ID) value forkeypath: (nsstring *) keypath will crash

2. Problems with presentviewcontroller

This is mainly because we did not set the required type for a property in uiviewcontroller, that is, modalpresentationstyle (which is the style to be used by the controller in modal view). In ios13, the default of modalpresentationstyle is changed to uimodalpresentationautomatic, while the previous default is uimodalpresentationfullscreen.

This is not affected by the Xcode version. As long as the IOS 13 system does not explicitly set the modal presentation style, this problem will occur

3. Launchimage to be discarded

Since IOS 8, Apple has introduced launchscreen. We can set launchscreen as the startup page. Of course, now you can also use launchimage to set the startup diagram. However, using launchimage requires us to provide startup diagrams of various screen sizes to adapt to various devices. With the increasing size of Apple devices, this method is obviously not flexible enough. If you use launchscreen, the situation will become very simple. Launchscreen supports AutoLayout + sizeclass, so it’s no problem to adapt to various screens. Attention ⚠️, Starting from April 2020, launchscreen must be provided for all apps that enable the ios13 SDK, and launchimage will soon exit the stage of history

4. Dark mode


1. Create two modes of styles for the same resource. The system automatically obtains the resources of the style according to the currently selected style
2. Every time the system updates the style, the application will call all existing elements, call some corresponding redrawing methods, and redraw the view. You can make corresponding changes in the corresponding methods

Resource file adaptation

1. Create an assets file (or in an existing assets file)
2. Create a new picture resource file (or color resource file or other resource file)
3. Select the resource file, open the Xcode – > View – > inspectors – > show attributes inspectors (or option + Command + 4) view, and change the occurrences option to any, dark
4. After step 3, the resource file will have multiple container boxes, which are any appearance and dark appearance. Any appearance is applied to unspecified and light, and dark appearance is applied to dark mode
5. When the code is executed by default, it can be used normally by name, and the system will automatically obtain the corresponding resource file according to the current mode

be careful

After multiple assets files in the same project are packaged, an file will be generated. Therefore, ensure that the names of resource files in assets cannot be the same






Global turn off dark mode

Mode 1   Configuration plist file: in the info.plist file, add uiuserinterfacestyle key with the name of user interface style and the value of string, and set the value of uiuserinterfacestyle key to light

During development, if the system controls used (such as the background color of cell and tableview) are not set with the background color (or transparent), the background color of the controls will turn black after entering the dark mode.

Each page can be set, and of course, the whole can be set,

Generally, our app is under one window, so set the window in the app as a whole

Mode 2: the code closes the dark mode and forcibly closes the dark mode

#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if(@available(iOS 13.0,*)){
self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;

A single interface does not follow the dark mode

  • Both uiviewcontroller and uiview add an attribute overrideuserinterfacestyle
  • If overrideuserinterfacestyle is set to the corresponding mode, the element and its child elements are forcibly restricted to be displayed in the set mode and do not change with the change of system mode
    • Setting this property of viewcontroller will affect the view and child view controllers of the view controller to adopt this style
    • Setting this property of view will affect the view and all its sub views to adopt this style
    • Setting this property of window will affect the style of all contents in the window, including the root view controller and all presentation controllers (uipresentationcontroller) that display contents in the window

IOS adaptation dark mode:

5. Add permission application for always using Bluetooth

Cbcentralmanager, before ios13, can be used directly when using Bluetooth without permission prompt. After ios13, you will be prompted when using it again.

Added in info.plist

< string > we should always use your Bluetooth. Don't ask me what to do`

6. Use different methods of handling nsnull in mjextention

This will directly lead to crash. When converting the server data dictionary into a model, if the data given by the server is nsnull,
mj_ Jsonobject, where class_ There is an efsqlbinding type in the properties obtained by the copypropertylist method, and the number of properties is not accurate, so there is no way. I can only rewrite this method. When this component is not updated, I write a method swizzling to turn it directly to nil when nsnull is encountered.

7. Change the method of measuring the height of page content in wkwebview

Before IOS 13

In IOS 13
The difference of 55 should be that the browser definition height has changed

8. Push the Youmeng message and obtain the devicetoken adapter

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
 if (![deviceToken isKindOfClass:[NSData class]]) return;
  const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
  NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),ntohl(tokenBytes[6]),ntohl(tokenBytes[7])];
  pushDeviceToken = hexToken;

9. The statusbar is different from the previous version

At present, a mode has been added to the status bar, from the previous two to three. Default changes from the previous black content to automatically select whether to display lightcontent or darkcontent according to the system mode

10. Crash caused by fishhook(

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.