iOS13不允许 valueForKey、setValue: forKey 获取和设置私有属性
iOS13以前:
// textField
[_textField setValue:[UIColor orangeColor] forKeyPath:@"_placeholderLabel.textColor"];
// textView
[_textView setValue:创建的label的对象 forKey:@"_placeholderLabel"];
iOS13以后可以修改为:
// 通过 runtime 获取对象属性
// instance:textField或者textView对象
// name:属性名字例如(@"_placeholderLabel")
Ivar ivar = class_getInstanceVariable(instance.class, name.UTF8String);
UILabel *label = object_getIvar(aTextField, ivar);
// 通过设置label修改
iOS13之后模态present跳转后页面没有充满屏幕
- 因为iOS13之后默认类型为 UIModalPresentationPageSheet 导致
解决办法:
设置 modalPresentationStyle 为 UIModalPresentationFullScreen
iOS13之后 deviceToken 获取方式改变
- 修改方式如下:
NSString *tokenStr = nil;
if (@available(iOS 13.0, *)) {
// 适配iOS13
NSMutableString *deviceStr = [NSMutableString string];
const char *bytes = deviceToken.bytes;
NSInteger count = deviceToken.length;
for (int i = 0; i < count; i++) {
[deviceStr appendFormat:@"%02x", bytes[i]&0x000000FF];
}
tokenStr = deviceStr;
}else {
// iOS13以前
NSString *deviceStr = [deviceToken description];
if ((deviceStr.length > 0) && ([deviceStr rangeOfString:@"<"].location != NSNotFound)) {
NSString *tk0 = [deviceStr stringByReplacingOccurrencesOfString:@"<"withString:@""];
NSString *tk1 = [tk0 stringByReplacingOccurrencesOfString:@">"withString:@""];
tokenStr = [tk1 stringByReplacingOccurrencesOfString:@" "withString:@""];
}
}
NSLog(@"%@",tokenStr);