IOS-How to Fit iOS10 (episode)

Source: Internet
Author: User
Tags uikit

Upgrade the system 10.12beta Xcode8 a big push to the problem, even the app on the shelves has become a problem. We can only solve these problems first, then study the 3D engine.

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

As a developer, how to fit iOS10?

1.Notification (Notification)

Since Notification being introduced, Apple has been updating and optimizing, but these update optimizations are just a scratch, and until now iOS 10 is starting to really make big changes, which gives developers UserNotifications the ease of use and the ability to become very powerful.

    • Previous notifications for IOS 9

      1. When calling a method, some methods make it difficult to distinguish and write wrong methods, which makes the developer sometimes very distressed.

      2. The path that the app captures notifications at run time and non-runtime is not consistent.

      3. When applied to the foreground, remote notifications cannot be displayed directly, and further processing is required.

      4. Notifications that have been issued cannot be updated, the content is not changed when it is issued, and only simple text presentation, extensibility is not very good at all.

    • Notifications starting with IOS 10

      1. All relevant notifications have been consolidated into the UserNotifications.framework framework.

      2. Added cancellation, update, mid-way can also modify the content of the notice.

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

      4.iOS 10 is easier to manage than previous notifications and has been optimized for large scale, which is a good thing for developers.

      5.iOS 10 starting with the optimization of permissions issues, it is easier to request permissions (local and remote notifications are integrated in one method).

If push is used, modify the

   

2.ATS Problem

The default non-HTTs network in IOS 9 is banned, and of course we can NSAllowsArbitraryLoads set it to YES disabled ATS . However iOS 10 since January 1, 2017 Apple does not allow us to skip through this method ATS , that is, forcing us HTTPS to use, if not, submitting the app may be rejected. But we can NSExceptionDomains easily pass audits by being open to specific domain names HTTP .

The Nsexceptiondomains method sets the domain. It can be simply understood that the interface that does not support HTTPS protocol is set to HTTP.

Specific methods:

1), add a Key:app Transport Security Settings in the info.plist of the project, type is the dictionary type.

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

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

4), each domain below need to set 3 properties: Nsincludessubdomains, Nsexceptionrequiresforwardsecrecy, Nsexceptionallowsinsecurehttploads.

details: In the iOS9 after the system if you use the network picture, also pay attention to whether the network image is HTTP, oh, if it is, also to the picture of the domain settings Oh! 3.iOS 10 privacy rights Settings

IOS 10 starts to be more strict with privacy rights, if you do not set it will crash directly, now a lot of crash problems, the general solution is to info.plist add the corresponding-on the file Key Value .

The above Value values, 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

We saw a new project of our own. Print a heap of rotten seven or eight bad things, I think this should be Xcode 8 the problem,

There is no detailed study, the solution is to set up OS_ACTIVITY_MODE : disable such as:

The first step:

Step Two:

Step Three:

To add a parameter:

Name:os_activity_mode

Value:disable

5.iOS Uistatusbar method Expires:

Some properties may be used in our development UIStatusBar , and these methods have expired in iOS 10 and need to be adapted if they are useful in your project.

The above image can also be found if you need to use this example in iOS 10 preferredStatusBar :

//iOS 10 - (UIStatusBarStyle)preferredStatusBarStyle {    return UIStatusBarStyleDefault;}

 

6.iOS uicollectionview Performance Optimization

With the trust of the developers, there are UICollectionView more places in the project, but there are still some problems, such as sometimes lag, slow loading, etc. So iOS 10 UICollectionView is further optimized.

    • Uicollectionview cell pre-fetching Pre-loading mechanism
    • Uicollectionview and UITableView prefetchdatasource new API
    • Improvements for self-sizing cells
    • Interactive reordering

Before iOS 10, if there is a large number of cells above Uicollectionview, when the user activity is very fast, the entire uicollectionview will be obvious, why this problem, here involves the iOS system reuse mechanism, When the cell is ready to load into the screen, the entire cell is loaded, waiting outside the screen, that is, the entire cell has been loaded, which is the main cause of the lag, the jargon is called: drop frame.
To make the user feel stuck, our app must have a frame rate of 60 frames per second, which means 16 milliseconds each frame is refreshed once.

