How to Adapt iOS 10 to ios 10

Source: Internet
Author: User

How to Adapt iOS 10 to ios 10

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

How can I adapt to iOS10 as a developer?

1. Notification)

SinceNotificationAfter it was introduced, Apple constantly updated and optimized, but these updates and optimizations were just a bit of a hassle. So far, iOS 10 has been truly undergoing major changes and restructuring, which has made developers realizeUserNotificationsEasy to use and powerful features.

  • Notifications before iOS 9

    1. When calling methods, some methods are difficult to distinguish and are easy to write wrong methods, which makes developers sometimes very worried.

    2. The paths for the application to capture notifications at runtime and non-runtime are inconsistent.

    3. Remote notifications cannot be directly displayed when the application is on the frontend. Further Processing is required.

    4. the notifications that have been sent cannot be updated, and the content cannot be changed when it is sent. In addition, only the simple text display method is available, and the scalability is not very good at all.

  • Notifications starting with iOS 10

    1. All related notifications are unifiedUserNotifications.frameworkFramework.

    2. Added undo, update, and notification content that can be modified midway through.

    3. Notifications are no longer in simple text. You can add videos, images, and display custom notifications.

    4. Compared with previous notifications, iOS 10 is easier to use and manage, and has been optimized on a large scale. This is a good thing for developers.

    5. Since iOS 10, the permission issue has been optimized, so it is easy to apply for permissions (local and remote notifications are integrated in a method ).

2. ATS Problems

In iOS 9, non-HTTS networks are disabled by default.NSAllowsArbitraryLoadsSetYESDisableATS. However, since January 1, 2017, iOS 10 does not allow us to skip this method.ATSThat is to say, force us to useHTTPSIf this is not the case, the App may be rejected. But we can useNSExceptionDomainsFor specific domain namesHTTPIt is easy to pass the review.

3. Privacy permission settings for iOS 10

Since iOS 10, the privacy permission is more strict. If you do not set the permission, it will crash directly. Now many crash problems are encountered. The general solution isinfo.plistAdd the correspondingKey-ValueYou can.

OfAccess albumOfKeyIncorrect addition. Which of the following statements is correct?Privacy - Photo Library Usage Description.

AboveValueThe text of the circled red line is displayed to the user and must be added.

4. Xcode 8 running a bunch of useless logs Solutions

 

We can see that a newly created Project prints a bunch of bad things without doing anything. I think this should beXcode 8Problems,

The solution is to setOS_ACTIVITY_MODE : disableFor example:

5. iOS 10 UIStatusBar method expired:

 

It may be used in our development.UIStatusBarSome attributes. in iOS 10, these methods have expired. If your project is useful, you need to adapt them.

The image above can also be found, if you need to usepreferredStatusBarFor example:

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

 

6. iOS 10 UICollectionView Performance Optimization

WithUICollectionViewTrust, there are many places in the project, but there are still some problems, such as sometimes slow loading. ThereforeUICollectionViewFurther optimization.

  • UICollectionView cell pre-fetching pre-loading mechanism
  • New API for UICollectionView and UITableView prefetchDataSource
  • Improvement on self-sizing cells
  • Interactive reordering

Before iOS 10, if there were a large number of cells in the UICollectionView, when the user activity was very fast, the whole UICollectionView was choppy obviously. Why would this problem occur, this involves the iOS system's reuse mechanism. when the cell is ready to be loaded into the screen, the entire cell has been loaded and is waiting outside the screen, that is, the entire row of cells has been loaded, which is the main cause of choppy. The term is frame drop.
To make users feel stuck, our app must have a frame rate of 60 frames/second, that is, refresh every frame in 16 milliseconds.

Before iOS 10, the life cycle of UICollectionViewCell is as follows:
  • 1. the user slides the screen, and a cell is ready to be loaded out of the screen, takes the cell out of the reusr queue, and then callsprepareForReuseMethod. In this method, You can reset the cell status and load new data;
  • 2. continue to slide and you will callcellForItemAtIndexPathMethod: assign a model to the cell in this method, and then return it to the system;
  • 3. When the cell enters the screen immediately, it will callwillDisplayCellIn this method, we can also modify the cell to make the final preparations for the screen;
  • 4. Execution completedwillDisplayCellWhen the cell is completely out of the screen, it will calldidEndDisplayingCellMethod.
The life cycle of iOS 10 UICollectionViewCell is as follows:
  • 1. the user slides the screen, and a cell is ready to be loaded out of the screen, takes the cell out of the reusr queue, and then callsprepareForReuseMethod. When the cell has not been included in the screen, this method has been called in advance, the difference is that this method is called when the upper edge of the cell enters the screen immediately, while iOS 10 calls this method before the cell is out of the screen;
  • 2. IncellForItemAtIndexPathCell creation, data filling, and refresh status are performed in advance;
  • 3. If the user continues to slide, we will call it when the cell needs to be displayed immediately.willDisplayCellThe principle is: When to display and when to callwillDisplayCellMethod;
  • 4. When the cell completely leaves the screen, it will calldidEndDisplayingCellMethod, as before, the cell will enter the reuse queue.
    Before iOS 10, the cell can only be retrieved from the reuse queue, and then go through the lifecycle and callcellForItemAtIndexPathCreate or generate a cell.
    In iOS 10, the system will save the cell for a period of time. That is to say, after the user slides the cell out of the screen, if the cell slides back, the cell does not need to go through the lifecycle again, but only needs to be called.willDisplayCellMethod to appear on the screen again.
    In iOS 10, the system loads cells one by one, and the second is loaded by one row in the past, which can improve a lot of performance; the newly added Pre-Fetching in iOS 10 is designed to reduce the time it takes for UICollectionViewCell to load. in iOS 10, apart from the data source protocol and proxy protocol, A newUICollectionViewDataSourcePrefetchingProtocol, which defines two methods:
  - (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);

