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).
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
.
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 访问相册
addition of the Key
wrong, correct is Privacy - Photo Library Usage Description
.
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:
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 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.
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
中有的文字显示不全了:
英文字母会不会也有这种问题,我又通过测试,后来发现英文字母没有问题,只有汉字有问题。
目前只有一个一个修改控件解决这个问题,暂时没有其他好办法来解决。
"Go" iOS Learning adapter iOS10