iOS13AdaptationTips icon indicating copy to clipboard operation
iOS13AdaptationTips copied to clipboard

新系统 KVC crash 风险

Open ChenYilong opened this issue 6 years ago • 22 comments

KVC 修改_placeholderLabel Crash

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

UITextField

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

[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命令分析,为系统检测了该内部字段,非误伤。

dis -n "-[UITextField valueForKey:]"

UISearchBar

[self setValue:@"xxx " forKey:@"_cancelButtonText"];

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

UIScreen.setBrightness crash in global thread #25

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

ChenYilong avatar Jun 06 '19 06:06 ChenYilong

只是不能访问系统的内部属性吧,如果用来访问自己写的类应该还是可以的?

peter2022Begin avatar Jun 24 '19 08:06 peter2022Begin

是的,私有API内部属性有校验,公开API没问题。

ChenYilong avatar Jun 24 '19 09:06 ChenYilong

Xcode-beta3 貌似又恢复可以访问了

确定?我用的不行

huangzhifei avatar Jul 19 '19 08:07 huangzhifei

@property(nullable, nonatomic,copy) NSAttributedString *attributedPlaceholder API_AVAILABLE(ios(6.0));

用这个就就可以了

CoderMaurice avatar Jul 25 '19 04:07 CoderMaurice

漂亮

ChenYilong avatar Jul 25 '19 06:07 ChenYilong

你那个ValueForKey的key._去掉就不崩溃.有_就崩溃...我刚也试了试

MeteoriteMan avatar Jul 29 '19 13:07 MeteoriteMan

[self setValue:@"xxx " forKey:@"_cancelButtonText"]; 这个有什么新方法替代吗?

yuzhiyou1990 avatar Aug 05 '19 03:08 yuzhiyou1990

[self setValue:@“xxx”forKey:@“_ cancelButtonText”]; 这个有什么新方法替代吗?

去掉下划线,亲测没问题

searchBar.setValue("呵呵哒", forKey: "cancelButtonText")

MeteoriteMan avatar Aug 05 '19 09:08 MeteoriteMan

你那个ValueForKey的key._去掉就不崩溃.有_就崩溃...我刚也试了试

UISearchBar的valueForKey:@"_cancelButton"会崩溃

kingstarwmx avatar Aug 12 '19 11:08 kingstarwmx

试试[[[[UIApplication sharedApplication] valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews]

wyxy2005 avatar Aug 30 '19 07:08 wyxy2005

UITextField *searchField = [self.searchController.searchBar valueForKey:@"_searchField"];

在iOS13下,需要使用新属性,否则也是闪退

UITextField *searchField = self.searchController.searchBar.searchTextField;

hstdt avatar Sep 03 '19 03:09 hstdt

_placeholderLabel 有什么替代方案么?

LuckyRoc avatar Sep 17 '19 05:09 LuckyRoc

UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

这个也会crash

zhfwch avatar Sep 17 '19 07:09 zhfwch

[_textView setValue:_placeholderLabel forKey:@"_placeholderLabel"]; 这个呢? 我还没更新

24KYang avatar Sep 20 '19 08:09 24KYang

UITableViewCell中cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;方框问题 在xcode10上打包运行到ios13会有方框怎么解决

wlingf avatar Sep 25 '19 08:09 wlingf

UITableViewCell中cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;方框问题 在xcode10上打包运行到ios13会有方框怎么解决

你用了VVImageTint这种框架吧,和新api重名了

hstdt avatar Sep 25 '19 08:09 hstdt

VVImageTint 这个框架没用过啊

wlingf avatar Sep 25 '19 08:09 wlingf

但是有imagewithtint 这种方法

wlingf avatar Sep 25 '19 08:09 wlingf

已解决,UITableViewCell中cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;方框问题

wlingf avatar Sep 25 '19 08:09 wlingf

已解决,UITableViewCell中cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;方框问题

怎么解决的,是你自己的代码吗

peter2022Begin avatar Sep 25 '19 09:09 peter2022Begin

已解决,UITableViewCell中cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;方框问题

怎么解决的,是你自己的代码吗

iOS13有和这个方法的同名的系统Api image

hstdt avatar Sep 25 '19 09:09 hstdt

https://github.com/Tencent/QMUI_iOS/issues/617

ChenYilong avatar Sep 25 '19 22:09 ChenYilong