ChenYilong / ChenYilong/iOS13AdaptationTips

新系统 KVC crash 风险

Open
#12 22 comments 0 reactions 0 assignees View on GitHub
note
Dominant language
No language data
Stars
170
Forks
5
PR merge metrics
No merged PRs in 30d

Description

## KVC 修改_placeholderLabel Crash

版本 | Crash情况
:-------------:|:-------------:
App Store版本| 旧版本不会Crash
使用Xcode11编译上传版本| 会crash
iOS13 | 与系统无关,只与Xcode版本有关

## UITextField

iOS 13(beta版本) 上 UITextField 的 _placeholder 拿不到了,KVC 还是有风险:

```Objective-C
[textField setValue:[UIColor xxx] forKeyPath:@"_placeholderLabel.textColor"];
```

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

App Store 上的旧版本,不会因为kvc 闪退。使用Xcode11编译上传版本才会Crash。

经 SAGESSE-iOS-深圳 使用dis命令分析,为系统检测了该内部字段,非误伤。

```Objective-C
dis -n "-[UITextField valueForKey:]"
```

![](http://ww4.sinaimg.cn/large/006tNc79ly1g3rfjm1ncfj31am04q75z.jpg)
![](http://ww1.sinaimg.cn/large/006tNc79ly1g3rfj6bggzj311j0u0h2w.jpg)

## UISearchBar

```Objective-C
[self setValue:@"xxx " forKey:@"_cancelButtonText"];
```

iOS 13 的 seachbar 添加了一个 `- (void)set_cancelButtonText:(NSString *)text` 方法,这个方法专门用来命中 kvc。一旦命中 就crash

![](http://ww3.sinaimg.cn/large/006tNc79ly1g3wcvrklocj314w0ssdqq.jpg)

## UIScreen.setBrightness crash in global thread #25

Reference: https://github.com/ChenYilong/iOS13AdaptationTips/issues/25#issue-480076177

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.