1, the preface

For iOS 13, Apple has made a very big change, among which Dark mode is the latest visible change at the UI level, while iPadOS for iPad has led to the divergence from iOS, and at the same time, iOS has to make the same change for iPad. For example, an application supports multiple window displays. Therefore, after WWDC every year, because the situation of each application is different and the API used is different, the adaptation work is not consistent, and everyone encounters different pits. Therefore, the problems encountered by everyone are summed up, that is, there must be some effect, which is the original intention of this paper.

2. IOS 13 adaptation problems

1. How to turn off the dark mode in the program?

One of the biggest features of iOS13 is that it brings dark mode, but if it doesn’t work, you might get white where it should be black, black where it should be white, and you can’t see it, how do you turn it off?

  • 1.1 Code mode: It can be set for each page, of course, it can also be set as a whole. Generally, our APP is under a window, so set the window in the APP as a whole:
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
    if(@available(iOS 13.0, *)) {self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }
#endif
Copy the code
  • 1.2 Configuration File Mode: YesInfo.plistAdd the key:UIUserInterfaceStyleSet to force dark mode (Dark) or daytime mode (Light)

<key>UIUserInterfaceStyle</key>
<string>UIUserInterfaceStyleLight</string>
Copy the code
  • Implementing Dark Mode on iOS – WWDC 2019 – Videos – Apple Developer

Apple has yet to announce when it will force night mode. According to the previous official article, it is not mandatory for all apps to adapt, because some apps may indeed be difficult to adapt.

If you need more time to adjust the appearance of your app in dark mode, or if your app is not suitable for dark mode, you can learn more about disabling dark mode.

  • Get Ready for Dark Mode – News – Apple Developer

2. UIWebView deprecated

ITMS-90809: Deprecated API Usage – Apple will stop accepting submissions of apps that use UIWebView APIs . See Developer.apple.com/documentati… for more information.

UIWebView iOS 2.0 — 12.0 Deprecated Mac Catalyst 13.0 — 13.0 Deprecated

  • UIWebView – UIKit | Apple Developer Documentation

In December 2019 – updated

The App Store will no longer accept new apps using UIWebView as of April 2020 and app updates using UIWebView as of December 2020.

Apple has made it mandatory for new apps to no longer use UIWebView in April 2020, and for all app updates to no longer use UIWebView in December 2020.

  • Updating Apps that Use Web Views – News – Apple Developer

3. PresentViewController mode changes

After iOS13 Prensent way pop-up page, the default mode into the UIModalPresentationAutomatic, this way is also quite good, animation is good-looking, bring their own closed, as long as the drop-down close the page, the animation mode, The previous issue of UITabBar display confusion on iPhoneX Push is no longer available. But there are times when we don’t want to use this style, such as when the user can’t close it:

Just specify the modalPresentationStyle attribute for the pop-up page, noting the page to Present:

UIViewController *vc = [[UIViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController presentViewController:vc animated:YES completion:nil];
Copy the code

4. Add the permission application for “Always Using Bluetooth”

IOS 13, app info.plist added

<key>NSBluetoothAlwaysUsageDescription</key>
<string>We're gonna use your Bluetooth all the time, so don't ask me</string>
Copy the code

5. Change the way to measure the height of page content in WKWebView

IOS 13 before

document.body.scrollHeight 
Copy the code

IOS 13

document.documentElement.scrollHeight
Copy the code

The difference of 55 should be a change in browser definition height

6. UIActivityIndicatorView

The previous UIActivityIndicatorView had three styles whiteLarge, White, and Gray, now all obsolete. Add two styles, medium and large, and change the indicator color with the color attribute.

  • Implementing Dark Mode on iOS – WWDC 2019 – Videos – Apple Developer

7. Status Bar

Remove.default. lightContent and change it to:

! [iOS13 – the Status Bar. PNG] (github.com/iHTCboy/iGa… Bar.png)

8. Sign In with Apple

  • Updates to the App Store Review Guidelines – News – Apple Developer

Sign In with Apple will be available for beta testing this summer. It will be required as an option for users in apps Those who support third-party sign-in when it is commercially available later this year. Apple login will be in beta this summer. Apple login will be an option for apps that allow third-party users to log in when they go on sale later this year.

The API is used to retrieve information such as the user name, but the key userIdentifier is random (at least from our developer’s point of view), and this userIdentifier is held by only one app under the same developer account. In addition, Apple login is supported across platforms, Android and Windows web pages using Apple ID login authorization.

Note: Sign In with Apple requires the user to enable the two-step authentication. If it is not enabled, the user will be prompted to enable it for the first time. If it is not enabled, the user will not be able to use it.

In addition, the Apple login button has requirements, see Sign In with Apple – Sign In with Apple – Human Interface Guidelines-Apple Developer for details

Updated in September 2019

4.8 Login through Apple If the app exclusively uses third-party or social login services (for example, Facebook login, Google login, Twitter login, LinkedIn login, Amazon login or wechat login) to set it up or verify the main user account of the app, The app must also provide “Log in via Apple” as an equivalent option. A user’s primary account is the account established in the app for identification, login and access to functions and related services. The “Log in through Apple” option is not required when:

  • Your app only uses your company’s own account to set up and log in to the system.
  • Your app is an education, enterprise or business app that requires users to log in using an existing education or business account.
  • Your app uses a government – or industry-backed citizenship system or electronic ID card to authenticate users.
  • Your app is a client for certain third party services and users need to log in directly using their email, social media or other third party accounts to access content.
  • Update for guidance on “Log in through Apple” – News – Apple Developer
  • App Store Review Guide – Apple Developer

9. KVC restrictions

IOS 13 through KVC to modify private attributes, Crush risk, use caution! IOS13 will no longer be able to use KVC to modify properties that are not exposed. Error: ‘Access to UITextField’s _metaglabel ivar is prohibited. This is an application bug’

Known:

// placeholder color for UITextField
[textField setValue:[UIColor xxx] forKeyPath:@"_placeholderLabel.textColor"];
/ / UISearchBar _searchField
[searchBar valueForKey:@"_searchField"];
Copy the code

Modified as follows:

NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName : self.placeholderColor}];
_textField.attributedPlaceholder = placeholderString;
Copy the code

