[toc]簡(jiǎn)書(shū)不支持目錄跳轉(zhuǎn)顿乒,好可惡
1.解決工程中輸出無(wú)關(guān)日志
Edit Scheme -> Run -> Arguments, 在Environment Variables里邊添加 OS_ACTIVITY_MODE
disable
遺留問(wèn)題:
還會(huì)出現(xiàn)下面這個(gè)問(wèn)題Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x112b58910) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x112982210).
One of the two will be used. Which one is undefined.
在模擬器中岩榆、發(fā)現(xiàn)One of the two will be used. Which one is undefined.
日志
查找資料發(fā)現(xiàn)原因:objc runtime
對(duì)所用App使用同一個(gè)命名空間(flat namespace),運(yùn)行機(jī)制如下:
首先二進(jìn)制映像被加載普泡,檢查程序依賴關(guān)系
每一個(gè)二進(jìn)制映像被加載的同時(shí),程序的objc classes
在objc runtime
命名空間中注冊(cè)
如果具有相同名稱的類被再次加載厦坛,objc runtime
的行為是不可預(yù)知的桦锄。一種可能的情況是任意一個(gè)程序的該類會(huì)被加載(這應(yīng)該也是默認(rèn)動(dòng)作)
2.注釋快捷鍵?+/失效
重啟電腦,如果還不能使用的話就啟用命令工具(命令運(yùn)行 sudo /usr/libexec/xpccachectl)抠忘,然后重啟電腦
3.對(duì)于插件無(wú)法使用
網(wǎng)上推薦的是將Xcode拷貝一份可以使用插件的Xcode(在應(yīng)用程序中)撩炊,但是這個(gè)Xcode不能打包上傳等,建議不要使用這種方法
三方插件解決方法(fix method):讓你的Xcode8繼續(xù)使用插件
但是看到文章最后的解釋褐桌,我們知道如果用插件的話衰抑,可能安全上會(huì)有問(wèn)題、并且提交審核會(huì)被拒絕荧嵌,所以建議大家還是不要用了呛踊,解決辦法總是有的,比如在Xcode中添加注釋的代碼塊也是很方便的啦撮。
另外:Xcode 推出來(lái)快速文本注釋:Command +Option +/
<#Description#> @param frame
<#frame description#> @return
<#return value description#>
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]){
[self initUiConfig];
}
return self;
}
4.iOS10隱私權(quán)限問(wèn)題
OS10中調(diào)用相機(jī)相冊(cè)等系統(tǒng)功能時(shí)谭网,需要在info.plist文件中添加字段,否則會(huì)出現(xiàn)閃退的情況
<!-- 相冊(cè) -->
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)相冊(cè)</string>
<!-- 相機(jī) -->
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)相機(jī)</string>
<!-- 麥克風(fēng) -->
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)麥克風(fēng)</string>
<!-- 位置 -->
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)位置</string>
<!-- 在使用期間訪問(wèn)位置 -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期間訪問(wèn)位置</string>
<!-- 始終訪問(wèn)位置 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始終訪問(wèn)位置</string>
<!-- 日歷 -->
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)日歷</string>
<!-- 提醒事項(xiàng) -->
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)提醒事項(xiàng)</string>
<!-- 運(yùn)動(dòng)與健身 -->
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)運(yùn)動(dòng)與健身</string>
<!-- 健康更新 -->
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)健康更新 </string>
<!-- 健康分享 -->
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)健康分享</string>
<!-- 藍(lán)牙 -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)藍(lán)牙</string>
<!-- 媒體資料庫(kù) -->
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能訪問(wèn)媒體資料庫(kù)</string>
5.label中的文字顯示變化
Xcode8與Xcode7.3的文字寬度變化(英文字母沒(méi)有問(wèn)題赃春,只有漢字有問(wèn)題)
當(dāng)我們手機(jī)系統(tǒng)字體改變了之后愉择,那我們App的label也會(huì)跟著一起變化,這需要我們寫(xiě)很多代碼來(lái)進(jìn)一步處理才能實(shí)現(xiàn),但是iOS 10 提供了這樣的屬性adjustsFontForContentSizeCategory
來(lái)設(shè)置锥涕,
UILabel *myLabel = [UILabel new];
// UIFont 的preferredFontForTextStyle:意思是指定一個(gè)樣式衷戈,并讓字體大小符合用戶設(shè)定的字體大小
myLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
myLabel.adjustsFontForContentSizeCategory = YES; // 是否更新字體的變化
6.Notification(通知)
- 所有相關(guān)通知被統(tǒng)一到了UserNotifications.framework框架中
- 增加了撤銷、更新层坠、中途還可以修改通知的內(nèi)容
- 通知不再是簡(jiǎn)單的文本殖妇,現(xiàn)在還可以是圖片、視頻,自定義通知的展示等等
- iOS10相對(duì)之前的通知來(lái)說(shuō)更好用更易于管理,并且進(jìn)行了大規(guī)模優(yōu)化
- iOS10之后昔瞧,本地與遠(yuǎn)程通知集成在一個(gè)方法中
而且一般來(lái)說(shuō),也會(huì)開(kāi)啟Remote notifications 的 Background Modes
7.ATS的問(wèn)題
iOS 9中默認(rèn)非HTTS的網(wǎng)絡(luò)是被禁止的,當(dāng)然我們也可以把NSAllowsArbitraryLoads
設(shè)置為YES禁用ATS。不過(guò)iOS 10從2017年1月1日起蘋(píng)果不允許我們通過(guò)這個(gè)方法跳過(guò)ATS,也就是說(shuō)強(qiáng)制我們用HTTPS舰绘,如果不這樣的話提交App可能會(huì)被拒絕。但是我們可以通過(guò)NSExceptionDomains
來(lái)針對(duì)特定的域名開(kāi)放HTTP可以容易通過(guò)審核延赌。
NSExceptionDomains
方式 設(shè)置域除盏。可以簡(jiǎn)單理解成挫以,把不支持https協(xié)議的接口設(shè)置成http的接口者蠕。
具體方法:
- 在項(xiàng)目的info.plist中添加一個(gè)Key:App Transport Security Settings,類型為字典類型掐松。
- 然后給它添加一個(gè)Exception Domains踱侣,類型為字典類型;
- 把需要的支持的域添加給Exception Domains大磺。其中域作為Key抡句,類型為字典類型。
- 每個(gè)域下面需要設(shè)置3個(gè)屬性:
NSIncludesSubdomains
杠愧、NSExceptionRequiresForwardSecrecy
待榔、NSExceptionAllowsInsecureHTTPLoads
。
在iOS9以后的系統(tǒng)中如果使用到網(wǎng)絡(luò)圖片流济,也要注意網(wǎng)絡(luò)圖片是否是HTTP锐锣,如果是,也要把圖片的域設(shè)置绳瘟!
8.iOS10中UICollectionView性能優(yōu)化
具體查看WWDC2016 Session筆記 - iOS 10 UICollectionView新特性
9.iOS10 UIColor新增方法
iOS10蘋(píng)果建議我們使用DisplayP3雕憔,因?yàn)樗阅芨茫矢S富糖声。
+ (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);
10.iOS10 UIScrollView新增refreshControl
就是說(shuō)以后只要是繼承UIScrollView就支持刷新功能
@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 500)];
scrollView.backgroundColor = [UIColor redColor];
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, 1000);
[self.view addSubview:scrollView];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]];
[scrollView addSubview:imageView];
// 添加下拉刷新控件
UIRefreshControl *ref = [[UIRefreshControl alloc] init];
// 監(jiān)聽(tīng)刷新方法
[ref addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
scrollView.refreshControl = ref;
self.view.backgroundColor = [UIColor redColor];
}
- (void)refresh:(UIRefreshControl *)ref {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(22 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 結(jié)束刷新
[ref endRefreshing];
});
}
11.iOS10判斷系統(tǒng)版本正確姿勢(shì)
NSLog(@"%zd\n%f\n%@",
[[[[UIDevice currentDevice] systemVersion] substringToIndex:1] integerValue],
//1
[[UIDevice currentDevice] systemVersion].floatValue,
//10.100000
[[UIDevice currentDevice] systemVersion]);
//10.1
所以建議大家用[[UIDevice currentDevice] systemVersion]這個(gè)方法斤彼!
Swift判斷如下:
if #available(iOS 10.0, *) {
// iOS 10.0
print("iOS 10.0");
}
else { }
12.UIStatusBar的問(wèn)題
在iOS10中分瘦,如果還是用以前設(shè)置UIStatusBar類型或者控制隱藏還是顯示的方法,會(huì)報(bào)警告琉苇,方法過(guò)期嘲玫,如下圖:
要想修改UIStatusBar的樣式或者狀態(tài)使用下圖中所示的屬性或方法:
@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
13.UITextField新增字段
在iOS10中,UITextField新增了textContentType
字段并扇,是UITextContentType
類型趁冈,它是一個(gè)枚舉,作用是可以指定輸入框的類型拜马,以便系統(tǒng)可以分析出用戶的語(yǔ)義,是電話類型就建議一些電話沐绒,是地址類型就建議一些地址俩莽。可以在#import<UIkit/UITextInputTraits.h>
文件中乔遮,查看textContentType
字段扮超,有以下可以選擇的類型:
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);
14.藍(lán)牙相關(guān)
CBCentralManagerState廢棄,使用CBManagerState替代
CBCentralManager直接繼承于CBManager蹋肮,里面直接聲明的屬性:
@property(nonatomic, assign, readonly) CBManagerState state;
15.Application openURL的方法被遺棄
使用其替換方法
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion NS_AVAILABLE_IOS(10_0) NS_EXTENSION_UNAVAILABLE_IOS("");