ChenYilong / iOS13AdaptationTips

iOS13 AdaptationTips
MIT License
175 stars 6 forks source link

新系统 KVC crash 风险 #12

Open ChenYilong opened 5 years ago

ChenYilong commented 5 years ago

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

peter2022Begin commented 5 years ago

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

ChenYilong commented 5 years ago

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

huangzhifei commented 5 years ago

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

确定?我用的不行

CoderMaurice commented 5 years ago

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

用这个就就可以了

ChenYilong commented 5 years ago

漂亮

MeteoriteMan commented 5 years ago

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

yuzhiyou1990 commented 5 years ago

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

MeteoriteMan commented 5 years ago

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

去掉下划线,亲测没问题

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

kingstarwmx commented 5 years ago

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

UISearchBar的valueForKey:@"_cancelButton"会崩溃

wyxy2005 commented 5 years ago

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

hstdt commented 5 years ago

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

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

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

LuckyRoc commented 4 years ago

_placeholderLabel 有什么替代方案么?

zhfwch commented 4 years ago

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

这个也会crash

24KYang commented 4 years ago

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

wlingf commented 4 years ago

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

hstdt commented 4 years ago

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

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

wlingf commented 4 years ago

VVImageTint 这个框架没用过啊

wlingf commented 4 years ago

但是有imagewithtint 这种方法

wlingf commented 4 years ago

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

peter2022Begin commented 4 years ago

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

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

hstdt commented 4 years ago

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

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

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

ChenYilong commented 4 years ago

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