一, iOS 13 vc present viewcontrolller 時(shí)默認(rèn)人成了 automotic 之前我們直接present 里面 modalPresentationStyle是默認(rèn) fullscreen 的 所以現(xiàn)在要適配就不能直接present了

設(shè)置vc.modalPresentationStyle = UIModalPresentationFullScreen ;
這樣的就好了,至于一些三方的問題,你直接升級(jí)就好了。沒有升級(jí)的看能不看能不能想辦法修改下。
二, iOS不允許valueForKey、setValue: forKey獲取和設(shè)置私有屬性,如果有使用會(huì)直接導(dǎo)致崩潰 需要使用其它方式修改
[textField setValue:[UIColor red] forKeyPath:@"_placeholderLabel.textColor"];
//替換為
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"輸入"attributes:@{NSForegroundColorAttributeName: [UIColor red]}];
三, MPMoviePlayerController 在iOS 13已經(jīng)不能用了
在使用到MPMoviePlayerController的地方,直接拋了異常:
'MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.'
替代方案就是AVPlayerViewController in AVKit.'
四, 即將廢棄的 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)
五,4. iOS 13 DeviceToken有變化??
這個(gè)很重要?? 可能大多數(shù)使用第三方推送的童鞋都不會(huì)注意到這個(gè)問題,一般現(xiàn)在的第三方推送都是將DeviceToken原始數(shù)據(jù)丟進(jìn)去,具體的解析都是第三方內(nèi)部處理,所以,這些第三方解析DeviceToken的方式正確的話,那就毫無問題。如果你們是通過這種方式來獲取DeviceToken,那你需要注意了。(這個(gè)坑也是多年前埋下的,很多文章介紹的也是下面這個(gè)方法,不規(guī)范的做法遲早要還的??),如下:
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)變了。
{length = 32, bytes = 0x778a7995 29f32fb6 74ba8167 b6bddb4e ... b4d6b95f 65ac4587 }
可以看到,跟原來我們認(rèn)識(shí)的那個(gè)已經(jīng)完全不一樣了。其實(shí),造成這樣的問題,主要還是沒有使用正確的方式來操作,下面是解決辦法:
NSMutableString *deviceTokenString = [NSMutableString string];
const char *bytes = deviceToken.bytes;
NSInteger count = deviceToken.length;
for (int i = 0; i < count; i++) {
[deviceTokenString appendFormat:@"%02x", bytes[i]&0x000000FF];
}
或者你也可以使用極光提供的方法(2019年7月24日更新)
- (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);
}
六,暗黑模式
iOS13 之前 UIColor只能表示一種顏色,而從 iOS13 開始UIColor是一個(gè)動(dòng)態(tài)的顏色,在Light Mode和Dark Mode可以分別設(shè)置不同的顏色。
uicolor 實(shí)例時(shí)多了兩個(gè)實(shí)例方法 ,
照下面操作就好
UIColor *dyColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trainCollection) {
if ([trainCollection userInterfaceStyle] == UIUserInterfaceStyleLight) {
return [UIColor redColor];
}
else {
return [UIColor greenColor];
}
}];
[self.bgView setBackgroundColor:dyColor];
a,監(jiān)聽模式切換
有時(shí)我們需要監(jiān)聽系統(tǒng)模式的變化,并作出響應(yīng)
那么我們就需要在需要監(jiān)聽的viewController中,重寫下列函數(shù)
/ 注意:參數(shù)為變化前的traitCollection
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection;
// 判斷兩個(gè)UITraitCollection對(duì)象是否不同
- (BOOL)hasDifferentColorAppearanceComparedToTraitCollection:(UITraitCollection *)traitCollection;
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
// trait發(fā)生了改變
if ([self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
// 執(zhí)行操作
}
}
還有其他操作請(qǐng)看: http://www.itdecent.cn/p/0da3b107f06c