Organize the pits that appear in the IOS 9 adaptation

Source: Internet
Author: User
Tags password protection

Tung Platinum authorized this site reproduced.

This article is mainly about some iOS9 adaptation of the pit, if only to understand the iOS9 new features can be seen in the eyes of God's developers need to know the IOS 9 SDK new features. September 17 early morning, Apple to users pushed the IOS9 official version, with the user has been upgraded iOS9, also gradually derived a series of problems, the author also quickly for their own maintenance of the app to do the adaptation, this article wrote some of the pits are basically firsthand experience.

First, nsapptransportsecurity

IOS9 let all http default HTTPS, the original HTTP protocol transfer is changed to TLS1.2 protocol for transmission. The direct result is that when the app sends a request, the network fails to connect. The solution is to add the following node to the project's Info.plist file:

Nsapptransportsecurity-nsallowsarbitraryloads

This sub-node means: whether to allow wayward loading?! Set to Yes will disable the apptransportsecurity switch to the user-defined settings, the problem is resolved.

It says that Apple restricts the HTTP protocol, but it doesn't mean that all https is perfectly suited to iOS9.

Take a chestnut, from within the app WebView loading HTTPS Web pages. Create a new project write a few lines from the page code

123456789101112 - (void)loadView{    UIWebView *web = [[UIWebView alloc]initWithFrame:[UIScreen mainScreen].bounds];    self.view = web;}- (void)viewDidLoad {    [superviewDidLoad];         UIWebView *web = (UIWebView *)self.view; //董铂然    NSURL *url = [NSURL URLWithString:@"https://github.com/"];    NSURLRequest *request = [NSURLRequest requestWithURL:url];    [web loadRequest:request];}

The middle URL is the HTTPS address that we want to load, with https://baidu.com/and https://github.com/to try each, the result is different

GitHub Web page can open, Baidu's Web page cannot open, the following print a line of log

1 NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

The reason is that Apple's official profile says it must first be based on the TLS 1.2 version agreement. Then the cryptographic algorithm of the certificate also needs to reach the RSA key or ECC key of SHA256 or higher, and if it does not, the request is interrupted and nil is returned.

In the browser is can directly see this website encryption algorithm, first point green Lock point certificate information.


As you can see from the two images on the right, GitHub's SHA-256 with RSA encryption meets Apple's requirements, so it can be displayed.

The situation for Baidu can be configured in Info.plist as follows, if the site reference more than should be required for each site configuration.

Nsapptransportsecurity,nsexceptiondomains,nsincludessubdomains,nsexceptionrequiresforwardsecrecy, Nsexceptionallowinsecurehttploads is written below for easy copying.

One of the Forwardsecrecy understood as the advanced password protection algorithm, in the official information has written, altogether is 11 kinds. After the configuration Baidu can access.

Second, Bitcode

Bitcode's understanding should be to compile the program into a transition code, and then Apple to compile the transition code into an executable program. Bitcode also allows Apple to re-optimize our program binaries in the late stages, with ideas like app slimming.

The following error may occur with the Xcode7 compiler to compile items that are not problematic before compiling.

1 XXXX’ does not contain bitcode. You must rebuild it withbitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. forarchitecture arm64

The problem is due to the fact that some third-party libraries do not yet support Bitcode. Otherwise, wait for the library developers to upgrade this feature we update the library, or to disable this bitcode.

The disabled method is to find the following configuration, select No. (iOS Bitcode is the default Yes,watchos in Bitcodes is not allowed to change must be yes.) )

Third, set up trust

This article is only relevant to enterprise applications or inhose, not to the application of AppStore channels.

In iOS8 just pop up a window asking if you need to let the phone trust this app, but in iOS9 but directly banned, if you really want to trust yourself need to manually open. Similar to the MAC system downloaded from unknown developers, DMG directly will not open, and then to the system preferences of security and privacy manually opened. Show left IOS8, right iOS9

