“This is the second day of my participation in the First Challenge 2022, for more details: First Challenge 2022”.
Record the compatibility points of each iOS system version
Sort out the adaptation version of each iOS system, the following article is only for record sorting, some are encountered by the author, some are reference online sorting, because some adaptation point I did not use, so there is no actual adaptation, it is best to meet the point of their own verification.
Points to be adapted for iOS11
1. In ios11, a new left-swipe deletion method is added to support images and text styles
// Swipe actions // These methods supersede -editActionsForRowAtIndexPath: if implemented // return nil to get the default swipe actions - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE (ios (11.0)) API_UNAVAILABLE (tvos); - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView TrailingSwipeActionsConfigurationForRowAtIndexPath: (NSIndexPath *) indexPath API_AVAILABLE (ios (11.0)) API_UNAVAILABLE(tvos);Copy the code
2. UIScrollView, UITableView, UICollectionView navigation offset problem
Scroll view when obstructed by Navigation, TabBar contentInset attribute of the system default will modify the scroll view, if the user set the scroll view contentInsetAdjustmentBehavior attributes to. Never, then the system will not do the related processing. Generally, we handle the layout of the scroll view frame by ourselves. By default, the scroll view is under the navigation bar and on the TabBar, so we need to write both
tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
Copy the code
IOS12 needs to fit points
Library not found for -lstdc++.6.0.9
Apple removed the libstdc++ library in Xcode10 and iOS 12 and replaced it with the libc++ library
Solution:
You can either delete that library or copy -lstdc++.6.0.9 from Xcode9 to Xcode10
// Xcode 10: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes /iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/ Xcode 11: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes / iOS simruntime/Contents/Resources/RuntimeRoot/usr/lib / / / / real machine /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/Copy the code
2. IOS 12WiFi
To obtainSSID
(wifi name) andBSSID
(MAC address) Failed
IOS 12 failed to obtain SSID(WiFi name) and BSSID(MAC address) for WiFi. After iOS 12, Apple improved the permission control for obtaining WiFi name and MAC address. To obtain these information, you need to manually enable the permission for obtaining WiFi information for the application. For details, see Obtaining the WiFi Name and MAC Address of an iOS Device + Obtaining iOS12 Failed. Solution:
In the developer account, check the Access WiFi Infomation option of the App ID of the project; In Xcode’s Capabilities, check the Access WiFi Infomation option for your project.
3. After the webView returns from playing the video, the status bar disappears
The UIStatusBar is still hidden when the main window becomes the KeyWindow after the video is played. Solution:
- (void) videoPlayerFinishedToShowStatusBar {the if (@ the available (iOS 12.0, *)) { [[NSNotificationCenter defaultCenter] addObserverForName:UIWindowDidBecomeKeyNotification object:self.window queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) { [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; }]; }}Copy the code
IOS13 needs to fit points
1. Adaptation of dark mode
IOS13 has added dark mode. If dark mode is prohibited in a project, it needs to be displayed in info.plist
Add, otherwise the system control background color in the project will change to black background under dark theme.
2. Modal pop-up full screen and card style
IOS13 modal pop-up mode is not full screen style, if you need a modal are still iOS13 before style, need to add the vc. ModalPresentationStyle = UIModalPresentationFullScreen; So the modal pops up just like before.
3. Sign In with Apple
If your application includes three-way login, such as QQ, wechat… , your app must include an AppID login, or your app will be rejected.
4. Modification of private properties
In iOS 13, it is no longer allowed to use valueForKey, setValue:forKey: and other methods to obtain or set private attributes. Although the compilation can pass, it will crash directly at run time, with a crash message
/ / / using a private method [self. 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'Copy the code
alternative
/ / / modify the placeholder UITextField at font size and color NSMutableAttributedString * arrStr = [[NSMutableAttributedString alloc]initWithString:self.valueTextField.placeholder attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0xD8D8D8),NSFontAttributeName:UIDEFAULTFONTSIZE(12)}]; self.valueTextField.attributedPlaceholder = arrStr;Copy the code
In general, try not to access private properties of the system in a project, and if so, add a classification swap KVC method to handle the breakdown points in the KVC’s underlying traversal access key logic
5. Black line processing problem of UISearchBar
In order to deal with the problem of black lines in the search box, the searchBar subViews were usually traversed to find and delete the UISearchBarBackground.
Doing so in iOS13 will cause UI rendering to fail and then crash, with the following crash message:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Missing or detached view for search bar layout'
Copy the code
Black lines can be handled in the following way
[searchBar setBackgroundImage:[UIImage new]];
Copy the code
6. LaunchImage is deprecated
Before iOS 8, we used LaunchImage to set the startup image. Whenever Apple launched a device with a new screen size, we needed to put the startup image of the corresponding size into assets, which was a very tedious step. So in iOS 8, Apple introduced LaunchScreen, which allows you to set up the launch interface directly in the Storyboard, making it easy to adapt to different screens.
In the Modernizing Your UI for iOS 13 section, apple says that starting in April 2020, all apps that support iOS 13 must provide launchscreen.storyboard. Otherwise, it will not be submitted to the App Store for approval.
Use launchscreen. storyboard to set up the launch page and discard LaunchImage.
IOS14 needs to be adapted
1. Photo Permission Added the permission to select a photo
In iOS14, select photo permission allows the user to allow the application to access some photos.
2. UITableView contentView
In iOS14, controls on the UITableViewCell are added directly to the cell, and click events are blocked by the contentView, so controls on the cell need to be added to self.contentview regardless of whether there are click events.
3. The OBTAINING unique identifier API is invalid
In iOS13 and before, the system will enable the setting of allowing tracking for users by default. We can simply obtain the user’s IDFA identifier through the code.
if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
NSString *idfaString = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
NSLog(@"%@", idfaString);
}
Copy the code
After iOS 14, AD tracking will be disabled by default, and the above method for determining whether to enable it has been deprecated.
Solution: Need we need the Info. That is configured in the plist “` NSUserTrackingUsageDescription” and describe the copy, Then use in the framework of ATTrackingManager AppTrackingTransparency requestTrackingAuthorizationWithCompletionHandler request user permissions, Only after the user is authorized to access IDFA can the correct information be obtained.
#import <AppTrackingTransparency/AppTrackingTransparency.h> #import <AdSupport/AdSupport.h> - (void)testIDFA { if (@available(iOS 14, *)) { [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { if (status == ATTrackingManagerAuthorizationStatusAuthorized) { NSString *idfaString = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString; } }]; } else {// use the original way to access IDFA}}Copy the code
4. Locate the fault
In iOS13 and before, when an App requests a user’s location authorization, it follows the following pattern: once the user agrees that the App can obtain location information, the current App can obtain the user’s precise location.
IOS14 new user location options available for users to choose. The switch for Precise is selected by default in iOS14. This switch allows users to make changes. When set to On, the map shows the exact location. When switched to Off, the user’s approximate location is displayed.
For apps that are not highly sensitive to the user’s location, this seems to have no effect, but it is very important for App adaptation that strongly relies on accurate location. Precise location can be turned on by users in “privacy Settings,” but it is possible that users would rather not use the app than turn it on. At this point, iOS14 has two new methods in CLLocationManager that can be used to request users to temporarily enable a precise location.
5. Camera and recording
In iOS14, apps will have ICONS and green and yellow dots when using the camera and microphone, and it will show you which App is currently using this feature. We have no control over whether the prompt is displayed.
6. Disable the KVC method
As with iOS 13, UITextField disallows setValue:forKey: When an overlay Label is set, iOS 14 UIPageControl also disables setValue for _pageImage and _currentPageImage. Otherwise the runtime will crash.
Points to be adapted for iOS15
1. The background color of the iOS navigation bar is invalid
2. IOS TabBar handles the same as NavigationBar
3. Add TopPadding height to UITableView
As of iOS 15, I’m going to add sectionHeaderTopPadding, TableView if it’s plain, once I implement viewForHeaderInSection and heightForHeaderInSection, If sectionHeaderTopPadding is not set to 0, the sectionHeaderTopPadding is 22 pixels high by default. Generally we need to prohibit.
4. UIImageWriteToSavedPhotosAlbum
In iOS15 UIImageWriteToSavedPhotosAlbum stored images after the callback is no longer return to the images, returns nil.
UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:), NULL);
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
}
Copy the code
conclusion
Sort out these for the time being, and replenish them later.
Refer to the link
Lstdc++ 6.0.9 adaptation
IOS12 adaptation and compatibility problems are resolved
IOS14 privacy adaptation and part of the solution
IOS 14 adaptation
IOS15 adaptation is related