IOS 10 version Adaptation issue collection-B

Source: Internet
Author: User
Tags uikit color gamut

With IOS10 released near, everyone's app needs to fit iOS10, here are some of my summary of iOS10 adaptation aspects, if there are errors, welcome to point out.

1. System Judgment Method Failure:

In your project, when you need to determine the system version, do not use the following method:

#define isiOS10 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=10)

It will return forever NO and iOS substringToIndex:1 10 will be detected as iOS 1 and should use these methods: Objective-c:

#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

or use:

if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 9, .minorVersion = 1, .patchVersion = 0}]) {// 代码块}if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9,3,0}]) { // 代码块}

or use:

if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_9_0) { // 代码块} else { // 代码块}

Sometimes the missing constants NSFoundationVersionNumber are defined in, NSObjCRuntime.h as part of the Xcode7.3.1, we set the Changshu range from iphone OS 2 to #define NSFoundationVersionNumber_iOS_8_4 1144.17 , in iOS (Xcode 8), Apple supplements the missing numbers and sets the future version.

#define NSFoundationVersionNumber_iOS_9_0 1240.1#define NSFoundationVersionNumber_iOS_9_1 1241.14#define NSFoundationVersionNumber_iOS_9_2 1242.12#define NSFoundationVersionNumber_iOS_9_3 1242.12#define NSFoundationVersionNumber_iOS_9_4 1280.25#define NSFoundationVersionNumber_iOS_9_x_Max 1299

This is written in Swift:

if NSProcessInfo().isOperatingSystemAtLeastVersion(NSOperatingSystemVersion(majorVersion: 10, minorVersion: 0, patchVersion: 0)) { // 代码块}

or use

if #available(iOS 10.0, *) { // 代码块} else { // 代码块}
2. Privacy Data access issues:

Your project access to private data, such as: Cameras, albums, contacts, etc., in the Xcode8 to open the compilation, all will be crash, the console will output the following such a log:

This is due to the increased security and privacy of iOS, and the need to add a description when requesting many private permissions, however, Xcode before using Xcode 8 uses the system's permission notification box. To solve this problem, only need to info.plist add NSContactsUsageDescription the key, the value of its own random fill can be, here to list the corresponding key (Source code mode):

<!--albums-<key>NSPhotoLibraryUsageDescription</key> <string>app requires your consent to access the album </string > <!--camera--<key>NSCameraUsageDescription</key> <string>app requires your consent to access the camera </string > <!--Microphone--<key>NSMicrophoneUsageDescription</key> <string>app requires your consent to access the microphone </ String> <!--location-<key>NSLocationUsageDescription</key> <string>app requires your consent to access the location </ String> <!--access Location-<key>NSLocationWhenInUseUsageDescription</key> <string> The app requires your consent to access location </string> <!--always access location--<key>NSLocationAlwaysUsageDescription</key> <string>app requires your consent to always access the location </string> <!--calendar--<key>nscalendarsusagedescription</key > <string>app Need your consent to access Calendar </string> <!--reminders-<key>nsremindersusagedescription</ Key> <string>app need your consent to access reminders </string> <!--sports and fitness--<key>nsmotionusaGedescription</key> <string>app need your consent to access sports and fitness </string> <!--health Updates--<key> Nshealthupdateusagedescription</key> <string>app requires your consent to access health updates </string> <!--health Sharing--< Key>nshealthshareusagedescription</key> <string>app need your consent to access health sharing </string> <!--Bluetooth-- <key>NSBluetoothPeripheralUsageDescription</key> <string>app need your consent to access Bluetooth </string> <! --Media Library-<key>NSAppleMusicUsageDescription</key> <string>app requires your consent to access the Media Library </string >

If it doesn't work, you can request background permissions, similar to this:

<key>UIBackgroundModes</key><array> <!-- 在这里写上你在后台模式下要使用权限对应的key --> <string>location</string>...</array>

Or in Xcode Select Current target , select Capabilities , find Background Modes , open it, select the corresponding permission inside

3.UIColor problem

The official document says: Most core of the opening graphics frames and AVFoundation all increase support for extended pixel and wide color gamut color space. This approach is easier than ever to support a wide-color display device in a graphics stack extension. The Uikit extension can now work in sRGB's color space, with better performance, and with sRGB color in a wider gamut. If your project is graphically processed by a low-level API, it is recommended that you use sRGB, That is, the proposal to use RGB conversion colors in a project translates to using sRGB, with UIColor two new APIs in the class:

- (UIColor *)initWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);+ (UIColor *)colorWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);
4. Display of True Color