10. UISegmentedControl default style changes

The default style is black text on a white background. If the color has been changed, the page needs to be changed. The UI style has also changed.

11. During App startup, some Views may not be able to obtain the frame in real time

In order to optimize the startup speed (or leave the sea screen), some views may fail to obtain the correct frame in real time during App startup

// Only after executing the viewDidAppear method on UIViewController can we get the correct value. In viewDidLoad, the frame Size is 0, for example:
 [[UIApplication sharedApplication] statusBarFrame];
Copy the code

12. MPMoviePlayerController deprecated in iOS 13

Where MPMoviePlayerController is used, an exception is thrown directly:

'MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.'
Copy the code

The alternative is the AVKit player

13. IOS 13 DeviceToken is changed

This is important!! Probably most of the children who use third-party push will not notice this problem. Generally, the current third-party push is to throw in the original DeviceToken data, and the specific parsing is handled by the third party internally. Therefore, if these third parties parse DeviceToken correctly, there will be no problem. If you’re getting DeviceToken this way, be careful. (This pit was also planted many years ago, and many articles introduced the following method. Non-standard practices will be returned sooner or later), as follows:

NSString *dt = [deviceToken description];
dt = [dt stringByReplacingOccurrencesOfString: @ "<" withString: @ ""];
dt = [dt stringByReplacingOccurrencesOfString: @ ">" withString: @ ""];
dt = [dt stringByReplacingOccurrencesOfString: @" " withString: @ ""];
Copy the code

This code can no longer get the exact DeviceToken string when running on iOS 13. What iOS 13 gets from [DeviceToken Description] has changed.

{length = 32, bytes = 0x778a7995 29f32fb6 74ba8167 b6bddb4e ... b4d6b95f 65ac4587 }
Copy the code

Solution, FB SDK:

+ (NSString *)hexadecimalStringFromData:(NSData *)data
{
    NSUInteger dataLength = data.length;
    if (dataLength == 0) {
        return nil;
    }
    const unsigned char *dataBuffer = data.bytes;
    NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
    for (int i = 0; i < dataLength; ++i) {
        [hexString appendFormat:@"%02x", dataBuffer[i]];
    }
    return [hexString copy];
}
Copy the code

Umeng push solution

- (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])];
          NSLog(@"deviceToken:%@",hexToken); }}Copy the code

Which of these two methods is better? According to apple document application: didRegisterForRemoteNotificationsWithDeviceToken: :

Compatibility solutions for UmENG are not rigorous. Apple says Tokens are variable in length and do not hardcode them!!

More references: IOS13 PKPushCredentials broken | Apple Developer Forums facebook – objc – SDK/FBSDKInternalUtility. M [notice] iOS 13 after the official release of U – Push NotificationCenter, Issue # 23, the influence of ChenYilong/iOS13AdaptationTips

14. The soon-to-be-abandoned LaunchImage

Since iOS 8, apple has introduced the LaunchScreen, which we can set up as the LaunchScreen. Of course, now you can also use LaunchImage to set up the LaunchImage. With LaunchImage, however, we have to provide launch images of various screen sizes to fit all devices, which is obviously not Flexible enough as Apple devices get bigger and bigger. LaunchScreen supports AutoLayout+SizeClass, so it’s easy to fit all kinds of screens.

