ios开发 关于iOS13开发者需要注意的问题

1.KVC访问私有属性的崩溃问题

在Xcode11上使用- (void)setValue:(nullable id)value forKeyPath:(NSString *)keyPath方法访问私有属性,编译时会崩溃,例

[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];///崩溃
[textField setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];///崩溃
不过使用- (void)setValue:(nullable id)value forKey:(NSString *)key方法正常,例如:
[self setValue:baseTabBar forKey:@"tabBar"]; //正常

2.即将废弃的LaunchImage

随着苹果设备的型号日益增多,利用LaunchImage来设置启动图显然显得不够明智。
替代方式:使用LaunchScreen来设置启动图。LaunchScreen是iOS8引入的,支持AutoLayout+SizeClass,所以用起来十分方便。据消息,明年4月份后,所有app必须提供LaunchScreen了,尽早替换吧。

3.完全废弃的UIWebView

随着iOS13的到来,UIWebView的使用范围定格在了iOS12。很早时间之前UIWebView就因存在内存泄漏问题被苹果建议用WKWebView来替代。此次更是完全被废弃。现在上传AppStore的应用如果存在UIWebView,苹果会给你发邮件告诉你,UIWebView的API已经废弃了。So,赶紧替换。

4.presentViewController的问题

iOS 13 的 presentViewController 默认有视差效果,模态出来的界面现在默认都下滑返回。 一些页面必须要点确认才能消失的,需要适配。如果项目中页面高度全部是屏幕尺寸,那么多出来的导航高度会出现问题。所以手动设置一下Style吧

self.modalPresentationStyle = UIModalPresentationFullScreen;

5.暗黑模式的适配

随着iOS13的到来,有了暗黑模式,需要我们开发者花更多精力去适配,尤其是那些重量级项目,很费时间。这里先不谈适配问题,以后再谈。如果不适配的话需要你全局关闭暗黑模式。
方法:配置plist文件: 在Info.plist 文件中,添加UIUserInterfaceStyle key 名字为 User Interface Style 值为String,将UIUserInterfaceStyle key 的值设置为 Light。

6.增加蓝牙权限申请

iOS13以前,使用蓝牙时可以直接用,不会出现权限提示,iOS13后,再使用就会提示了。 在info.plist里增加

<key>NSBluetoothAlwaysUsageDescription</key> 
<string>我们需要使用您的蓝牙</string>`

7.DeviceToken 获取

DeviceToken 获取到的格式发生变化

#include <arpa/inet.h>
- (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);
}

8.MPMoviePlayerController 彻底弃用

MPMoviePlayerController 在 iOS 9 开始被弃用,如果在 iOS 13 中继续使用的话会直接抛出异常:


9.UISearchDisplayController彻底弃用

在 iOS 8 之前,我们在 UITableView 上添加搜索框需要使用 UISearchBar + UISearchDisplayController 的组合方式。

在 iOS 8 之后,苹果就已经推出了 UISearchController 来代替这个组合方式。在 iOS 13 中,如果还继续使用 UISearchDisplayController会直接导致崩溃,崩溃信息如下

Terminating app due to uncaught exception 'NSGenericException', reason: 'UISearchDisplayController is no longer supported when linking against this version of iOS. Please migrate your application to UISearchController.'
解决方法:使用UISearchController代替

10.[UIApplication sharedApplication].keyWindow API将被弃用


@property(nullable, nonatomic,readonly) UIWindow *keyWindow API_DEPRECATED("Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes", ios(2.0, 13.0));
修改使用下方代码获取
[[[UIApplication sharedApplication] windows] objectAtIndex:0]
原文出处https://www.jianshu.com/p/4409ccf98070
posted @ 2020-03-20 17:38  代佳宏  阅读(769)  评论(0编辑  收藏  举报