True Color display will be based on the light sensor from the motion of the adjustment to achieve a specific environment and performance of the balance effect, if this function is required, can be info.plist configured in (in source code mode):

<key>UIWhitePointAdaptivityStyle</key>

It has five kinds of values, namely:

<string>UIWhitePointAdaptivityStyleStandard</string> // 标准模式<string>UIWhitePointAdaptivityStyleReading</string> // 阅读模式<string>UIWhitePointAdaptivityStylePhoto</string> // 图片模式<string>UIWhitePointAdaptivityStyleVideo</string> // 视频模式<string>UIWhitePointAdaptivityStyleStandard</string> // 游戏模式

In other words, if your project is reading class, choose UIWhitePointAdaptivityStyleReading This mode, the five modes of the display effect is descending from the top, that is, if your project is a picture processing class, you choose the Reading mode, to choose too good effect will affect performance.

5.ATS problem

1. On iOS 9, the default non-HTTs network is forbidden, and we can add the nsapptransportsecurity dictionary to the info.plist file, and the Nsallowsarbitraryloads set to YES to disable ATS; 2. From January 1, 2017 onwards, all newly submitted apps will not allow nsallowsarbitraryloads to bypass ATS restrictions by default, and your app can access encryption strong enough (TLS V1.2 above) by default HTTPS content; 3. You can choose to use nsexceptiondomains to set up a whitelist to open HTTP content for a particular domain to be audited, for example, your app integrates a third-party login sharing SDK, which can be done in this way, The following is a demonstration of the Sina SDK (Source Code mode):

<key>NSAppTransportSecurity</key><dict><key>NSExceptionDomains</key><dict> <key>sina.cn</key><dict><key>NSThirdPartyExceptionMinimumTLSVersion</key>< string>tlsv1.0</string><key>nsthirdpartyexceptionrequiresforwardsecrecy</key><false/ ><key>NSIncludesSubdomains</key><true/></dict><key>weibo.cn</key>< dict><key>nsthirdpartyexceptionminimumtlsversion</key><string>tlsv1.0</string>< Key>nsthirdpartyexceptionrequiresforwardsecrecy</key><false/><key>nsincludessubdomains </key><true/></dict><key>weibo. com</key><dict><key>nsthirdpartyexceptionminimumtlsversion</key><string>tlsv1.0 </string><key>NSThirdPartyExceptionRequiresForwardSecrecy</key><false/><key> nsincludessubdomains</key><true/></dict><key>sinaimg.cn</key><dict><key>nsthirdpartyexceptionminimumtlsversion</key><string>tlsv1.0</ String><key>nsthirdpartyexceptionrequiresforwardsecrecy</key><false/><key> Nsincludessubdomains</key><true/></dict><key>sinajs.cn</key><dict><key >NSThirdPartyExceptionMinimumTLSVersion</key><string>TLSv1.0</string><key> Nsthirdpartyexceptionrequiresforwardsecrecy</key><false/><key>nsincludessubdomains</key ><true/></dict><key>sina.com.cn</key><dict><key> Nsthirdpartyexceptionminimumtlsversion</key><string>tlsv1.0</string><key> Nsthirdpartyexceptionrequiresforwardsecrecy</key><false/><key>nsincludessubdomains</key ><true/></dict></dict></dict>

4. In iOS 10 info.plist , a new NSAllowsArbitraryLoadsInWebContent key is added to the file, allowing any Web page to load, and Apple will use ATS to protect your app; 5. Safe transmission is no longer supported SSLv3 , it is recommended to deactivate and algorithm as soon as possible SHA1 3DES ;

6.UIStatusBar problem:

In IOS10, if you also use previously set Uistatusbar types or control hidden or displayed methods, the warning is reported and the method expires, such as:

