IOS Development ———— Detailed Zhei iOS10 problem _ios

Source: Internet
Author: User
Tags uikit

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.

iOS 9 prior notice

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 can also be found in IOS 10 if you need to use Preferredstatusbar 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.

    • Pre-loading mechanism of Uicollectionview cell pre-fetching
    • Uicollectionview and UITableView prefetchdatasource new API
    • The improvement of self-sizing cells
    • 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-loading

This 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 Corresponding 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]

//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, As if in the 8.3 version of the output value is 8.2, it is not clear that anyway is not reliable, so we suggest that we use [[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

Xcode7

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:

Official explanation:

You are must call the super implementation of Awakefromnib to give parent classes the opportunity to perform any additional in Itialization they require.

Although the default implementation of this method does nothing, many uikit classes, provide non-empty.
You could call the super implementation in any point during your own awakefromnib method.

You must invoke the parent class implementation awakefromnib to give the parent class the opportunity to perform any additional initialization they need.

Although the default implementation of this method does nothing, many Uikit classes provide NON-EMPTY implementations.

You can call your own awakefromnib method at any time super implementation.

15, push the time, open remote notifications

You ' ve implemented-[<uiapplicationdelegate> application:didreceiveremotenotification: Fetchcompletionhandler:],

But you still need to add "remote-notification" to the list of your supported, uibackgroundmodes in your.

Solution: Need to modify the application in the Xcode capabilities open remote notifications, please refer to the following figure:

16. One of the two would be used. Which one is undefined. "

OBJC[5114]: Class plbuildversion is implemented in both/applications/xcode.app/contents/developer/platforms/ iphonesimulator.platform/developer/sdks/iphonesimulator.sdk/system/library/privateframeworks/ Assetslibraryservices.framework/assetslibraryservices (0x1109a5910) and/applications/xcode.app/contents/ developer/platforms/iphonesimulator.platform/developer/sdks/iphonesimulator.sdk/system/library/ Privateframeworks/photolibraryservices.framework/photolibraryservices (0x110738210). One of the two would be used. Which one is undefined.

In the simulator, discover "one of the" two would be used. Which one is undefined. " Log

Find Data Discovery Reason: OBJC runtime uses the same namespace (flat namespace) for the app used, and the operating mechanism is as follows:

1. First binary image is loaded, check program dependencies

2. While each binary image is loaded, the program's OBJC classes is registered in the OBJC runtime namespace

3. If a class with the same name is loaded again, the behavior of the OBJC runtime is unpredictable. One possible scenario is that the class of any program will be loaded (this should also be the default action)

17. Invalid bundle-the Asset Catalog at ' Payload/xxxxx/assets.car ' can ' t contain 16-bit or P3 Assets if the app supports IOS 9.3 or earlier

In Xcode 8, this problem occurs when your resource file contains a 16-bit graph or [the image display mode gamma is ' P3 '] and iOS targets is set to iOS 9.3. If your app needs to support wide gamut display, you have to set target to iOS 9.3+, on the other hand, if your app doesn't need to support wide gamut and you want to be compatible with iOS 9.3, you'll have to have all 16-bit or display mode ' P3 ' The pictures are all replaced with 8-bit patterns of sRGB colors.

You can find 16-bit or P3 resource files by running "Assetutil" in the error message in itunes Connect. The offline solution is as follows:

1. IPA Document for export project

2. Navigate to the IPA file to modify the suffix name. IPA is. zip.

3. Unzip the. zip file. The unpacked directory will have a Payload folder containing your app bundle files.

4. Open Terminal disease switch to your app's payload folder under the. App bundle folder in the form as follows:

CD Path/to/payload/your.app

5. Locate the Assets.car file using the Find command. App bundle, in the form as follows:

Find. -name ' Assets.car '

6. Use the Assetutil command to locate any resource file containing the 16-bit or P3, and the following command for each assets.car line:

sudo xcrun--sdk iphoneos assetutil--info/path/to/a/assets.car >/tmp/assets.json

7. Open the/tmp/assets.json file that was generated in the previous step and look for "Displaygamut": "P3" or related content. The value for this JSON's "Name" field is 16-bit or a resource file name that displays a gamma value of P3.

8. Find this resource file modified to 8-bit sRGB form, recompile upload your app.

18. This version does not support documents saved in the Xcode 8 format. Open This document with Xcode 8 or later

When editing an item, the default is to use Xcode8 to open, causing me to use Xcode7 to open Xib is an error:

This version does is not support documents saved in the Xcode 8 format. Open This document with Xcode 8.0 or later

Cause with Xcode8 open xib All can not open, only with editor will xib inside the following sentence deleted to open:

<capability name= "Documents saved in the Xcode 8 format" mintoolsversion= "8.0"/>

To be continued, continue to update ~

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.