坑一
- UITextField 的私有屬性 _placeholderLabel 被禁止訪問了
[self.textField setValue:self.placeholderColor forKeyPath:@"_placeholderLabel.textColor"];
居然崩潰了,錯(cuò)誤信息如下
'Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug'
解決方案:
UITextField有個(gè)attributedPlaceholder的屬性灭翔,我們可以自定義這個(gè)富文本來達(dá)到我們需要的結(jié)果。
NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName : self.placeholderColor}];
_textField.attributedPlaceholder = placeholderString;
iOS 13 通過 KVC 方式修改私有屬性,有 Crash 風(fēng)險(xiǎn),謹(jǐn)慎使用!并不是所有KVC都會(huì)Crash岖赋,要嘗試!
坑二
控制器的 modalPresentationStyle 默認(rèn)值變了
查閱了下 UIModalPresentationStyle枚舉定義瓮孙,赫然發(fā)現(xiàn)iOS 13新加了一個(gè)枚舉值:
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,
};
解決方案
如果你完全接受蘋果的這個(gè)默認(rèn)效果唐断,那就不需要去修改任何代碼汁汗。
如果,你原來就比較細(xì)心栗涂,已經(jīng)設(shè)置了modalPresentationStyle的值,那你也不會(huì)有這個(gè)影響祈争。
對(duì)于想要找回原來默認(rèn)交互的同學(xué)斤程,直接設(shè)置如下即可:
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
坑三
IOS13更改了[self presentViewController: animated: completion:] 更改了 不是全屏并且下滑動(dòng)會(huì)崩潰
解決方案
self.modalPresentationStyle = UIModalPresentationFullScreen; //設(shè)置模式為全屏 如果滑動(dòng)還有崩潰 設(shè)置animated為NO
坑四
MPMoviePlayerController 在iOS 13已經(jīng)不能用了
'MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.'
解決方案:
既然不能再用了,那只能換掉了菩混。替代方案就是AVKit里面的那套播放器忿墅。
坑五
UITextField設(shè)置leftView 會(huì)出現(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:點(diǎn)我下載
坑八
即將廢棄的 LaunchImage
從 iOS 8 的時(shí)候邢疙,蘋果就引入了 LaunchScreen棍弄,我們可以設(shè)置 LaunchScreen來作為啟動(dòng)頁。當(dāng)然疟游,現(xiàn)在你還可以使用LaunchImage來設(shè)置啟動(dòng)圖呼畸。不過使用LaunchImage的話,要求我們必須提供各種屏幕尺寸的啟動(dòng)圖颁虐,來適配各種設(shè)備蛮原,隨著蘋果設(shè)備尺寸越來越多,這種方式顯然不夠 Flexible另绩。而使用 LaunchScreen的話儒陨,情況會(huì)變的很簡單, LaunchScreen是支持AutoLayout+SizeClass的笋籽,所以適配各種屏幕都不在話下蹦漠。
注意啦?,從2020年4月開始干签,所有使? iOS13 SDK的 App將必須提供 LaunchScreen津辩,LaunchImage即將退出歷史舞臺(tái)。
坑九
KVC獲取狀態(tài)欄(_statusBar)會(huì)導(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會(huì)崩潰
解決方案
extension UISearchBar {
public func getSearchTextField() -> UITextField{
if #available(iOS 13.0, *) {
return self.searchTextField
}else {
return value(forKey: "_searchField") as! UITextField
}
}
}
坑十一
我項(xiàng)目運(yùn)行的時(shí)候 崩潰了 ,但是我項(xiàng)目里面并沒有_LSDefaults,報(bào)錯(cuò)如下:
[_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)其實(shí)是因?yàn)槲业腢MCCommon 這個(gè)太久了 pod update UMCCommon
坑十二
IOS13 使用AOP切面編程會(huì)報(bào) TUICandidateView collectionView:didSelectItemAtIndexPath: unrecognized selector sent to instance 0x2802a4c60
發(fā)現(xiàn)我的項(xiàng)目中根本就沒有 TUICandidateView 這個(gè)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這個(gè)是系統(tǒng)的
目前暫時(shí)沒發(fā)現(xiàn)好的解決方案
if([NSStringFromClass([delegate class]) isEqualToString:@"TUICandidateGrid"]){
return;
}
坑十三
IOS13使用暗黑模式容劳,UIView喘沿,UITableview,UITextfile 默認(rèn)背景色會(huì)變成暗黑色
解決方案: info.plist 加入
<key>UIUserInterfaceStyle</key>
<string>UIUserInterfaceStyleLight</string>
注意點(diǎn):
- xcode10 沒有這個(gè)屬性竭贩,如果是xcode10打包加入這個(gè)字段提交AppStore 會(huì)報(bào)錯(cuò)蚜印,xcode10打包的話 不會(huì)受到暗黑模式影響
- xcode11打包可以加上這個(gè)字段