坑一
- UITextField 的私有屬性 _placeholderLabel 被禁止訪問了
[self.textField setValue:self.placeholderColor forKeyPath:@"_placeholderLabel.textColor"];
居然崩潰了误澳,錯誤信息如下
'Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug'
解決方案:
UITextField有個attributedPlaceholder的屬性从媚,我們可以自定義這個富文本來達(dá)到我們需要的結(jié)果。
NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName : self.placeholderColor}];
_textField.attributedPlaceholder = placeholderString;
iOS 13 通過 KVC 方式修改私有屬性材蹬,有 Crash 風(fēng)險,謹(jǐn)慎使用无埃!并不是所有KVC都會Crash鹤树,要嘗試!
坑二
控制器的 modalPresentationStyle 默認(rèn)值變了
查閱了下 UIModalPresentationStyle枚舉定義椰拒,赫然發(fā)現(xiàn)iOS 13新加了一個枚舉值:
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
UIModalPresentationFormSheet API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
UIModalPresentationCurrentContext API_AVAILABLE(ios(3.2)),
UIModalPresentationCustom API_AVAILABLE(ios(7.0)),
UIModalPresentationOverFullScreen API_AVAILABLE(ios(8.0)),
UIModalPresentationOverCurrentContext API_AVAILABLE(ios(8.0)),
UIModalPresentationPopover API_AVAILABLE(ios(8.0)) API_UNAVAILABLE(tvos),
UIModalPresentationBlurOverFullScreen API_AVAILABLE(tvos(11.0)) API_UNAVAILABLE(ios) API_UNAVAILABLE(watchos),
UIModalPresentationNone API_AVAILABLE(ios(7.0)) = -1,
UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2,
};
解決方案
如果你完全接受蘋果的這個默認(rèn)效果晶渠,那就不需要去修改任何代碼。
如果燃观,你原來就比較細(xì)心褒脯,已經(jīng)設(shè)置了modalPresentationStyle的值,那你也不會有這個影響缆毁。
對于想要找回原來默認(rèn)交互的同學(xué)番川,直接設(shè)置如下即可:
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
坑三
IOS13更改了[self presentViewController: animated: completion:] 更改了 不是全屏并且下滑動會崩潰
解決方案
self.modalPresentationStyle = UIModalPresentationFullScreen; //設(shè)置模式為全屏 如果滑動還有崩潰 設(shè)置animated為NO
坑四
MPMoviePlayerController 在iOS 13已經(jīng)不能用了
'MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.'
解決方案:
既然不能再用了,那只能換掉了脊框。替代方案就是AVKit里面的那套播放器颁督。
坑五
UITextField設(shè)置leftView 會出現(xiàn)圖片無法按照意圖顯示的問題。
// Confuse in beta4 iOS13
UIImageView *iconView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
//search_icon 15*15
iconView.image = [UIImage imageNamed:@"icon"];
iconView.contentMode = UIViewContentModeCenter;
UITextField *file = [[UITextField alloc] init];
file.leftView = iconView;
解決方案
自定義UITextfile 前面增加間距
- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
CGRect iconRect = [super leftViewRectForBounds:bounds];
iconRect.origin.x += 8; //像右邊偏15
return iconRect;
}
//UITextField 文字與輸入框的距離
- (CGRect)textRectForBounds:(CGRect)bounds{
if (_margin>0) {
return CGRectInset(bounds, _margin, 0);
}else{
return CGRectInset(bounds, 34, 0);
}
}
//控制文本的位置
- (CGRect)editingRectForBounds:(CGRect)bounds{
if (_margin>0) {
return CGRectInset(bounds, _margin, 0);
}else{
return CGRectInset(bounds, 34, 0);
}
}
然后在設(shè)置
坑六
iOS 13 DeviceToken有變化
NSString *dt = [deviceToken description];
dt = [dt stringByReplacingOccurrencesOfString: @"<" withString: @""];
dt = [dt stringByReplacingOccurrencesOfString: @">" withString: @""];
dt = [dt stringByReplacingOccurrencesOfString: @" " withString: @""];
這段代碼運(yùn)行在 iOS 13 上已經(jīng)無法獲取到準(zhǔn)確的DeviceToken字符串了浇雹,iOS 13 通過[deviceToken description]獲取到的內(nèi)容已經(jīng)變了沉御。
解決方案
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
if (![deviceToken isKindOfClass:[NSData class]]) return;
const unsigned *tokenBytes = [deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSLog(@"deviceToken:%@",hexToken);
}
坑七
Sign in with Apple -提供第三方登錄的注意啦
如果你的應(yīng)用使用了第三方登錄,那么你可能也需要加下 「Sign in with Apple」
Sign In with Apple will be available for beta testing this summer. It will be required as an option for users in apps that support third-party sign-in when it is commercially available later this year.
解決方案
附上官方Demo:點我下載
坑八
即將廢棄的 LaunchImage
從 iOS 8 的時候昭灵,蘋果就引入了 LaunchScreen吠裆,我們可以設(shè)置 LaunchScreen來作為啟動頁。當(dāng)然烂完,現(xiàn)在你還可以使用LaunchImage來設(shè)置啟動圖试疙。不過使用LaunchImage的話,要求我們必須提供各種屏幕尺寸的啟動圖窜护,來適配各種設(shè)備效斑,隨著蘋果設(shè)備尺寸越來越多,這種方式顯然不夠 Flexible柱徙。而使用 LaunchScreen的話缓屠,情況會變的很簡單, LaunchScreen是支持AutoLayout+SizeClass的护侮,所以適配各種屏幕都不在話下敌完。
注意啦?,從2020年4月開始羊初,所有使? iOS13 SDK的 App將必須提供 LaunchScreen滨溉,LaunchImage即將退出歷史舞臺什湘。
坑九
KVC獲取狀態(tài)欄(_statusBar)會導(dǎo)致崩潰
UIApplication *app = [UIApplication sharedApplication]; if ([[app valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
NSArray *views = [[[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
解決方案
使用第三方 Reachability
+ (NSString *)getNetworkType
{
NSString *networkType = @"Wi-Fi";
WSXReachability *reachability = [WSXReachability reachabilityForInternetConnection];
TTNetworkStatus internetStatus = [reachability currentReachabilityStatus];
switch (internetStatus) {
case NotTTReachable:// 沒有網(wǎng)絡(luò)
{
networkType = @"";
}
break;
case TTReachableViaWiFi:// Wifi
{
networkType = @"Wi-Fi";
}
break;
case TTReachableViaWWAN:// 手機(jī)自帶網(wǎng)絡(luò)
{
// 獲取手機(jī)網(wǎng)絡(luò)類型
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
NSString *currentStatus = info.currentRadioAccessTechnology;
if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyGPRS"]) {
networkType = @"GPRS";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyEdge"]) {
networkType = @"2.75G EDGE";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyWCDMA"]){
networkType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyHSDPA"]){
networkType = @"3.5G HSDPA";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyHSUPA"]){
networkType = @"3.5G HSUPA";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMA1x"]){
networkType = @"2G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORev0"]){
networkType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevA"]){
networkType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevB"]){
networkType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyeHRPD"]){
networkType = @"HRPD";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyLTE"]){
networkType = @"4G";
}
}
break;
default:
break;
}
return networkType;
}
坑十(謝謝網(wǎng)友提供)
KVC獲取searchbar的_searchField會崩潰
解決方案
extension UISearchBar {
public func getSearchTextField() -> UITextField{
if #available(iOS 13.0, *) {
return self.searchTextField
}else {
return value(forKey: "_searchField") as! UITextField
}
}
}
坑十一
我項目運(yùn)行的時候 崩潰了 ,但是我項目里面并沒有_LSDefaults,報錯如下:
[_LSDefaults sharedInstance]: unrecognized selector sent to class
解決方案:
@implementation NSObject (Extend)
+ (void)load{
SEL originalSelector = @selector(doesNotRecognizeSelector:);
SEL swizzledSelector = @selector(sw_doesNotRecognizeSelector:);
Method originalMethod = class_getClassMethod(self, originalSelector);
Method swizzledMethod = class_getClassMethod(self, swizzledSelector);
if(class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))){
class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
}else{
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
+ (void)sw_doesNotRecognizeSelector:(SEL)aSelector{
//處理 _LSDefaults 崩潰問題
if([[self description] isEqualToString:@"_LSDefaults"] && (aSelector == @selector(sharedInstance))){
//冷處理...
return;
}
[self sw_doesNotRecognizeSelector:aSelector];
}
網(wǎng)上這樣處理可以
但是我發(fā)現(xiàn)其實是因為我的UMCCommon 這個太久了 pod update UMCCommon
坑十二
IOS13 使用AOP切面編程會報 TUICandidateView collectionView:didSelectItemAtIndexPath: unrecognized selector sent to instance 0x2802a4c60
發(fā)現(xiàn)我的項目中根本就沒有 TUICandidateView 這個View
解決方案
- (void)swiz_setDelegate:(id<UICollectionViewDelegate>)delegate {
[self swiz_setDelegate:delegate];
if([NSStringFromClass([delegate class]) isEqualToString:@"TUICandidateGrid"]){
return;
}
if (delegate && [delegate respondsToSelector:@selector(collectionView:didSelectItemAtIndexPath:)]) {
NSNumber *isHook = objc_getAssociatedObject(delegate, delegateCollectionViewIsHook);
if (isHook == nil || ![isHook boolValue]) {
@try {
NSError *error = nil;
[(NSObject *)delegate aspect_hookSelector:@selector(collectionView:didSelectItemAtIndexPath:) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> aspectInfo) {
TZUserStatistics<AOPLoggerClickProtocol> *aopLoggerEngine=(TZUserStatistics<AOPLoggerClickProtocol>*)[TZStatisticInterceptionManager sharedStatLogger];
if ([aopLoggerEngine respondsToSelector:@selector(alcp_collectionView:didSelectItemAtIndexPath:from:)]) {
[aopLoggerEngine alcp_collectionView:aspectInfo.arguments[0] didSelectItemAtIndexPath:aspectInfo.arguments[1] from:aspectInfo.instance];
}
} error:&error];
objc_setAssociatedObject(delegate, delegateCollectionViewIsHook, @(YES), OBJC_ASSOCIATION_RETAIN);
}
@catch (NSException *exception) {
}
}
}
}
判斷代理當(dāng)前的類是不是 TUICandidateGrid這個是系統(tǒng)的
目前暫時沒發(fā)現(xiàn)好的解決方案
if([NSStringFromClass([delegate class]) isEqualToString:@"TUICandidateGrid"]){
return;
}
坑十三
IOS13使用暗黑模式,UIView晦攒,UITableview闽撤,UITextfile 默認(rèn)背景色會變成暗黑色
解決方案: info.plist 加入
<key>UIUserInterfaceStyle</key>
<string>UIUserInterfaceStyleLight</string>
注意點:
- xcode10 沒有這個屬性,如果是xcode10打包加入這個字段提交AppStore 會報錯脯颜,xcode10打包的話 不會受到暗黑模式影響
- xcode11打包可以加上這個字段
歡迎大家補(bǔ)充