The above method to IOS 10 cannot be used, to modify the Uistatusbar style or state using the properties or methods shown in:

@property(nonatomic, readonly) UIStatusBarStyle preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault@property(nonatomic, readonly) BOOL prefersStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to NO- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to NO// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarAnimationFade
7.UITextField

In iOS 10, Uitextfield has the new textcontenttype field, which is the uitextcontenttype type, which is an enumeration The function is to specify the type of the input box so that the system can parse out the user's semantics. is the telephone type on the recommended number of calls, is the address type suggested some addresses. Available in #import <UIKit/UITextInputTraits.h> file, view the textcontenttype field with the following types of options:

Uikit_extern Uitextcontenttype const Uitextcontenttypename Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypenameprefix Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypegivenname Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypemiddlename Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypefamilyname Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypenamesuffix Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypenickname Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypejobtitle Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypeorganizationname Ns_available_ios (10_0);           Uikit_extern Uitextcontenttype Const Uitextcontenttypelocation       Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const uitextcontenttypefullstreetaddress Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const UITEXTCONTENTTYPESTREETADDRESSLINE1 Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const UITextContentTypeStreetAddressLine2 Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const uitextcontenttypeaddresscity Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const uitextcontenttypeaddressstate Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const uitextcontenttypeaddresscityandstate Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const uitextcontenttypesublocality Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypecountryname Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypepostalcode Ns_available_ios (10_0); Uikit_extern Uitextcontenttype Const UitextContenttypetelephonenumber Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const uitextcontenttypeemailaddress Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypeurl Ns_available_ios (10_0); Uikit_extern Uitextcontenttype const Uitextcontenttypecreditcardnumber Ns_available_ios (10_0);
8.UserNotifications (user notification)

IOS 10 will notify the associated APIs to be unified, based on a number of user-defined notifications, and can capture callbacks for individual notification states. The concept of prior notification is: Everyone wants to be prepared in advance, and then a full two distribution, confiscated to also don't care about the sender, Now the user notification made a similar to the network request, the first to send a request get response process, also encapsulated error , can be in the various state of the method to do some additional operations, and can get some fields, such as the sender and so on. The header file for this feature is: The #import <UserNotifications/UserNotifications.h> following files are mainly available:

#import <UserNotifications/NSString+UserNotifications.h>#import <UserNotifications/UNError.h>#import <UserNotifications/UNNotification.h>#import <UserNotifications/UNNotificationAction.h>#import <UserNotifications/UNNotificationAttachment.h>#import <UserNotifications/UNNotificationCategory.h>#import <UserNotifications/UNNotificationContent.h>#import <UserNotifications/UNNotificationRequest.h>#import <UserNotifications/UNNotificationResponse.h>#import <UserNotifications/UNNotificationSettings.h>#import <UserNotifications/UNNotificationSound.h>#import <UserNotifications/UNNotificationTrigger.h>#import <UserNotifications/UNUserNotificationCenter.h>#import <UserNotifications/UNNotificationServiceExtension.h>
Optimization of the 9.UICollectionViewCell

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, and then go through the lifecycle , and call Cellforitematindexpath to create or generate a cell. In iOS 10, the system will save a 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, just call Willdisplaycell Method can be re-appeared on the screen. iOS 10, the system is one to load the cell, two previously loaded in a row, so you can improve a lot of performance; IOS 10 The newly added pre-fetching preload is to reduce the time it takes for Uicollectionviewcell to load, In IOS 10, in addition to the data source protocol and the proxy protocol, a new uicollectionviewdatasourceprefetching protocol is added, 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);

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 indexPaths This 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.

Use of Uirefreshcontrol

In iOS 10, Uirefreshcontrol can be used directly in Uicollectionview and UITableView, And out of the Uitableviewcontroller. Now Refreshcontrol is a property of Uiscrollview. How to use:

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];    [refreshControl addTarget:self action:@selector(loadData) forControlEvents:UIControlEventValueChanged];    collectionView.refreshControl = refreshControl;

You are welcome to ask me, I will continue to improve the project

IOS 10 version Adaptation issue collection-B

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.