Adaptation issues with IOS 10

Source: Internet
Author: User
Tags 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 always return no,substringtoindex:1 in iOS 10 will be detected as iOS 1,

The following methods should be used:

This is written in 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}]) { NSLog(@"Hello from > iOS 9.1");}if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9,3,0}]) { NSLog(@"Hello from > iOS 9.3");}

or use:

if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_9_0) { // do stuff for iOS 9 and newer} else { // do stuff for older versions than iOS 9}

Some constants are sometimes missing, nsfoundationversionnumber is defined in NSObjCRuntime.h, and as part of 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 a 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 add nscontactsusagedescription key in Info.plist, value to fill out the optional, here is listed in 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 select the current target in Xcode, select capabilities, find background Modes, open it, select the corresponding permission

3.UIColor problem

The official document says that most of the graphics frames and avfoundation at the beginning of the core increase support for extended pixel and wide color gamut color space. This 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 the project is converted to use sRGB, and two new APIs are added to the Uicolor 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 for display and performance balance effect, if this function is required, can be configured in the Info.plist (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> // 游戏模式

That is, if your project is reading class, choose Uiwhitepointadaptivitystylereading This mode, the five mode display effect is descending from the top, that is, if your project is a picture processing class, you choose the reading mode, Giving the choice too good effect can affect performance.

5.ATS problem

1. In iOS 9, the default non-HTTs network is forbidden, we can add the Nsapptransportsecurity dictionary in the Info.plist file, set the nsallowsarbitraryloads to Yes to disable ATS;

2. Starting January 1, 2017, all newly submitted apps do not allow Nsallowsarbitraryloads to bypass ATS by default, and by default your app can access encrypted enough (TLS V1.2 above) HTTPS content;

3. You can choose to use Nsexceptiondomains to set up a whitelist to open HTTP content for a specific domain to be audited, for example, your app integrates third-party login sharing SDK, which can be done in this way, following the Sina SDK as a demonstration (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> & nbsp <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, the Info.plist file added the Nsallowsarbitraryloadsinwebcontent key, allowing any Web page to load, and Apple will use ATS to protect your app;

5. Secure transmission no longer supports SSLV3, it is recommended to deactivate SHA1 and 3DES algorithm as soon as possible;

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 added the Textcontenttype field, which is the Uitextcontenttype type, which is an enumeration that allows you to specify the type of the input box, So that the system can parse out the semantics of the user. is the telephone type on the recommended number of phone, is the address type is suggested some address. In the #import file, you can view the Textcontenttype field with the following types of choices:

Uikit_extern Uitextcontenttype Const uitextcontenttypename                      ns_available_ios (10_0); Uikit_extern Uitextcontenttype Const Uitextcontenttypenameprefix                n S_available_ios (10_0); Uikit_extern Uitextcontenttype Const uitextcontenttypegivenname                 NS _available_ios (10_0); Uikit_extern Uitextcontenttype Const uitextcontenttypemiddlename                n S_available_ios (10_0); Uikit_extern Uitextcontenttype Const uitextcontenttypefamilyname                n S_available_ios (10_0); Uikit_extern Uitextcontenttype Const Uitextcontenttypenamesuffix                n S_available_ios (10_0); Uikit_extern Uitextcontenttype Const uitextcontenttypenickname                 &NB Sp Ns_available_ios (10_0); Uikit_extern Uitextcontenttype Const uitextcontenttypejobtitle                 &NB Sp Ns_available_ios (10_0); Uikit_extern Uitextcontenttype Const uitextcontenttypeorganizationname          ns_available_ IOS (10_0); Uikit_extern Uitextcontenttype Const uitextcontenttypelocation                 &NB Sp 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_ava Ilable_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_ava Ilable_ios (10_0); Uikit_extern Uitextcontenttype Const uitextcontenttypecountryname               Ns_ava Ilable_ios (10_0); Uikit_extern Uitextcontenttype Const Uitextcontenttypepostalcode                n S_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 similar to the network request, first sent a request to get the response process, but also encapsulated the error, you can do some additional operations in the various state methods, and can get some fields, such as the sender and so on. The header file for this feature is: #import

The following documents 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.用户滑动屏幕,屏幕外有一个cell准备加载进来,把cell从reusr队列拿出来,然后调用prepareForReuse方法,在这个方法里面,可以重置cell的状态,加载新的数据;    2.继续滑动,就会调用cellForItemAtIndexPath方法,在这个方法里面给cell赋值模型,然后返回给系统;    3.当cell马上进去屏幕的时候,就会调用willDisplayCell方法,在这个方法里面我们还可以修改cell,为进入屏幕做最后的准备工作;    4.执行完willDisplayCell方法后,cell就进去屏幕了.当cell完全离开屏幕以后,会调用didEndDisplayingCell方法.

The life cycle of IOS Uicollectionviewcell is this:

    1. User swipe 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 has not yet entered the screen, it has been called earlier this method, The difference before is that the method is called when the upper edge of the cell is immediately in the screen, and iOS 10 is called before the cell is out of the screen;   &NBSP;2. Create cells in Cellforitematindexpath, populate data, refresh State, and so on, compared to earlier;    3. If the user continues to slide, then we call the Willdisplaycell method when the cell needs to be displayed, the principle is: when to display, when to call the 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, Just call the Willdisplaycell method to re-appear on the screen.    ios 10, the system is one to load the cell, two before the line is loaded, so you can improve a lot of performance;    ios 10 new added pre-fetching preload     This 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 has been 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 asynchronous 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 10.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 a question, I will continue to improve the project.

Adaptation issues with IOS 10

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.