IOS10 Adaptation Tutorials

Source: Internet
Author: User
Tags uikit
iOS Development adaptation iOS10

September 7, 2016, Apple releases iOS 10. September 14, 2016, the new operating system iOS 10 will be officially online.

As a developer, how to fit iOS10. 1.Notification (notice)

Since the introduction of notification, Apple has been constantly updating the optimization, but these update optimization is only a minor, until now the iOS 10 began to real restructuring, so that developers also realize that the usernotifications of ease of use, function has become very powerful.

Pre-IOS 9 notifications

1. When calling methods, some methods are difficult to distinguish, easy to write the wrong way, which makes the developer sometimes very distressed.

2. The path that the application captures notifications at run time and not run is inconsistent.

3. When applied to the foreground, it is not possible to display the remote notification directly, and further processing is required.

4. Notifications that have been issued cannot be updated, content is not changed when issued, and only simple text display, extensibility is not very good.

IOS 10 Start Notice

1. All relevant notices are integrated into the usernotifications.framework framework.

2. The contents of the notice can also be modified in addition to the cancellation, update and halfway.

3. The notification is not a simple text, you can add video, pictures, custom notification of the display and so on.

4.iOS 10 is easier to manage than previous notifications, and it's a good thing for developers to do a massive optimization.

5.iOS 10 began to optimize for permissions issues, the request permissions are relatively simple (local and remote notifications are integrated in one method).

If a push is used, modify it as shown:

    2.ATS Problem

The default HTTs network in IOS 9 is prohibited, but we can also set the nsallowsarbitraryloads to Yes to disable ATS. However, iOS 10 since January 1, 2017, Apple does not allow us to skip the ATS in this way, which means that we are forced to use HTTPS, and if not, submitting the app may be rejected. But we can use Nsexceptiondomains to open HTTP for specific domain names that can be easily audited.

Set the domain Nsexceptiondomains way. It can be easily understood that interfaces that do not support HTTPS protocols are set to HTTP interfaces.

Specific methods:

1), add a Key:app transport security Settings in the project's info.plist, type the dictionary type.

2), then add a exception Domains to it, type the dictionary type;

3), add the required support domain to exception Domains. Where the field is a key and the type is a dictionary type.

4, the following needs to set 3 properties per domain: Nsincludessubdomains, nsexceptionrequiresforwardsecrecy, Nsexceptionallowsinsecurehttploads.

As shown in figure:

detail tip: In the iOS9 after the system if the use of network pictures, but also pay attention to whether the network image is http Oh, if it is, also to the picture's domain settings oh. 3.iOS 10 privacy permission Settings

IOS 10 began to more stringent privacy permissions, if you do not set up a direct crash, now a lot of crash problems, the general solution is in the Info.plist file to add the corresponding key-value on it.

The above value, circled the red line part of the text is displayed to the user to see, must be added. 4.Xcode 8 Run a bunch of useless logs solutions

Above we see that a new project of our own has not done anything to print a pile of rotten seven or eight bad things, I think this should be Xcode 8 problem,

Specifically also did not study, the solution is to set os_activity_mode:disable the following figure:

First step:

Step Two:

Step Three:

To add a parameter:

Name:os_activity_mode

Value:disable

5.iOS Uistatusbar method Expires:

In our development it is possible to use some of the Uistatusbar attributes, which have expired in iOS 10 and need to be adapted if useful in your project.

The image above also shows that if you need to use Preferredstatusbar in iOS 10, for example:

IOS-(Uistatusbarstyle) Preferredstatusbarstyle {return uistatusbarstyledefault;
}

6.iOS uicollectionview Performance Optimization

With the developer of Uicollectionview Trust, the project used in the place is also more, but there are some problems, such as sometimes cotton, loading slow. So iOS 10 is further optimized for Uicollectionview. Uicollectionview cell pre-fetching Pre-loading mechanism Uicollectionview and UITableView prefetchdatasource new APIs for self-sizing cells Improvement of Interactive reordering

