The following problems are my problems encountered after upgrading Xcode9 and running the project on iOS11 devices. I will record them here. Maybe you have experienced similar problems, and we can discuss and solve the problems together.

  1. The custom navigation bar height is invalid, use Xcode9 and Xcode8 to run the same code, Xcode8 running iOS11 mobile phone navigation bar height is a custom height, Xcode9 running height becomes the system 44pt height; No effective solution has been found at present; Before iOS11beta5 version of Apple to fix the bug, the official system released after this problem;

    The differences are as follows:



Custom UINavigationBar code is as follows:

public let customNavigationBarHeight: CGFloat = isPad ? 75 : 60

final class CustomNavigationBar: UINavigationBar {
  
  override func sizeThatFits(_ size: CGSize) -> CGSize {
    return CGSize(width: UIScreen.main.bounds.width, height: customNavigationBarHeight)
  }
  
  override func layoutSubviews() {
    super.layoutSubviews()

    for subview in subviews {
      subview.center.y = frame.height / 2
    }
  }

  override func titleVerticalPositionAdjustment(for barMetrics: UIBarMetrics) -> CGFloat {
    return -(frame.height - 44)/2
  }
}
Copy the code

A solution found in stackeroverflow does allow you to change the height of the navigation bar on iOS11 devices, but there are two problems: the first navigation bar title bar is not vertically centered; If the rootViewController of the second navigation controller is tableVeiwController or topInset with tableView is 44pt, there is no corresponding move down with the height of the navigation bar:

  override func layoutSubviews() {
    super.layoutSubviews()

    backgroundColor = .black
    frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: customNavigationBarHeight)
    for subview in self.subviews {
      printLog(subview)
      let stringFromClass = NSStringFromClass(subview.classForCoder)
      if stringFromClass.contains("BarBackground") {
        subview.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: customNavigationBarHeight)
        subview.backgroundColor = .blue//self.backgroundColor
      } else if stringFromClass.contains("BarContent") {
        subview.frame = CGRect(x: subview.frame.origin.x, y: 0, width: subview.frame.width, height: customNavigationBarHeight)
        subview.backgroundColor = .red//self.backgroundColor
        subview.center.y = customNavigationBarHeight / 2
      } else {
        subview.center.y = frame.height / 2
      }
    }
  }
Copy the code

The results and analysis chart are as follows:


















This problem needs to be further discussed, if anyone has a solution, we can discuss it together!

  1. [Fixed] When using Xcode9 to package and upload builds, you get a warning that the 1024x1024px Icon image is missing. Solution: Add an Icon image of the required size to the AppIcon of project Assets.xcassets; The email content is as follows
Dear developer, We have discovered one or more issues with your recent delivery for "Your delivery was successful." but you may wish to correct the following issues in your next delivery: Missing Marketing Icon - iOS Apps must include a 1024x1024px Marketing Icon in PNG format. Apps that do not include the Marketing Icon cannot be submitted for App Review or Beta App Review. After you've corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect. Regards, The App Store teamCopy the code





1024×1024 size Icon


Also remember to ask UI to add LaunchImage for iPhone X.

  1. Swift version mismatch problem. If some dependent libraries used in our project are framework built using Swift language, the compilation fails after upgrading from Xcode8 to Xcode9, prompting swift Module version mismatch error. At this point, we just need to recompile the corresponding framework using Xcode9 to compile it.
  2. Add user privacy agreement submitted AppStore audit, the audit time is nearly a month, a week or two before the National Day holiday in our company submit a version, and solved the problem iOS11 some flash back and adaptation, added the user privacy policy at the same time, the result is still in audit, after National Day holidays to come back during the audit we sent letters of urgent mail, But all the time yes reply is under review! After the investigation, there are many reasons for the addition of the user privacy policy. Although the content of the user privacy agreement is provided by the legal department of the company group, it seems that Apple has to review the content of your privacy agreement. Decisive withdraw behind this version (a large number of users to upgrade iOS11 system feedback after the inside of the app a broadcast video module flash back, locked behind reason is that we set up broadcast video class name of the class, and system class name repetition), remove the privacy policies and resubmit a new build, and then write an urgent email, immediately approved the next day. A few days later, at the same time, other parts of the group submitted a version containing the privacy policy, which was rejected.
  3. Flash back iOS11 system equipment save images to the photo album, solution: in the info. Add access, plist key: NSPhotoLibraryAddUsageDescription, value: whether to allow $(PRODUCT_NAME) access to your photo album? .

10.27 add

  1. TableView is white on both sides of iOS11 devices, such as the white space in the red box in the lower left picture, and the effect after the solution on the right picture:





    Solution:

# if available (iOS 9.0. *)} {tableView. CellLayoutMarginsFollowReadableWidth = falseCopy the code
  1. For iphoneX, most of our projects used storyboard development and autolayout for layout, so it only took one day to complete the layout adaptation of iphoneX. I think the adaptation rules of iPhoneX are very simple: modify according to the rules suggested by Apple and the renderings given to you by THE UI. For example, we use the corresponding distance between the left and right Spaces officially recommended by Apple, layout within the Safe Area, and do not add click events for content outside the Safe Area.You can check these two articles for detailsUnderstand iPhone X design size and fit in three minutes.4 things to know about The iPhone X: Wang and Design LionAfter reading these two articles, you should have a basic understanding of the iPhoneX.

    Let’s take a look at a bunch of UI’s that don’t work





    7.1 AutoLayout layout for iPhoneX adaptation;(many projects may be deployed in versions lower than iOS9, soSafe Area Layout GuidesLayouts are not supported, but this does not affect automatic adaptation on the iPhoneX. One of the storyboard bugs reported just after upgrading to Xcode9 is thisSafe Area Layout Guides before iOS 9.0Since this option is turned on by default, we just need to turn it off.The first,Collection views like tableView, collectionView, autolayout have been automatically adapted for us, so we don’t need to make too many changes. As shown in the figure above, the white part of the left, right, and bottom three sides is automatically adapted to the distance. I just need to change the color of this part to the dark color of tableView to fit the distance.The second,The distance between left and right in the yellow area at the top of the image has to be addedview.safeAreaInsetsThe distance between the left and the right, this part of the fit only needs to draw out the constraint by oneIBOutletAnd then inviewDidLayoutSubviewsMethod, the specific code is as follows:

@IBOutlet weak var backBtnLeadingCons: NSLayoutConstraint! @IBOutlet weak var stageViewTrailingCons: NSLayoutConstraint! Override func viewDidLayoutSubviews () {super. ViewDidLayoutSubviews # () if available (iOS 11.0, *) { let inset = view.safeAreaInsets printLog(inset) backBtnLeadingCons.constant = inset.left + 20 stageViewTrailingCons.constant = inset.right + 10 } }Copy the code

Modified renderings:





An adaptation of the iPhoneX



Code constraints (like the navigation) or hand-written controls frame for the iPhoneX

/ / screen wide high let kScreenWidth = UIScreen. Main. Bounds. Size. The width let kScreenHeight = UIScreen. Main. Bounds. Size. Height let isiPhoneX = (max(kScreenWidth, kScreenHeight) == 812 && min(kScreenWidth, kScreenHeight) == 375)Copy the code
  • There are only so many problems we have encountered temporarily. We will add pits when we encounter them in the future. Welcome to add pits when we encounter them!