自從Notification被引入以後,蘋果就不斷的更新優化,但這些更新優化只是小打小鬧,直至如今iOS 10開始真正的進行大改重構,這讓開發者也體會到UserNotifications的易用,功能也變得很是強大。php
iOS 9 之前的通知java
1.在調用方法時,有些方法讓人很難區分,容易寫錯方法,這讓開發者有時候很苦惱。ios
2.應用在運行時和非運行時捕獲通知的路徑還不一致。數組
3.應用在前臺時,是沒法直接顯示遠程通知,還須要進一步處理。xcode
4.已經發出的通知是不能更新的,內容發出時是不能改變的,而且只有簡單文本展現方式,擴展性根本不是很好。緩存
iOS 10 開始的通知ruby
1.全部相關通知被統一到了UserNotifications.framework框架中。性能優化
2.增長了撤銷、更新、中途還能夠修改通知的內容。網絡
3.通知不在是簡單的文本了,能夠加入視頻、圖片,自定義通知的展現等等。架構
4.iOS 10相對以前的通知來講更加好用易於管理,而且進行了大規模優化,對於開發者來講是一件好事。
5.iOS 10開始對於權限問題進行了優化,申請權限就比較簡單了(本地與遠程通知集成在一個方法中)。
若是使用了推送:
iOS 10 通知學習相關資料:
UserNotifications: 蘋果官方文檔
-蘋果官方視頻1
- 蘋果官方視頻2
- 蘋果官方視頻3
活久見的重構 - iOS 10 UserNotifications 框架解析 WWDC2016 Session筆記 - iOS 10 推送Notification新特性
iOS 9中默認非HTTS的網絡是被禁止的,固然咱們也能夠把NSAllowsArbitraryLoads設置爲YES禁用ATS。不過iOS 10從2017年1月1日起蘋果不容許咱們經過這個方法跳過ATS,也就是說強制咱們用HTTPS,若是不這樣的話提交App可能會被拒絕。可是咱們能夠經過NSExceptionDomains來針對特定的域名開放HTTP能夠容易經過審覈。
NSExceptionDomains方式 設置域。能夠簡單理解成,把不支持https協議的接口設置成http的接口。
具體方法:
1)、在項目的info.plist中添加一個Key:App Transport Security Settings,類型爲字典類型。
2)、而後給它添加一個Exception Domains,類型爲字典類型;
3)、把須要的支持的域添加給Exception Domains。其中域做爲Key,類型爲字典類型。
4)、每一個域下面須要設置3個屬性:NSIncludesSubdomains、NSExceptionRequiresForwardSecrecy、NSExceptionAllowsInsecureHTTPLoads。
如圖:
細節提示:在iOS9之後的系統中若是使用到網絡圖片,也要注意網絡圖片是不是HTTP的哦,若是是,也要把圖片的域設置哦!
iOS 10 開始對隱私權限更加嚴格,若是你不設置就會直接崩潰,如今不少遇到崩潰問題了,通常解決辦法都是在info.plist文件添加對應的Key-Value就能夠了。
(錯誤: This app attempts to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.—訪問相冊失敗,請求權限
This app attempts to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.–訪問相機(二維碼識別等)錯誤,要求相機權限
)
以上Value值,圈出的紅線部分的文字是展現給用戶看的,必須添加。
Xcode8代碼出現ubsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0,,enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 2016-09-14 17:18:55.843428 MyApp[6880:340837]
本身新建的一個工程啥也沒幹就打印一堆爛七八糟的東西,我以爲這個應該是Xcode 8的問題,
具體也沒細研究,解決辦法是設置OS_ACTIVITY_MODE : disable
【product】-【scheme】-【Edit Scheme】-【Run】-【Argument】-【Environment Variable】添加keyValue【OS_ACTIVITY_MODE disable】能夠中止輸出打印此日誌
遺留問題:還會出現Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x10a39a910) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x10a1c4210). One of the two will be used. Which one is undefined.
在咱們開發中有可能用到UIStatusBar一些屬性,在iOS 10 中這些方法已通過期了,若是你的項目中有用的話就得須要適配。
UIStatusBarStyle 和 prefersStatusBarHidden這兩個屬性是readonly readonly readonly也就是說咱們若是在iOS 10中調用,你須要使用preferredStatusBar好比這樣:
//iOS 10
- (BOOL)prefersStatusBarHidden{ return YES; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; }
6.iOS 10 UICollectionView 性能優化
隨着開發者對UICollectionView的信賴,項目中用的地方也比較多,可是仍是存在一些問題,好比有時會卡頓、加載慢等。因此iOS 10 對UICollectionView進一步的優化。
UICollectionView cell pre-fetching預加載機制UICollectionView and UITableView prefetchDataSource 新增的API針對self-sizing cells 的改進Interactive reordering
在iOS 10 以前,UICollectionView上面若是有大量cell,當用戶活動很快的時候,整個UICollectionView的卡頓會很明顯,爲何會形成這樣的問題,這裏涉及到了iOS 系統的重用機制,當cell準備加載進屏幕的時候,整個cell都已經加載完成,等待在屏幕外面了,也就是整整一行cell都已經加載完畢,這就是形成卡頓的主要緣由,專業術語叫作:掉幀.要想讓用戶感受不到卡頓,咱們的app必須幀率達到60幀/秒,也就是說每幀16毫秒要刷新一次.
iOS 10 以前UICollectionViewCell的生命週期是這樣的:
1.用戶滑動屏幕,屏幕外有一個cell準備加載進來,把cell從reusr隊列拿出來,而後調用prepareForReuse方法,在這個方法裏面,能夠重置cell的狀態,加載新的數據;
2.繼續滑動,就會調用cellForItemAtIndexPath方法,在這個方法裏面給cell賦值模型,而後返回給系統;
3.當cell立刻進去屏幕的時候,就會調用willDisplayCell方法,在這個方法裏面咱們還能夠修改cell,爲進入屏幕作最後的準備工做;
iOS 10 UICollectionViewCell的生命週期是這樣的:
1.用戶滑動屏幕,屏幕外有一個cell準備加載進來,把cell從reusr隊列拿出來,而後調用prepareForReuse方法,在這裏當cell尚未進去屏幕的時候,就已經提早調用這個方法了,對比以前的區別是以前是cell的上邊緣立刻進去屏幕的時候就會調用該方法,而iOS 10 提早到cell還在屏幕外面的時候就調用;
2.在cellForItemAtIndexPath中建立cell,填充數據,刷新狀態等操做,相比於以前也提早了;
3.用戶繼續滑動的話,當cell立刻就須要顯示的時候咱們再調用willDisplayCell方法,原則就是:什麼時候須要顯示,什麼時候再去調用willDisplayCell方法;
4.當cell徹底離開屏幕之後,會調用didEndDisplayingCell方法,跟以前同樣,cell會進入重用隊列.
在iOS 10 以前,cell只能從重用隊列裏面取出,再走一遍生命週期,並調用cellForItemAtIndexPath建立或者生成一個cell.在iOS 10 中,系統會cell保存一段時間,也就是說當用戶把cell滑出屏幕之後,若是又滑動回來,cell不用再走一遍生命週期了,只須要調用willDisplayCell方法就能夠從新出如今屏幕中了.
iOS 10 中,系統是一個一個加載cell的,二之前是一行一行加載的,這樣就能夠提高不少性能;iOS 10 新增長的Pre-Fetching預加載這個是爲了下降UICollectionViewCell在加載的時候所花費的時間,在 iOS 10 中,除了數據源協議和代理協議外,新增長了一個UICollectionViewDataSourcePrefetching協議,這個協議裏面定義了兩個方法:
- (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray*)indexPaths NS_AVAILABLE_IOS(10_0); -(void)collectionView:(UICollectionView*)collectionView cancelPrefetchingForItemsAtIndexPaths:(NSArray*)indexPaths NS_AVAILABLE_IOS(10_0);
在ColletionView prefetchItemsAt indexPaths這個方法是異步預加載數據的,當中的indexPaths數組是有序的,就是item接收數據的順序;
CollectionView cancelPrefetcingForItemsAt indexPaths這個方法是可選的,能夠用來處理在滑動中取消或者下降提早加載數據的優先級.
注意:這個協議並不能代替以前讀取數據的方法,僅僅是輔助加載數據.
Pre-Fetching預加載對UITableViewCell一樣適用.
WWDC2016 Session筆記 - iOS 10 UICollectionView新特性
如下是官方文檔的說明:
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.
(譯:大多數圖形架構整個系統,包括核心圖形核心形象,金屬,和AVFoundation,有擴展範圍的像素格式和寬色域的色彩空間大幅改善的支持。經過將此行爲擴展到整個圖形堆棧中,它比以往任什麼時候候都更容易支持具備寬顏色顯示的設備。此外,UIKit規範在新擴展的sRGB色彩空間工做,所以很容易與其餘顏色混合的sRGB顏色,更寬的色域不顯著的性能損失。)
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.
(譯:在iOS 10中,該UIColor類使用擴展的sRGB色彩空間和初始化再也不夾原成分值在0和1之間。若是你的應用程序依賴UIKit夾緊元件值(不管你是建立一個顏色或要求顏色其組件的值),你須要改變你的應用程序的行爲時,你的連接和iOS 10。)
When performing custom drawing in a UIView on an iPad Pro (9.7 inch), the underlying drawing environment is configured with an extended sRGB color space.
(譯:當執行在iPad上親一個UIView的自定義繪製(9.7英寸),基本的繪圖環境配置一個擴展的sRGB色彩空間。)
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.
(譯:若是你的應用程序提供自定義的圖像對象,使用新的uigraphicsimagerenderer類控制是否目標位圖是使用擴展的範圍或標準格式建立。)
If you are performing your own image processing on wide-gamut devices using a lower level API, such as Core Graphics or Metal, 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 is necessary, you should do so explicitly.
(譯:若是您正在使用較低級別的接口,如核心圖形或金屬,在寬色域設備上執行本身的圖像處理,則應該使用擴展的範圍顏色空間和支持16位浮點組件值的像素格式。當對顏色值進行夾緊是必要的,你應該明確地這樣作。)
Core Graphics, Core Image, and Metal Performance Shaders provide new options for easily converting colors and images between color spaces.
(譯:圖形核心,核心形象,和金屬的性能提供了新的選擇,很容易着色的顏色和圖像之間的顏色空間轉換。)
由於以前咱們都是用RGB來設置顏色,反正用起來也不是特別多樣化,此次新增的方法應該就是一個彌補吧。因此在iOS 10 蘋果官方建議咱們使用sRGB,由於它性能更好,色彩更豐富。若是你本身爲UIColor寫了一套分類的話也可嘗試替換爲sRGB,UIColor類中新增了兩個Api以下:
+(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
在iOS 10 UITextField添加了textContentType枚舉,指示文本輸入區域所指望的語義意義。
使用此屬性能夠給鍵盤和系統信息,關於用戶輸入的內容的預期的語義意義。例如,您能夠指定一個文本字段,用戶填寫收到一封電子郵件確認uitextcontenttypeemailaddress。當您提供有關您指望用戶在文本輸入區域中輸入的內容的信息時,系統能夠在某些狀況下自動選擇適當的鍵盤,並提升鍵盤修正和主動與其餘文本輸入機會的整合。
當咱們手機系統字體改變了以後,那咱們App的label也會跟着一塊兒變化,這須要咱們寫不少代碼來進一步處理才能實現,可是iOS 10 提供了這樣的屬性adjustsFontForContentSizeCategory來設置。由於沒有真機,具體實際操做還沒去實現,若是理解錯誤幫忙指正。
UILabel *myLabel = [UILabel new]; /* UIFont 的preferredFontForTextStyle: 意思是指定一個樣式,並讓字體大小符合用戶設定的字體大小。 */ myLabel.font =[UIFont preferredFontForTextStyle: UIFontTextStyleHeadline]; /* 指示是否應自動更新相應元素的字體時,裝置的uicontentsizecategory。 這個屬性生效,元素的字體必須使用+ preferredfontfortextstyle: 或+ preferredfontfortextstyle:compatiblewithtraitcollection:一個有效的uifonttextstyle。 */ //是否更新字體的變化 myLabel.adjustsFontForContentSizeCategory = YES;
iOS 10 之後只要是繼承UIScrollView那麼就支持刷新功能:
@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED; - (instancetype)init; @property (nonatomic, readonly, getter=isRefreshing) BOOL refreshing; @property (null_resettable, nonatomic, strong) UIColor *tintColor; @property (nullable, nonatomic, strong) NSAttributedString *attributedTitle UI_APPEARANCE_SELECTOR; // May be used to indicate to the refreshControl that an external event has initiated the refresh action - (void)beginRefreshing NS_AVAILABLE_IOS(6_0); // Must be explicitly called when the refreshing has completed - (void)endRefreshing NS_AVAILABLE_IOS(6_0);
11.iOS 10 判斷系統版本正確姿式
判斷系統版本是咱們常常用到的,尤爲是如今你們都有可能須要適配iOS 10,那麼問題就出現了,以下圖:
咱們獲得了答案是:
//值爲 1 [[[[UIDevice currentDevice] systemVersion] substringToIndex:1] integerValue] //值爲10.000000 [[UIDevice currentDevice] systemVersion].floatValue, //值爲10.0 [[UIDevice currentDevice] systemVersion]
因此說判斷系統方法最好仍是用後面的兩種方法,哦~我忘記說了[[UIDevice currentDevice] systemVersion].floatValue這個方法也是不靠譜的,好像在8.3版本輸出的值是8.2,記不清楚了反正是不靠譜的,因此建議你們用[[UIDevice currentDevice] systemVersion]這個方法!
Swift判斷以下:
if #available(iOS 10.0, *) { // iOS 10.0 print("iOS 10.0"); } else { }
12.推送的時候,開啓Remote notificationsYou’ve implemented -[application:didReceiveRemoteNotification:fetchCompletionHandler:],
but you still need to add 「remote-notification」 to the list of your supported UIBackgroundModes in your Info.plist.
解決方案:須要在Xcode 中修改應用的 Capabilities 開啓Remote notifications,請參考下圖:
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 two will be used. Which one is undefined.
在模擬器中、發現「One of the two will be used. Which one is undefined.」日誌
查找資料發現緣由:objc runtime 對所用app使用同一個命名空間(flat namespace),運行機制以下:
首先二進制映像被加載,檢查程序依賴關係
每個二進制映像被加載的同時,程序的objc classes在objc runtime命名空間中註冊
若是具備相同名稱的類被再次加載,objc runtime的行爲是不可預知的。一種可能的狀況是任意一個程序的該類會被加載(這應該也是默認動做)
解決方法:在終端輸入
//sudo /usr/libexec/xpccachectl
重啓電腦便可.
另外:Xcode 推出來快速文本註釋:Command +Option +/
/** <#Description#> @param frame <#frame description#> @return <#return value description#> */ - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self initUiConfig]; } return self; }
這個問題剛開始估計你們都會碰到也是第一個要解決的問題
這個問題就是一個證書的設置問題,下面看兩張圖
正常咱們會在BuildeSettings中設置證書:
可是在xcode8.0中咱們看到下面的新特性:
相信你們都能看到在Genreal下面會有Siging,沒錯這就是新特性,爲了方便用戶來管理,你們能夠選擇Automatically manage signing。須要輸入開發者帳號!若是沒有帳號也不要緊,在下面也能夠選擇Debug、Realease、inHouse模式下對應的證書也能夠!
可是 可是 可是 若是你的證書若是是通配符類型的,可是你的app包含了好比推送、apple pay、他會報錯提示你未報含xx.id的manteid等等。因此你要生成針對你app的bundleid對應的證書!
咱們知道用戶沒開啓,確定要提醒用戶去設置開啓的吧,因此咱們要跳轉到app的隱私數據界面。如何調用呢
iOS10 以前調用方法:
NSURL*url=[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]; [[UIApplication sharedApplication] openURL:url];
可是iOS10 以後不能再調用此方法進行跳轉隱私設置界面.
iOS10以後:
1)定義一個宏方便調用
//-----------------------系統權限設置路徑(iOS8之後適用)--------------------- //url #define SettingURL [NSURL URLWithString:UIApplicationOpenSettingsURLString] //調到設置 #define GoToSetting if([[UIApplication sharedApplication] canOpenURL:SettingURL]) { \ [[UIApplication sharedApplication] openURL:SettingURL];}}
調用
//去設置 if (IOS8_OR_LATER) { GoToSetting; }
2,方法中直接調用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
真彩色的顯示會根據光感應器來自動的調節達到特定環境下顯示與性能的平衡效果,若是須要這個功能的話,能夠在info.plist裏配置(在Source Code模式下):
UIWhitePointAdaptivityStyle
它有五種取值,分別是:
UIWhitePointAdaptivityStyleStandard // 標準模式 UIWhitePointAdaptivityStyleReading // 閱讀模式 UIWhitePointAdaptivityStylePhoto // 圖片模式 UIWhitePointAdaptivityStyleVideo // 視頻模式 UIWhitePointAdaptivityStyleStandard // 遊戲模式
若是你的項目是遊戲類的,就選擇UIWhitePointAdaptivityStyleStandard這個模式,五種模式的顯示效果是從上往下遞減,也就是說若是你的項目是圖片處理類的,你選擇的是閱讀模式,給選擇太好的效果會影響性能.
使用Xcode8打開xib文件後,會出現下圖的提示。
QQ20160913-9.png-41.7kB
你們選擇Choose Device便可。
以後你們會發現佈局啊,frame亂了,只須要更新一下frame便可。以下圖
QQ20160913-11.png-113.2kB
QQ20160913-12.png-32.3kB
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
這句話,以及把< document >中的toolsVersion和< plugIn >中的version改爲你正常的xib文件中的值
19.MJRefresh出現崩潰現象
解決辦法:類庫增長判斷
1
2
3
|
if
(range.location !=
NSNotFound
) {
language = [language substringToIndex:range.location];
}
|
(本條更新於:2016-09-21) 不少人反映自定義相機出現了問題,cameraViewTransform不能用了,其實網上關於這個的資料不是不少,在這裏提供參考辦法以下:
經過監聽AVCaptureSessionDidStartRunningNotification來解決
//#import <AVFoundation/AVFoundation.h>
//監聽
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cameraNotification:) name:AVCaptureSessionDidStartRunningNotification object:nil];
//監聽方法
- (void)cameraNotification:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
// 這裏實現
imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(50, 50);
});
}
看來UIImagePickerController視乎不在適用於iOS 10了。因此說能夠選擇AVFoundation來解決這個問題。 下面是參考學習: UIImagePickerController’s cameraViewTransform
iOS開發時,將Xcode升級到8後,工程運行後出現了不少的報錯警告,以下圖所示,幾乎每一個文件都有「xx」is missing from working copy的警告。某某文件 is missing from working copy字面意思來看是相似使用SVN時出現的刪除某個文件後,此文件仍出如今SVN緩存的問題。可是奇怪的是這個工程我暫時尚未使用SVN,因此我的推斷緣由多是文件路徑緩存的問題。(有哪位同仁知道具體緣由請麻煩告知)
問題具體緣由:
同問題描述中所述。
問題解決:
1.打開Mac終端;
2.cd 到出問題的工程文件夾下 (to 新手朋友,就是在終端中輸入 cd 而後 輸入空格,再把出問題的那個文件拖拽到終端的窗口內,而後點擊回車。這其實就是一種獲取文件路徑的快速方法)
3.輸入 find . -type d -name .svn | xargs rm -rf (此命令的意思爲刪除置頂文件下的全部SVN相關)
4.從新打開Xcode運行,成功,不在報錯「xx」is missing from working copy。
注意⚠️:此處應用的方法爲解決svn緩存的方法,若是是由於SVN緩存問題出現的個別某個文件「xx」is missing from working copy報錯,請在第3步中輸入 svn rm --force 丟失文件的名稱,而不是刪除全部svn相關。
問題相關其餘問法(爲方便各類搜索問題習慣的朋友快速找到此解決方法):
Xcode8升級後報錯is missing from working copy;
iOS 報錯is missing from working copy;
升級Xcode8後不少警告報錯;
iOS不少警告報錯is missing from working copy;
某某文件 is missing from working copy;
參考資料及鳴謝:
http://blog.csdn.net/sinat_29789455/article/details/52640913
http://blog.csdn.net/hdfqq188816190/article/details/52594761
等等。