Sort out the pitfalls in iOS9 adaptation and ios9 adaptation

Source: Internet
Author: User
Tags password protection

Sort out the pitfalls (text) in iOS9 adaptation and ios9 adaptation

This article mainly describes some pitfalls in iOS9 adaptation. If you only need to understand the new features of iOS9, you can refer to the new features of the iOS 9 SDK that developers need to know. In the early morning of June September 17, Apple pushed the official version of iOS9 to users. As some users gradually upgrade iOS9, a series of problems gradually emerged. I am also busy adapting my own apps, some pitfalls in this article are basically self-experienced.

I. NSAppTransportSecurity

IOS9 enables all HTTP to Use HTTPS by default, and the original HTTP transmission is changed to TLS1.2 for transmission. The cause is that the pop-up network cannot be connected when the App sends a request. The solution is to add the following nodes to the info. plist file of the project:

NSAppTransportSecurity-NSAllowsArbitraryLoads

Does this subnode mean: Is it allowed to load automatically ?! If it is set to YES, AppTransportSecurity will be disabled and user-defined settings will be used instead. This problem will be solved.

If you did not see this article in Dong Boran's blog, click to view the original article.

 

Apple limits the HTTP protocol, but it does not mean that all HTTPS can be perfectly adapted to iOS9.

For example, you can load https web pages from webView in the app. Create a project and write several lines of webpage code

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

The url in the middle is the https address we want to load, use https://baidu.com/and https://github.com/respectively to try, the results are different

The github webpage can be opened, but the Baidu webpage cannot be opened. A line of log is printed below.

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

The reason is that, according to official Apple documents, the TLS 1.2 protocol must be used first. Then, the encryption algorithm of the certificate must reach SHA256 or a higher level RSA key or ECC key. If the key does not match, the request will be interrupted and the nil will be returned.

In the browser, you can directly view the encryption algorithm of this website. Click the green lock and then click the certificate information.

From the two pictures on the right, we can see that github's RSA-encrypted SHA-256 meets Apple's requirements, so it can be displayed.

For Baidu, you can configure the following in info. plist. If many websites are referenced, you must configure each website.

NSAppTransportSecurity, NSExceptionDomains, NSIncludesSubdomains, NSExceptionRequiresForwardSecrecy, NSExceptionAllowInsecureHTTPLoads can be easily copied.

Among them, ForwardSecrecy is considered as an advanced password protection algorithm. It is written in official documents and there are 11 types in total. After configuration is complete, Baidu can access it.

Ii. Bitcode

Bitcode is a kind of Transitional Code Compiled by the program, and then Apple compiles the Transitional Code into executable programs. Bitcode also allows Apple to re-optimize the binary files of our program in the future, similar to the idea of App slimming.

If the xcode7 compiler is used to compile a project that is normal before compilation, the following error may occur.

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

The cause is that some third-party libraries do not support bitcode. Otherwise, we will wait for the database developer to upgrade this function, or we will disable this bitcode.

To disable bitcode, find the following configuration and select "NO". (In iOS, bitcode is the default value "YES". In watchOS, bitcodes cannot be changed to YES .)

 

3. Set Trust

This one is only related to enterprise applications or inhose, and has nothing to do with the AppStore channel applications.

In iOS8, a window is displayed asking if you want your mobile phone to trust the app, but it is not allowed in iOS9. If you really want to trust it, you need to manually enable it. Similar to the dmg downloaded from an unknown developer in the Mac system, the dmg cannot be opened directly, and then it needs to be opened manually in the security and privacy settings of the system preference. Display iOS8 on the left and iOS9 on the right

 

You need to set --- General --- the description file to add your own trust.

There are two ways to solve this problem: 1. Do not upgrade iOS9 in advance; 2. enterprise-level applications mostly used by company employees. Send a group of guidance emails.

 

Iv. Font

In iOS8, the font isHelvetica, the Chinese font is somewhat similar to "文 ". It's only Apple's mobile phone that comes with rendering, so it may look more beautiful than ordinary Chinese.In iOS9, the font of the Chinese system is changed to "" designed specifically for China, which is somewhat similar to a word Font "". The font has a slight thickening effect, and the most important thing is that the font gap has become larger!

Therefore, many labels that have been written to the width may encounter.

IOS8

IOS9 egg pain

The above two images can intuitively show the changes of the same interface and label.

Therefore, in order to display the interface without errors, we recommend that you use sizetofit or ios to round up ceilf () or calculate it in advance even if it is a fixed-length text.

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

 

5. URL scheme

URL scheme is generally used in scenarios where an application has the ability to share or jump to another platform for authorization, and then jump back after sharing or authorization.

There are no too many restrictions on iOS8, but iOS9 needs to list the URL scheme that you want to call externally as a white list to complete the jump.

If iOS9 is not adapted, the following error is reported:

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

The specific solution is to set the LSApplicationQueriesSchemes type as an array in info. plist. add all the scheme

 

Vi. tableView

Although the official version of iOS9 has been pushed, The iOS9 still feels that the App is more choppy than before. The most obvious effect is displayed when the tableView is dragged. In addition, I encountered a bug. The original project was compiled with xcode7 AND THE tableView refresh encountered a problem. [tableView reloadData] was invalid because a cell line was changed but could not be refreshed. It may be that this method conflicts with some newly added features. It is suggested that the reloadData operation will be postponed until the next RunLoop execution fails.

The solution is to comment out [tableView reloadData] and use partial refresh to solve the problem.

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

 

If you did not see this article in Dong Boran's blog, click to view the original article.

When these problems are encountered for the time being, I feel that the emergence of iOS9 makes all iOS development very tight. I hope Apple will make a drastic change. After the maverick style develops, there will be no conflict with government, then the collapse of the company led to unemployment of developers. Maybe I thought too much. I hope that all iOS apps can adapt to and correct bugs in a timely manner. The next version will be released and all problems will be solved.

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.