標籤:
1 Xib檔案的注意事項
使用Xcode8開啟xib檔案後,會出現的提示。
大家選擇Choose Device即可。
之後大家會發現布局啊,frame亂了,只需要更新一下frame即可。如
注意:如果按上面的步驟操作後,在用Xcode7開啟Xib會報一下錯誤,
解決辦法:需要刪除Xib裡面
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
這句話,以及把< document >中的toolsVersion和< plugIn >中的version改成你正常的xib檔案中的值.
2 推送
如的部分,不要忘記開啟。所有的推送平台,不管是極光還是什麼的,要想收到推送,這個是必須開啟的。
推送的代理<UNUserNotificationCenterDelegate>iOS10收到通知不再是在[application: didReceiveRemoteNotification:]方法去處理, iOS10推出新的代理方法,接收和處理各類通知(本地或者遠程)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { //應用在前台收到通知 NSLog(@"========%@", notification);}- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { //點擊通知進入應用 NSLog(@"response:%@", response);}
3 屏蔽Xcode 8雜亂無章的log
更新Xcode8之後,建立立工程,都會列印一堆莫名其妙看不懂的Log.
如這些
subsystem: 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,
屏蔽的方法如下:
Xcode8裡邊 Edit Scheme-> Run -> Arguments, 在Environment Variables裡邊添加
OS_ACTIVITY_MODE = Disable
如果寫了之後還是列印log,請重新勾選對勾,就可以解決了
考慮到添加上述內容在Xcode8後,真機調試可能出現異常,大家可以自訂一個宏定義,來做日誌輸出。
#ifdef DEBUG#define DDLOG(...) printf(" %s\n",[[NSString stringWithFormat:__VA_ARGS__]UTF8String]);#define DDLOG_CURRENT_METHOD NSLog(@"%@-%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd))#else#define DDLOG(...) ;#define DDLOG_CURRENT_METHOD ;#endif
4 許可權以及相關設定
iOS10調用相簿會Crash下面資訊
This app has crashed because it attempted 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.
大體意思就是這個App缺少一個擷取私人(敏感)資料的許可權描述,需要我們在info.plist檔案中必須含有一個名字叫做NSPhotoLibraryUsageDescription的值來解釋為什麼應用需要使用這個資料,沒錯,擷取相簿資源的索引值就是NSPhotoLibraryUsageDescription
去plist檔案中添加了下面的索引值:
這個時候再點擊擷取圖片資源,就彈出了一個擷取許可權的問候,不會發生崩潰了:
除了相簿的許可權,iOS10之後如下的許可權請求也是需要我們填寫請求描述的
Privacy - Microphone Usage Description //麥克風許可權Privacy - Contacts Usage Description //通訊錄許可權Privacy - Camera Usage Description //網路攝影機許可權Privacy - NSSiriUsageDescription //Siri的許可權Privacy - Bluetooth Peripheral Usage Description //藍芽Privacy - Reminders Usage Description //提醒事項Privacy - Motion Usage Description //運動與健康Privacy - Media Libaray Usage Description //媒體資源庫Privacy - Calendars Usage Description //日曆
5 iOS 10開始項目中有的文字顯示不全問題
我用Xcode 8 和Xcode 7.3分別測試了下,如:
建立一個Label然後讓它自適應大小,字型大小都是17最後輸出的寬度是不一樣的,我們再看一下,下面的資料就知道為什麼升級iOS 10 之後App中有的文字顯示不全了:
| Xcode 8列印 |
Xcode 7.3列印 |
| 1個文字寬度:17.5 |
1個文字寬度:17 |
| 2個文字寬度:35 |
2個文字寬度:34 |
| 3個文字寬度:52 |
3個文字寬度:51 |
| 4個文字寬度:69.5 |
4個文字寬度:68 |
| 5個文字寬度:87 |
5個文字寬度:85 |
| 6個文字寬度:104 |
6個文字寬度:102 |
| 7個文字寬度:121.5 |
7個文字寬度:119 |
| 8個文字寬度:139 |
8個文字寬度:136 |
| 9個文字寬度:156 |
9個文字寬度:153 |
| 10個文字寬度:173.5 |
10個文字寬度:170 |
英文字母會不會也有這種問題,我又通過測試,後來發現英文字母沒有問題,只有漢字有問題。
目前可行的解決方案:
//@property(nonatomic) BOOL adjustsFontSizeToFitWidth; // default is NOlabel.adjustsFontSizeToFitWidth = YES;//設定成YES就可以啦
6 xib設定好固定尺寸在代碼中擷取控制項尺寸都變成(0,0,1000,1000)
UIView中要從- (void)updateConstraints或者- (void)drawRect:(CGRect)rect擷取控制項尺寸。
- (void)updateConstraints{ [super updateConstraints];}- (void)drawRect:(CGRect)rect{ [super drawRect:rect];}
UIViewController中要從- (void)viewDidLayoutSubviews擷取控制項尺寸。
- (void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews];}
7 Xcode 8使用Xib awakeFromNib的警告問題
在Xcode 8之前我們使用Xib初始化- (void)awakeFromNib {}都是這麼寫也沒什麼問題,但是在Xcode 8會有如下警告:
如果不喜歡這個警告的話,應該明確的加上[super awakeFromNib];我們來看看官方說明:
You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. You may call the super implementation at any point during your own awakeFromNib method.
參考
http://www.jianshu.com/p/484a909b4772
iOS10和Xcode8適配