Note: starting in April 2020, all apps using the iOS13 SDK will be required to provide LaunchScreen, and the LaunchImage will be phased out.

As a bonus, if you’re using LaunchScreen, it’s best not to put images in Xcassets, otherwise you’ll find that they don’t work on the LaunchScreen.

15. App Delegate

IOS supports multiple user interfaces running at the same time. The view superview of the root view controller is not directly UIWindow:

IOS 13 allows multiple Windows Windows to separate the UI-related lifecycle to SceneDelegate:

If SceneDelegate is implemented then iOS 13 will adjust SceneDalegate, if not, it will use AppDelegate. IOS 12 still calls AppDelegate:

@property(nullable.nonatomic.readonly) UIWindow *keyWindow API_DEPRECATED("Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes", ios(2.0.13.0));
Copy the code

Get keyWindow using [UIApplicatoin sharedApplication].

  • 1. This interface is deprecated
  • 2. For the iPad, an app can open multiple Windows (for example, Office can open multiple Word documents). In this case, keyWindow has multiple scenes, not the only one.
  • 3. For iPhone, you can’t open multiple Windows at the same time. So the keyWindow is still unique, so it doesn’t affect fetching for now.

Without keyWindow, how do I get the window currently active? Take a look here: How to Resolve: ‘keyWindow’ was deprecated in iOS 13.0

See official WWDC: Architecting Your App for Multiple Windows-WWDC 2019-Videos – Apple Developer for details

16. – (BOOL)application: openURL: options: 中 SourceApplication 为 nil

Documentation prior to Xcode 11:

// value is an NSString containing the bundle ID of the originating application

After Xcode 11 becomes:

// value is an NSString containing the bundle ID of the originating application; non-nil if the originating application and this application share the same team identifier

Official online documentation:

UIApplicationOpenURLOptionsSourceApplicationKey A key that contains the bundle ID of the app that sent the open-URL request to your app.

The value of this key is an NSString object containing the bundle ID of the app that made the request. If the request originated from another app belonging to your team, UIKit sets the value of this key to the ID of that app. If the team identifier of the originating app is different than the team identifier of the current app, the value of the key is nil.

Application: openURL: options: (BOOL) Application: openURL: options: Will UIApplicationOpenURLOptionsSourceApplicationKey return is nil, that is to say, can get the original App bundle ID, about this everyone say apple in order to solve the problem of privacy?

For developers, if they use the SourceApplication field, they can only adjust their business logic above iOS 13.

  • iOS 13 beta 2, openURL, with SourceApplication … |Apple Developer Forums
  • iOS13 UIApplicationOpenURLOptionsSourceApplicat… |Apple Developer Forums
  • UIApplicationOpenURLOptionsSourceApplicationKey – UIKit | Apple Developer Documentation

conclusion

These are just common and summary of what you see on the web, and there are a lot of details that need to be fine-tuned for iOS13. Over the years, there have been a lot of mutations before iOS versions, and of course this has its benefits, For example, WKWebview supports iOS 8.0 +, SFSafariViewController supports iOS 9.0+, and over time, a lot of better apis are available for everyone to use, so it’s going to be like this for the future, We are API users! Strive to be the API man!

reference

  • IOS13 development adaptation – Jane book
  • WWDC2019 — Webview iOS13 adaptation
  • IOS13 Sign In With Apple – Small Rui’s Blog
  • Adapter iOS13 | Feng ‘s Notes
  • IOS 13 adaptation – Jane Book
  • ChenYilong/iOS13AdaptationTips: iOS13 AdaptationTips
  • Architecting Your App for Multiple Windows – WWDC 2019 – Videos – Apple Developer
  • Implementing Dark Mode on iOS – WWDC 2019 – Videos – Apple Developer
  • How to resolve: ‘keyWindow’ was deprecated in iOS 13.0
  • Usage Guidelines for Website and Other Platforms – Sign in with Apple – Apple Developer
  • App Store Review Guide – Apple Developer
  • Update for guidance on “Log in through Apple” – News – Apple Developer
  • Updating Apps that Use Web Views – News – Apple Developer
  • Get Ready for Dark Mode – News – Apple Developer
  • iOS 13 beta 2, openURL, with SourceApplication … |Apple Developer Forums
  • iOS13 UIApplicationOpenURLOptionsSourceApplicat… |Apple Developer Forums
  • UIApplicationOpenURLOptionsSourceApplicationKey – UIKit | Apple Developer Documentation


  • If there are incorrect places, welcome to guide!
  • If you have any questions, feel free to discuss them in the comments section!