您的当前位置:首页正文

iOS 13 适配(持续更新)

来源:华拓网

iOS 13 马上就要来了,各位 iOS 开发的小伙伴们,iOS 13 beta版的适配工作可以做起来了,O(∩_∩)O哈哈~,不多废话,直入主题!

iOS 13 手机系统下载方式,可以用描述文件下载,但是该方法无法降级,建议用爱思助手,可以方便系统升降级;

方法,获取不到当前连接的WiFi信息

可以看出在这三个条件下,CNCopyCurrentNetworkInfo这个方法才可以获取到当前连接WiFi信息;

参考代码:


2.KVC 限制

[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];

调用该方法会导致xcode崩溃,iOS 13上可以正常运行,但是用xcode跑会crash,报错信息:

'Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug'

修改方案:

textField.attributedPlaceholder = [[NSAttributedStringalloc] initWithString:@""attributes:@{NSForegroundColorAttributeName:[UIColor red]}];


3.UISegmentedControl 颜色设置方式改变

iOS 13之前设置 tintColor 的方式,已经没法改变UISegmentedControl的背景色,可通过以下方法改变:

_segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"one", @"two"]];

[_segmentedControl setBackgroundImage:[vUtilityAPP imageWithColor:[UIColor blueColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

[_segmentedControl setBackgroundImage:[vUtilityAPP imageWithColor:[UIColor redColor]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

4.iOS 13中 presentViewController 模态动画,跳转问题修复

iOS 13之前 presentViewController 跳转的 modalPresentationStyle 默认为 UIModalPresentationFullScreen ;

在iOS 13中默认 style 被改为 UIModalPresentationAutomatic,可参考苹果代码注释:

修改方案:

CLBaseWebViewController *webViewController = [[CLBaseWebViewController alloc] initWithURL:url type:type data:data];

UINavigationController *nav = [[UINavigationControlleralloc] initWithRootViewController:webViewController];

nav.modalPresentationStyle = UIModalPresentationFullScreen;

[self.navigationController presentViewController:nav animated:YES completion:nil];

即:将 vc.modalPresentationStyle 的值改为 UIModalPresentationFullScreen ;

5.UITableView的accessoryType为UITableViewCellAccessoryDisclosureIndicator时,显示会有问题;

iOS 13设置该值时会显示:

需要更换为自定义的箭头图片;

6.[deviceToken description] 获取到的格式发生变化

iOS 13正确获取Devicetoken代码:

#include <arpa/inet.h>

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

    if (![deviceToken isKindOfClass:[NSData class]]) return;

    const unsigned *tokenBytes = (const unsigned *)[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);

}

7.App启动过程中,部分View可能无法实时获取到frame

// 只有等执行完 UIViewController 的 viewDidAppear 方法以后,才能获取到正确的值,在viewDidLoad等地方 frame Size 为 0,例如:

[[UIApplication sharedApplication] statusBarFrame];

8.适配深夜模式

Apps on iOS 13 are expected to support dark mode Use system colors and materials Create your own dynamic colors and images Leverage flexible infrastructure

在iOS 13设备上,苹果要求适配深夜模式,适配该模式的时候,本来想自己写一个较详细的,但是已经看到一个小伙伴写的很不错了,就直接拿过来啦,哈哈

9.UISearchBar

UISearchBar主要还是KVC获取系统私有属性,导致的坑,自己这边项目中没用到,但是有很多小伙伴遇到了,就一起记录下: