Summary of iOS 13 adaptation points

iOS 13 supports compatible models

  • iPhone X、iPhone XR、iPhone XS、iPhone XS Max
  • iPhone 8、iPhone 8 Plus
  • iPhone 7、iPhone 7 Plus
  • iPhone 6s、iPhone 6s Plus
  • iPhone SE
  • iPod touch (7th generation)

New feature adaptation

1. Dark Mode

iOS 13 introduces dark mode, UIKitprovides new system colors and api to adapt to different color modes, and xcassetsadjusts the material adaptation. For specific adaptation, see: Implementing Dark Mode on iOS
.

2. Sign In with Apple

Sign In with Apple will be available for beta testing this summer. It will be required as an option for users in apps that support third-party sign-in when it is commercially available later this year.

If your application supports the use of third-party login, you must add Apple's new login method:
Introducing Sign In with Apple . At present, Apple only mentions that it is required to be added when it is officially released on News and Updates , and the specific release time has not yet been determined.

API adaptation

1. Private method KVC is not allowed

In iOS 13 it is no longer allowed to use valueForKeyor setValue:forKey:other methods to get or set private properties. Although the compilation can pass, it will crash directly at runtime and prompt the crash information:

// 使用的私有方法
[_textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];

// 崩溃提示信息
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug' 

The solution can only be to use other methods:

// 替换的方案
_textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入"attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}]; 

2. The format obtained by the pushed deviceToken has changed

Could have direct NSDatatype deviceTokenis converted into NSStringa string, and then to replace the excess symbols:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSString *token = [deviceToken description];
    for (NSString *symbol in @[@" ", @"<", @">", @"-"]) {
        token = [token stringByReplacingOccurrencesOfString:symbol withString:@""];
    }
    NSLog(@"deviceToken:%@", token);
}

In iOS 13, this method is no longer valid, and NSDatathe converted string of the type deviceToken becomes:

{length = 32, bytes = 0xd7f9fe34 69be14d1 fa51be22 329ac80d ... 5ad13017 b8ad0736 } 

The need for a data processing format, reference League of Friends practices, old and new systems can be adapted to obtain as follows:

#include <arpa/inet.h>
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    if (![deviceToken isKindOfClass:[NSData class]]) return;
    const unsigned *tokenBytes = [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])];
    NSLog(@"deviceToken:%@", hexToken);
}

Engineering adaptation

1. UISearchBar black line processing causes a crash

In order to deal with the black line problem of the search box, it usually traverses the subViews of the searchBar, finds and deletes UISearchBarBackgroundit. Doing so in iOS13 will cause the UI rendering to fail and then directly crash. The crash information is as follows:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Missing or detached view for search bar layout'

The solution is to set UISearchBarBackgroundin layer.contentsas nil:

for (UIView *view in _searchBar.subviews.lastObject.subviews) {
    if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
        // [view removeFromSuperview];
        view.layer.contents = nil;
        break;
    }
} 

2. Using UISearchDisplayController causes a crash

Prior to iOS 8, we have UITableViewthe need to use a search box UISearchBar+ UISearchDisplayControllercombination, but after iOS 8, Apple has launched UISearchControllerinstead of the combination. In iOS 13, if you continue to use UISearchDisplayControllerwill directly lead to the collapse, crash information is as follows:

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'UISearchDisplayController is no longer supported when linking against this version of iOS. Please migrate your application to UISearchController.' 

In addition, in iOS 13 you can finally get the text box for direct access to search:

_searchBar.searchTextField.text = @"search";

3. Modal pop-up default interaction change

In UIModalPresentationStylethe definition of iOS 13 enumeration, Apple added a new enumeration value:

typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
    ...
    UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2,
}; 

In this enumeration value iOS 13 directly becomes the modal pop-up default, so presentViewControlleropened view parallax effect is as follows, the default is to return decline.

present.gif

 

The part of the page navigation bar that pops up modally is cut off, and you can also see in the storyboard that the content of the navigation bar will be obscured.

storyboard

If you need to make a full-screen display interface, you need to manually set the pop-up style:

- (UIModalPresentationStyle)modalPresentationStyle {
    return UIModalPresentationFullScreen;
} 

One thing to note is that we had a full-screen style pop-up page, this page will pop up that will in turn call ViewController viewWillDisappearand viewDidDisappear. When the page is then dismiss it will pop up that he's ViewController viewWillAppearand viewDidAppearwill be called in sequence. However, using the default parallax effect to pop up the page, the ViewController that popped it up does not call these methods. The code originally written in these four functions may have problems in the future.

4. UISegmentedControl default style change

The default style becomes black on a white background. If the color is changed, the page needs to be modified.

segment.png


Originally set up to select the color tintColorhas expired, added selectedSegmentTintColor attribute to modify the selected color.

 

5. MPMoviePlayerController is deprecated

Play video can be used before iOS 9 MediaPlayer.frameworkin MPMoviePlayerController class to complete, it supports local video and network video playback. However, it has been deprecated since iOS 9. If it continues to be used in iOS 13, an exception will be thrown directly:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.'

The solution is to use AVFoundationinside AVPlayer.

6. LaunchImage is deprecated

Before iOS 8, we were LaunchImagesetting up the launch map, but with the increasing size of Apple devices, we need to put all sizes of launch maps in the corresponding aseets, which is a very tedious step. Therefore, it was introduced by Apple in iOS 8. LaunchScreen.storyboardIt supports AutoLayout+ for interface layout SizeClass, which can be easily adapted to various screens.

launch screen

It should be noted that Apple mentioned in the Modernizing Your UI for iOS 13 section that
starting from April 2020, all apps that support iOS 13 must be provided LaunchScreen.storyboard, otherwise they will not be submitted to the App Store for approval.

7. The project created by Xcode 11 runs with a black screen on lower version devices

Use the project created by Xcode 11, select the device below iOS 13.0 as the running device, a black screen will appear when running the application. This is because Xcode 11 is created by default UISceneto manage multiple UIWindowapplications, in addition to project AppDelegateoutside will be one more SceneDelegate:

UIScene


This is to prepare a multi-process iPadOS, that UIWindowis no longer UIApplicationin management. But the old version did not UIScene, so the solution is in the AppDelegateheader file add:

 

@property (strong, nonatomic) UIWindow *window;

SDK adaptation

1. @availablecause older versions of Xcode compiler error.

In Xcode SDK project code which uses 11 @availableto determine the current system version, playing out of the bag on the compiler Xcode 10, an error will be about:

Undefine symbols for architecture i386:
    "__isPlatformVersionAtLeast", referenced from:
        ...
ld: symbol(s) not found for architecture i386

Error message from the point of view, is __isPlatformVersionAtLeastthe method no specific implementation, but there is no project in this method. The actual test wherever use @available, and use the Xcode 11 packaged into a DLL or static library, add the packaged library to the Xcode 10 compiler will this error, it can be judged iOS 13 of @availableimplementation used in the new api. If your SDK needs to adapt to the old version of Xcode, you need to avoid this method and judge by obtaining the system version:

if ([UIDevice currentDevice].systemVersion.floatValue >= 13.0) {
    ...
}

In addition, opening the SDK project on Xcode 10 should also be able to compile normally, which requires the addition of compilation macros for processing:

#ifndef __IPHONE_13_0
#define __IPHONE_13_0 130000
#endif

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
...
#endif

references

This article combines the content of the following documents and personal problems to summarize common adaptation problems

Guess you like

Origin blog.csdn.net/wangletiancsdn/article/details/101284170