The life cycle of Uicollectionviewcell before IOS 10 is this:
    • 1. The user swipe the screen, there is a cell outside the screen ready to load, 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 sliding, the method is called, in which the cell is assigned a cellForItemAtIndexPath value model, and then returned to the system;
    • 3. When the cell enters the screen immediately, it will call the willDisplayCell method, in this method we can also modify the cell, in order to enter the screen to do the final preparation work;
    • 4. After executing willDisplayCell the method, the cell goes inside the screen. The method is called when the cell completely leaves the screen. didEndDisplayingCell
The life cycle of IOS Uicollectionviewcell is this:
    • 1. When the user slides the screen, a cell outside the screen is ready to load, take the cell out of the REUSR queue, and then call the prepareforreuse method, where the cell is not yet in the screen. This method has been called ahead of time, the difference is that before the cell's upper edge immediately into the screen when the method will be called, and iOS 10 ahead of the cell is still outside the screen when the call;
    • 2. Create a cell in Cellforitematindexpath , populate the data, refresh the state, and so on, compared to earlier;
    • 3. If the user continues to swipe, then we call the Willdisplaycell method when the cell needs to be displayed at once, the principle is: when to display, when to call Willdisplaycell method;
    • 4. When the cell completely leaves the screen, the Didenddisplayingcell method is called, and as before, the cell enters the reuse queue.
      before iOS 10, the cell can only be removed from the reuse queue, go through the lifecycle, and call Cellforitematindexpath to create or generate a cell.
      in iOS 10, the system will save the cell for a period of time, that is, when the user slides the cell out of the screen, if it slides back, the cell does not have to go through the life cycle again, only need to call Willdisplaycell Method can be re-appeared on the screen.
      iOS 10, the system is one to load the cell, two previously loaded on a line, which can improve a lot of performance; IOS 10 The newly added pre-fetching preload this is to reduce the time it takes for Uicollectionviewcell to load, and in IOS 10, in addition to the data source protocol and the proxy protocol, a new Uicollectionviewdatasourceprefetching protocol, which defines two methods in this protocol:
-(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 asynchronously preloaded data, in which the indexPaths array is ordered, that is, the order in which the item receives the data;
   CollectionView cancelPrefetcingForItemsAt indexPathsThis method is optional and can be used to handle the priority of canceling or reducing the preload data in the swipe.
Note: This protocol does not replace the previous method of reading the data, only the auxiliary loading data.
Pre-fetching preload is also applicable for UITableViewCell.


7.iOS Uicolor New Method

The following is an explanation of the official documentation:

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

Here is some best practices to adopt as a start working with Wide Color.

  • In IOS, the Uicolor class uses the extended SRGB color space 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 "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 in a UIView on an iPad Pro (9.7 inch), the underlying drawing environment is configured wit H an extended SRGB color space.

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

  • If you is performing your own image processing on wide-gamut devices using a lower level API, such as Core Graphics or Me Tal, you should use an extended range color space and a pixel format that supports 16-bit floating-point component values. When clamping of 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 are used RGB to set the color, anyway, it is not particularly diversified, this new method should be a fix it. So in iOS 10 Apple is officially advised sRGB to use it because it has better performance and richer colors. If you have UIColor written a set of categories you can also try to replace sRGB , the UIColor class has added two new Api 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 is to provide the keyboard with extra information about the semantic intent of the text [email protected](nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0); // default is nil

In iOS UITextField textContentType , an enumeration is added that indicates the semantic meaning desired by the text input area.

Use this property to give keyboard and system information about the intended semantic meaning of the content that the user enters. For example, you can specify a text field that the user fills in to receive an e-mail acknowledgment uitextcontenttypeemailaddress . When you provide information about what you expect users to enter in the text input area, the system can automatically select the appropriate keyboard in some cases and improve keyboard corrections and integration with other text input opportunities.

9.iOS 10 fonts change with the font of your phone system

When our phone system font changes, then our App label changes will follow, which requires us to write a lot of code to further processing to achieve, but iOS 10 provides such a property adjustsFontForContentSizeCategory to set. Because there is no real machine, the actual operation has not been realized, if you understand the wrong to help correct.

  UILabel *myLabel = [UILabel new];   /*    UIFont 的preferredFontForTextStyle: 意思是指定一个样式,并让字体大小符合用户设定的字体大小。   */    myLabel.font =[UIFont preferredFontForTextStyle: UIFontTextStyleHeadline]; /* Indicates whether the corresponding element should automatically update its font when the device’s UIContentSizeCategory is changed. For this property to take effect, the element’s font must be a font vended using +preferredFontForTextStyle: or +preferredFontForTextStyle:compatibleWithTraitCollection: with a valid UIFontTextStyle. */     //是否更新字体的变化    myLabel.adjustsFontForContentSizeCategory = YES;

 

10.iOS uiscrollview New Refreshcontrol

IOS 10 supports refresh functionality as long as it is inherited UIScrollView :

@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;


11.iOS 10 Judging system version correct posture

Judging the system version is what we often use, especially now everyone may need to adapt to iOS 10, then the problem arises, such as:

We got the answer:

//值为 1 [[[[UIDevice currentDevice] systemVersion] substringToIndex:1] integerValue]

//值为10.000000 [[UIDevice currentDevice] systemVersion].floatValue,

//值为10.0 [[UIDevice currentDevice] systemVersion]

Therefore, the best way to judge the system is to use the latter two methods, oh ~ I forgot to say that [[UIDevice currentDevice] systemVersion].floatValue this method is also not reliable, as if the value of the 8.3 version output is 8.2 , remember that is not clear anyway is not reliable, so we recommend that you use [[UIDevice currentDevice] systemVersion] this method!

Swift judges the following:

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

12.Xcode 8 Plugin not available problem

Everyone has upgraded Xcode 8 , but for developers who rely on plugins, they are crying and looking for solutions online. So here's the workaround:
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 article at the end of the explanation, we know that if the use of plug-ins, there may be security problems, and the submission of the audit will be rejected, so it is recommended that you do not use, the solution is always there, such as the Xcode code block to add comments in is also very convenient.

13.iOS 10 Start Project Some text display is not complete problem

I used Xcode 8 and Xcode 7.3 separately tested the next, such as:

Xcode 8





创建一个Label然后让它自适应大小,字体大小都是17最后输出的宽度是不一样的,我们再看一下,
下面的数据就知道为什么升级iOS 10 之后App中有的文字显示不全了:



英文字母会不会也有这种问题,我又通过测试,后来发现英文字母没有问题,只有汉字有问题。
目前只有一个一个修改控件解决这个问题,暂时没有其他好办法来解决。

14.Xcode 8 warning issue with Xib awakefromnib

It Xcode 8 Xib - (void)awakeFromNib {} 's OK to write this before we use initialization, but Xcode 8 there's a warning like this:

官方解释:
You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require.

You may call the super implementation at any point during your own awakeFromNib method.


你必须调用父类实现awakeFromNib来给父类来执行它们需要的任何额外的初始化的机会。
虽然这种方法的默认实现不做任何事情,许多UIKit类提供非空的实现。
你可以调用自己的awakeFromNib方法中的任何时候超级实现。

15、推送的时候,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 info.plist.

Solution: To change the application's capabilities in Xcode to open remote notifications, refer to:


16、One of the two will 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 both would be used. Which one is undefined.

In the simulator, discover "one of the the both would beused." Which one is undefined. " Log

Find out why: OBJC runtime uses the same namespace (flat namespace) for the app, and runs the following mechanism:
    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 issue occurs when your resource file [contains 16-bit graphs] or the [picture display mode gamma is ' P3 '] and iOS targets is set to iOS 9.3. If your app needs to support wide gamut display, then you have to set target to iOS 9.3+, but if your app doesn't need to support wide gamut and you want to be compatible with iOS 9.3, you have to put all 16-bit or display modes as ' P3 ' Images are all replaced with 8-bit patterns of sRGB color pictures.

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

1. Export the project's IPA file

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

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

4. Open terminal sickness switch to the. App Bundle folder under the Payload folder in your app, in the following form:

CD Path/to/payload/your.app

5. Use the Find command to navigate to the Assets.car file. App bundle in the following form:

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 content that contains "Displaygamut": "P3" or related. The value for this JSON's "Name" field is either a 16-bit or a resource file name that displays a gamma value of P3.


8.  找到这个资源文件修改为 8位的sRGB形式,重新编译上传你的app即可. 


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

Editing the project by default using Xcode8 open, causing me to open with Xcode7 Xib is an error:

version does 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 the editor will xib inside the following sentence deleted to open:

<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>

IOS-How to Fit iOS10 (episode)

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.