Prior to iOS 10, if there was a large number of cell uicollectionview above, when the user activity is very fast, the whole uicollectionview of cotton will be obvious, why this problem, this involves the iOS system reuse mechanism, When the cell is ready to load into the screen, the entire cell has been loaded, waiting outside the screen, that is, a whole row of cell has been loaded, which is the main reason for cotton, the professional term is called: drop frame.
To make the user feel no cotton, our app must have a frame rate of 60 frames per second, that is, 16 milliseconds for each frame to refresh once.The lifecycle of Uicollectionviewcell before IOS 10 is this:1. The user slides the screen, there is a cell outside the screen ready to load in, the cell from the REUSR queue out, and then call the Prepareforreuse method, in this method, you can reset the state of the cell, loading new data; 2. Continue to slide, will call the Cellforitematindexpath method, in this method to the cell assignment model, and then return to the system; 3. When the cell goes into the screen immediately, it will call the Willdisplaycell method, in which we can also modify the cell, in order to enter the screen to do the final preparation; 4. After the Willdisplaycell method is executed, the cell goes into the screen. The Didenddisplayingcell method is invoked when the cell completely leaves the screen.The lifecycle of the IOS Uicollectionviewcell is this:1. The user slides the screen, the screen has a cell ready to load in, the cell from the REUSR queue out, and then call the Prepareforreuse method, where the cell has not gone into the screen, it has already called this method in advance, The difference was that the method was invoked when the upper edge of the cell was immediately inside the screen, and iOS 10 was called before the cell was still outside the screen; 2. Create a cell in the Cellforitematindexpath, fill the data, refresh the state and other operations, compared to earlier; 3. Users continue to slide, when the cell needs to be shown immediately when we call the Willdisplaycell method, the principle is: When to show, when to call the Willdisplaycell method; 4. When the cell completely leaves the screen, the Didenddisplayingcell method is invoked, as before, the cell enters the reuse queue.
Before iOS 10, the cell could only be removed from the reuse queue, go through the lifecycle, and invoke Cellforitematindexpath to create or generate a cell.
In iOS 10, the system will hold the cell for a period of time, which means that when the user slides the cell out of the screen, if it slides back again, the cell does not have to go through the lifecycle again, just call the Willdisplaycell method and it will be able to appear again on the screen.
In IOS 10, the system is one loaded cell, the second is a row of loading, so that can improve a lot of performance;IOS 10 new additions to pre-fetching pre-loadingThis is to reduce the time it takes to load the Uicollectionviewcell, and in IOS 10, there is a new uicollectionviewdatasourceprefetching protocol in addition to the data source protocol and the proxy protocol, There are two methods defined in this agreement:

-(void) CollectionView: (Uicollectionview *) CollectionView prefetchitemsatindexpaths: (Nsarray<nsindexpath *> *  ) indexpaths Ns_available_ios (10_0);

-(void) CollectionView: (Uicollectionview *) CollectionView cancelprefetchingforitemsatindexpaths: (NSArray< Nsindexpath *> *) indexpaths  Ns_available_ios (10_0);

In Colletionview Prefetchitemsat Indexpaths This method is asynchronous preload data, in which the indexpaths array is ordered, that is, the order in which the item receives data;
CollectionView Cancelprefetcingforitemsat Indexpaths This method is optional and can be used to process the priority of canceling or decreasing the data in advance in sliding.
Note: This protocol does not replace the previous method of reading data, only auxiliary loading data.
Pre-fetching preload is also applicable to UITableViewCell.


7.iOS Uicolor New Method

The following is a description of the official documentation:

Most graphics frameworks throughout the system, including core graphics, core Image, Metal, and avfoundation, have Substan Tially improved support for Extended-range pixel formats and wide-gamut color spaces. By extending this behavior throughout the entire graphics stack, it is easier than the ever to support devices with a wide col or display. In addition, Uikit standardizes on working in a new extended color spaces, SRGB it easy to mix making sRGB with colors RS in, wider color gamuts without a significant performance penalty.

Here are some best practices to adopt as your start working with Wide Color.