InColletionView prefetchItemsAt indexPathsThis method is used to asynchronously pre-load data.indexPathsArrays are ordered, that is, the order in which items receive data;
   CollectionView cancelPrefetcingForItemsAt indexPathsThis method is optional and can be used to cancel or reduce the priority of loading data in advance during sliding.
Note: This Protocol does not replace the previous method of reading data. It only helps to load data.
Pre-Fetching Pre-loading is also applicable to UITableViewCell.


 

7. New Methods for iOS 10 UIColor

The following is a description of the official documentation:

Most graphics frameworks throughout the system, including Core Graphics, Core Image, Metal, and AVFoundation, have substantially 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 ever to support devices with a wide color display. in addition, UIKit standardizes on working in a new extended sRGB color space, making it easy to mix sRGB colors with colors in other, wider color gamuts without a significant performance penalty.

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

  • In iOS 10, 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 you're creating a color or asking a color for its component values ), you need to change your app's behavior when you link against iOS 10.

  • When drawing Ming DRAM drawing in a UIView on an iPad Pro (9.7 inch), the underlying drawing environment is configured with an extended sRGB color space.

  • If your app renders custom image objects, use the new UIGraphicsImageRenderer class to control whether the destination bitmap is created using an extended-range or standard-range format.

  • If you are using Ming your own image processing on wide-gamut devices using a lower level API, such as Core Graphics or Metal, you shoshould use an extended range color space and a pixel format that supports 16-bit floating-point component values. when clamping of color values is necessary, you shoshould do so explicitly.

  • Core Graphics, Core Image, and Metal Performance Shaders provide new options for easily converting colors and images between color spaces.

Because we used it all before.RGBTo set the color, it is not very diverse to use, this new method should be a compensation. Therefore, we recommend that you usesRGBBecause of its better performance and richer colors. If youUIColorIf you have written a set of categories, you can try to replace themsRGB,UIColorTwo newApiAs 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 10 UITextContentType
// The textContentType property is to provide the keyboard with extra information about the semantic intent of the text document.@property(nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0); // default is nil

In iOS 10UITextFieldAddedtextContentTypeEnumeration indicates the semantic meaning of the text input area.

This attribute can be used to give keyboard and system information about the expected semantic meaning of user input content. For example, you can specify a text field.uitextcontenttypeemailaddress. When you provide information about the content you expect users to enter in the text input area, the system can automatically select the appropriate keyboard in some cases, it also improves keyboard correction and integration with other text input opportunities.

  9. the iOS 10 font changes with the font of the mobile phone system.

When the font of our mobile phone system changesAppOflabelIt will also change. This requires us to write a lot of code for further processing, but iOS 10 provides this attribute.adjustsFontForContentSizeCategory. Because there is no real machine, the actual operation has not been implemented. If you understand the error, correct it.

UILabel * myLabel = [UILabel new];/* UIFont preferredFontForTextStyle: Specifies a style and makes the font size conform to the font size you set. */MyLabel. font = [UIFont preferredFontForTextStyle: UIFontTextStyleHeadline];/* Indicates whether the corresponding element shocould 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. * /// whether to update the font change myLabel. adjustsFontForContentSizeCategory = YES;

 

10. Added refreshControl for iOS 10 UIScrollView

 

After iOS 10, as long as it is inheritedUIScrollViewThe refresh function is supported:

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


11. iOS 10 determines the correct system version posture

Judging the system version is often used, especially now that everyone may need to adapt to iOS 10, the problem arises, for example:

The answer is:

// The value is 1 [[[UIDevice currentDevice] systemVersion] substringToIndex: 1] integerValue]

// The value is 10.000000 [[[UIDevice currentDevice] systemVersion]. floatValue,

// The value is 10.0 [[UIDevice currentDevice] systemVersion]

Therefore, it is best to use the following two methods to determine the system method ~ I forgot to say[[UIDevice currentDevice] systemVersion].floatValueThis method is also unreliable, as if in8.3The output value is8.2It is unreliable, so we recommend that you[[UIDevice currentDevice] systemVersion]This method!

Swift judges:

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

12. Xcode 8 plug-in unavailable

Everyone has upgradedXcode 8But developers who rely on plug-ins are crying and searching for solutions online. The solution is as follows:
Let your Xcode8 continue using the plug-in (http://vongloo.me/2016/09/10/Make-Your-Xcode8-Great-Again? Utm_source = tuicool & utm_medium = referral)

However, according to the final explanation in the article, we know that if a plug-in is used, there may be security issues and the submission for review will be rejected. Therefore, we suggest you do not use the plug-in. There are always solutions, for exampleXcodeIt is also very convenient to add comments to the code block.

13. Incomplete text display in the project started with iOS 10

I useXcode 8AndXcode 7.3Tested separately, for example:

Xcode 8



Xcode7

CreateLabelThen make it adaptive, the font size is all17The output width is different. Let's take a look,
The following data shows why the upgrade is performed.iOS 10AfterAppThe text in is incomplete:



I passed the test again and found that there was no problem with English letters, but there was a problem with Chinese characters.
Currently, only one widget can be modified to solve this problem.


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.