1.啟動app存在的一些問題
在APP啟動時,若存在一些耗時操作,則會出現閃一下黑屏。可以檢查:1.launchImage是否正確 2.讀寫plist文件會很耗時
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}
使用widget啟動app時,launchOptions會存在數據,對于保存系統推送的key:kSystemNotificationUserDefalutsKey 會導致app啟動奔潰,此時需要將launchOptions = nil;iOS 程序啟動時總會調用application:didFinishLaunchingWithOptions:,其中第二個參數launchOptions為NSDictionary類型的對象,里面存儲有此程序啟動的原因。launchOptions中的可能鍵值見UIApplication Class Reference的Launch Options Keys節 。
2.1、若用戶直接啟動,lauchOptions內無數據;
2.2、若由其他應用程序通過openURL:啟動,則UIApplicationLaunchOptionsURLKey對應的對象為啟動URL(NSURL),UIApplicationLaunchOptionsSourceApplicationKey對應啟動的源應用程序的bundle ID (NSString);
2.3、若由本地通知啟動,則UIApplicationLaunchOptionsLocalNotificationKey對應的是為啟動應用程序的的本地通知對象(UILocalNotification);
2.4、若由遠程通知啟動,則UIApplicationLaunchOptionsRemoteNotificationKey對應的是啟動應用程序的的遠程通知信息userInfo(NSDictionary);
2.5、其他key有UIApplicationLaunchOptionsAnnotationKey,UIApplicationLaunchOptionsLocationKey, UIApplicationLaunchOptionsNewsstandDownloadsKey。
2.tableView嵌套問題
- 當cell中嵌套tableView時,若cell frame 小于子tableView的frmae,則會造成tableView點擊區域無法響應
- 多個多種view嵌套時,會遇到手勢沖突問題,這時需要重寫手勢代理:UIGestureRecognizerDelegate 來識別需要響應手勢的view
- (Bool)GestureRecognizer:(UIGestureRecognizer *)gestureRecoginzer shouldReceiveTouch:(UITouch *)touch {
if([touch.view isKindOfClass:[UILabel class]] ){
return YES;
} else {
return NO;
}
}
3.適配iOS 11遇到的問題及解決辦法
- UIScrollView及其子類(UITableView)的適配
iOS 11之前,在VC里設置:
automaticallyAdjustsScrollViewInsets = YES;
scrollView會自動設置相應的內邊距,存在tableHeaderView時是不會和導航欄存在適配問題。
iOS 11 之后,系統默認開啟self-sizing,TableHeaderView的背景圖下移20像素到導航欄下方,apple文檔解析:
Self-Sizing by Default
NEW
Link on iOS 11, all estimated heights default to UITableViewAutomaticDimension Headers, footers, and cells use self-sizing by default
iOS only—behavior is not changed on tvOS
Ensure all views have sufficient internal constraints
Return fixed sizes from delegate methods
此時需要設置:
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0 ;
tableView.estimatedSectionFooterHeight = 0;
if (systemVersion >= 11) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
4.獲取相冊權限
- iOS11下,蘋果對相冊的權限key做了調整,原來的 NSPhotoLibraryUsageDescription ,在iOS11之后,改成了NSPhotoLibraryAddUsageDescription
<key>NSPhotoLibraryAddUsageDescription</key> //iOS 11
<string>App需要您的同意,才能訪問相冊</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能訪問相冊</string> //<iOS10
5.導航欄
iOS11對導航欄做了比較大的更改:
- 表現一,以前使用如下方法設置導航欄UIBarButtonItem。到了iOS11上。UIBarButtonItem會被Tint Color渲染,原顏色被沖掉。
解決方法 : 設置UIImage的渲染模式——UIImage.renderingMode為 UIImageRenderingModeAlwaysOriginal——始終繪制圖片原始狀態,不使用Tint Color。
//設置導航欄返回按鈕,iOS11上顏色會被沖掉
- (void)setNavigationBarBackButtonItem:(NSString *)image {
UIImage *backImage = [UIImage imageNamed:image];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(popViewControllerAnimated)];
backItem.tintColor = [UIColor colorWithPatternImage:backImage];
backItem.title = @"";
self.navigationItem.leftBarButtonItem = backItem;
}
用 initWithCustomView的方法,不會受上面影響。
_leftBtn = [[UIButton alloc] ];
[_leftBtn setImage:image forState:UIControlStateNormal];
_leftBtn.backgroundColor = [UIColor cyanColor];
_leftBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
_leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[_leftBtn addTarget:self action:@selector(leftBtnClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_leftBtn];
self.navigationItem.leftBarButtonItem = leftBarButtonItem;
- 表現二,iOS11上initWithCustomView的方法給導航欄設置按鈕,如果圖片未加@3x后綴,圖片會顯示超大,超出了原始尺寸。解決方法就是給圖片加上@3x。
6、iOS 10無法連接網絡問題
有些時候在iOS10系統下,App無論如何都無法連接互聯網,這時候是因為我們的App沒有向用戶發出是否允許網絡請求,我們可以按照以下操作讓App彈出是否允許網絡請求:
設置-無線局域網或蜂窩移動網絡-使用無線局域網與蜂窩移動的移動
更改任意App的權限再恢復原先選項,操作完成后再打開相關問題應用,會彈出選擇網絡,確認即可
7、某些iOS設備在設置日歷提醒時,添加失敗
測試的同事開始給我反饋是iOS10.3.2的問題,后來經過反復排查,確認不是代碼問題,是設備本身設置提醒需要在icloud開啟(或曾經開啟過)
[圖片上傳中...(開啟日歷提醒)]
It works now!