In IOS, the Uicolor class uses the extended SRGB color spaces and its initializers no longer clamp raw component values To between 0.0 and 1.0. If your app relies on Uikit to clamp component values (whether your ' re creating a color or asking a color for its component values), you need to the change your app's behavior when you link against IOS 10.

When performing custom drawing into a uiview on IPad Pro (9.7 inch), the underlying drawing environment are configured wit H an extended sRGB color spaces.

If your app renders custom image objects, use the new Uigraphicsimagerenderer class to control whether the destination bit The map is created using a extended-range or standard-range format.

If you are are performing your own image processing on Wide-gamut the using a devices level API lower as Core such or Me Tal, you should use a extended range color spaces and a pixel format that supports 16-bit floating-point values. When clamping of the color values are necessary, you should does so explicitly.

Core Graphics, Core Image, and Metal performance shaders provide new options for easily converting colors and images Betwe En color spaces.

Because before we all use RGB to set color, anyway use up is not especially diverse, this new method should be a make up for it. So in iOS 10 Apple officials suggest we use sRGB because it's better and richer in color. If you wrote a set of categories for Uicolor, you can also try to replace the Srgb,uicolor class with the addition of two additional APIs as follows:

+ (Uicolor *) colorwithdisplayp3red: (cgfloat) displayp3red green: (cgfloat) Green Blue: (cgfloat) Blue Alpha: (cgfloat) Alpha Ns_available_ios (10_0);

-(Uicolor *) initwithdisplayp3red: (cgfloat) displayp3red green: (cgfloat) Green Blue: (cgfloat) Blue Alpha: (cgfloat) Alpha Ns_available_ios (10_0);



8.iOS Uitextcontenttype
The Textcontenttype property are to provide the keyboard with extra information about the semantic intent of the text do Cument. @property (nonatomic,copy) uitextcontenttype textcontenttype Ns_available_ios (10_0); Default is Nil

The Textcontenttype enumeration was added to iOS Uitextfield to indicate the desired semantic meaning of the text input area.

Use this property to give the keyboard and system information about the intended semantic meaning of the user-entered content. For example, you can specify a text field that the user fills in to receive an email confirming uitextcontenttypeemailaddress. When you provide information about what you expect users to enter in a text entry area, the system can automatically select the appropriate keyboard in some cases and improve the integration of keyboard fixes and active and other text entry opportunities. 9.iOS 10 fonts change with phone system fonts

When the font of our phone system changes, the label of our app will change along with it, which requires us to write a lot of code to do it further, but iOS 10 provides such a property adjustsfontforcontentsizecategory to set. Because there is no real machine, the actual operation has not been achieved, if the understanding of the error to help correct.

Uilabel *mylabel = [Uilabel new];
 /* Uifont Preferredfontfortextstyle: Specifies a style and allows the font size to match the font size set by the user.
 * *
 mylabel.font =[uifont preferredfontfortextstyle:uifonttextstyleheadline]/*
 indicates whether the C orresponding element should automatically update its font when the device ' s uicontentsizecategory is changed.
 The to take effect, the element's font must be a font vended using +preferredfontfortextstyle:or +preferred FontForTextStyle:compatibleWithTraitCollection:with a valid uifonttextstyle.
 *
 ///whether to update font changes
 mylabel.adjustsfontforcontentsizecategory = YES;

10.iOS uiscrollview New Refreshcontrol

After IOS 10, as long as it inherits Uiscrollview, the refresh feature is supported:

@property (Nonatomic, Strong, nullable) Uirefreshcontrol *refreshcontrol Ns_available_ios (10_0) __tvos_prohibited;


11.iOS 10 To determine the correct posture of the system version

Judging the system version is something we often use, especially now that everyone is likely to need to fit iOS 10, then the problem arises, as shown in the following figure:

We got the answer:

value is 1 [[[[[Uidevice Currentdevice] systemversion] substringtoindex:1] IntegerValue]

The value is 10.000000 [[Uidevice Currentdevice] Systemversion].floatvalue,

value is 10.0 [[Uidevice Currentdevice] systemversion]

So the best way to judge the system is to use the latter two methods, oh ~ I forgot to say [[Uidevice Currentdevice] Systemversion].floatvalue This method is also not reliable, It seems that the output of the 8.3 version of the value is 8.2, it is not clear that it is not reliable anyway, so we recommend [[Uidevice Currentdevice] systemversion] This method.

Swift judged as follows:

If #available (iOS 10.0, *) {
 //iOS 10.0
 print ("ios 10.0");
 } else {}

12.Xcode 8 Plugin cannot use the problem

Everyone has upgraded Xcode 8, but the developers who rely on Plug-ins are crying to find solutions online. So here's the solution:
Let your Xcode8 continue to use the plugin (http://vongloo.me/2016/09/10/Make-Your-Xcode8-Great-Again/?utm_source=tuicool&utm_medium= Referral)

But see the final interpretation of the article, we know that if you use Plug-ins, there may be security problems, and submit the audit will be rejected, so we suggest that we still do not use, the solution is always available, such as the Xcode in the code block is also very convenient to add comments.

13.iOS 10 Start Item Some text display incomplete problem

I tested the Xcode 8 and Xcode 7.3 Separately, as shown below:

Xcode 8





Create a label and then make it adaptive size, the font size is 17 The last output width is not the same, we look again,
The following data will tell you why the app's text is not fully displayed after upgrading iOS 10:



English Alphabet will also have this problem, I passed the test, later found that the English alphabet is no problem, only Chinese characters have problems.
Currently there is only one modified control to solve this problem, there is no other good way to solve.

14.Xcode 8 warning problems using Xib awakefromnib

Before Xcode 8 We use xib initialization-(void) awakefromnib {} All of this is not a problem, but Xcode 8 will have the following warning:

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.