Users need to go to set---"General---" in the description file to add their own trust.

There are two ways to deal with this problem: 1. Do not upgrade IOS9 2. Most of the company employees use enterprise-class applications, mass a guidance mail.

Four, font

IOS8, the font is Helvetica, the Chinese font is a bit similar to "Chinese fine black". It's just that the iphone comes with its own rendering, so it may look more beautiful than ordinary Chinese. In IOS9, the Chinese system font has become a Chinese-designed "apple" is a bit like a word font "young circle". The font has a slight bold effect, and the most important thing is that the font gap gets bigger!

So many of the labels that were originally written to the width may appear "...".

IOS8

IOS9 Egg Pain

The above two graphs can also intuitively see the same interface, the same label changes.

So in order to display on the interface is not wrong, even if it is a fixed-length text is still recommended to use SizeToFit or iOS to take the whole CEILF () or Calculate in advance

12 CGSize size = [title sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0f]}];CGSize adjustedSize = CGSizeMake(ceilf(size.width), ceilf(size.height));

Five, URL scheme

The scenario used by URL scheme is that the application has the ability to share or jump other platform licenses, share or authorize and then jump back.

There are not too many restrictions on iOS8, but iOS9 need to whitelist the URL scheme you want to call outside to complete the jump

If IOS9 does not make the appropriate match, it will report the following error

1 canOpenURL: failed forURL : "mqzone://qqapp"- error: "This app is not allowed to query for scheme mqzone"

The specific solution is to set the Lsapplicationqueriesschemes type to an array in Info.plist, and add all of the schemes you use below

Liu, StatusBar

This is good just to report a warning, if it is regardless of him, there will be no problem.

1 : CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

We used to be able to control the style of the top statusbar in real-time, we might like to use

12 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent][[UIApplication sharedApplication]setStatusBarHidden:YES];

But before doing so need to add the info.plist inside the view controller-based status bar appearance bool value set to No, that is, the Controller control status bar permissions to prohibit, with the uiapplication to control. However, this practice is not recommended in iOS9, we recommend that we use the BOOL value is set to Yes, and then use the controller to manage the status bar such as.

1234 - (UIStatusBarStyle)preferredStatusBarStyle{    returnUIStatusBarStyleLightContent;}

The point in the header file can verify just the saying:

1 @property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]");

Seven, Didfinishlaunchingwithoptions

If you report the following error when you run it, your didfinishlaunchingwithoptions is wrong.

1 ***** Assertion failure in-[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UIApplication.m:3294**

IOS9 does not allow the Rootviewcontroller of Windows to be set after Didfinishlaunchingwithoptions is finished. Perhaps the Xcode7 compiler itself does not support it.

The solution, of course, is to initialize the values first, and then replace them with the values.

12 UIWindow *window = [[UIWindowalloc] initWithFrame:[UIScreenmainScreen].bounds];window.rootViewController = [[UIViewController alloc]init];

Eight, TableView

Although the current iOS9 has been pushed to the official version, but iOS9 use will still feel the app more than ever, TableView drag when the most obvious lag display. And before encountering a bug, the original Good project with Xcode7 a compile, tableView refresh the problem, [TableView Reloaddata] Invalid there is a row of cells clearly changed but not to refresh. The feeling may be that this method conflicts with some of the new features, and it may be that the reloaddata operation is deferred until the next Runloop execution is final.

The solution is to comment [TableView Reloaddata], instead of local refresh, the problem actually solved.

1 [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];

Temporarily encounter these problems, feel iOS9 of the emergence of all iOS development is a tight, hope that Apple this drastic change, maverick style development after not and government contradictions, and then the company closed down led to the development of unemployment, perhaps I think more. I wish all iOS can be timely to do a good job to change the bug, the next version of the line, all problems are resolved.

Organize the pits that appear in the adaptation of IOS 9 (graphic)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.