VIDEO_TOO_LONG_TITLE UIImagePickerController 显示的警报
VIDEO_TOO_LONG_TITLE alert shown by UIImagePickerController
我用UIImagePickerController
拍电影。通过设置控制器的 videoMaximumDuration
属性 来限制电影的长度。
当人们试图拍摄一部较长的电影时,会如预期的那样显示警告。
但是 标题为 VIDEO_TOO_LONG_TITLE 的意外附加警报 直接显示在控件上方(见下图)。
显然这是一个 iOS 错误(仅部分本地化,未选择剪辑)。
是否可以隐藏这个不必要和不适当的警报?
imagePicker.allowsEditing = false
我知道这个问题很老了,但这里有一个 Apple 仍未解决的问题的解决方案。
@implementation NSBundle (UIImagePickerControllerLocalizationFix)
+ (void) load {
SEL const selector = @selector (localizedStringForKey:value:table:);
Method const localizedStringMethod = class_getInstanceMethod (self, selector);
NSString *(*originalImp) (NSBundle *, SEL, NSString *, NSString *, NSString *) = (typeof (originalImp)) method_getImplementation (localizedStringMethod);
IMP const updatedImp = (typeof (updatedImp)) imp_implementationWithBlock (^(NSBundle *bundle, NSString *key, NSString *value, NSString *tableName) {
NSString *const result = originalImp (bundle, selector, key, value, tableName);
if ([key isEqualToString:@"VIDEO_TOO_LONG_TITLE"] && [result isEqualToString:key]) {
static NSBundle *properLocalizationBundle = nil;
static NSString *properLocalizationTable = nil;
static dispatch_once_t onceToken;
dispatch_once (&onceToken, ^{
NSString *const originalBundleName = bundle.infoDictionary [(NSString *) kCFBundleNameKey];
NSArray <NSBundle *> *const frameworkBundles = [NSBundle allFrameworks];
for (NSBundle *frameworkBundle in frameworkBundles) {
NSString *const possibleTableName = [originalBundleName isEqualToString:tableName] ? frameworkBundle.infoDictionary [(NSString *) kCFBundleNameKey] : tableName;
NSString *const localizedKey = originalImp (frameworkBundle, selector, key, value, possibleTableName);
if (![localizedKey isEqualToString:key]) {
properLocalizationBundle = frameworkBundle;
properLocalizationTable = possibleTableName;
break;
}
}
if (!(properLocalizationBundle && properLocalizationTable)) { // Giving up
properLocalizationBundle = bundle;
properLocalizationTable = tableName;
}
});
return originalImp (properLocalizationBundle, selector, key, value, properLocalizationTable);
} else {
return result;
}
});
method_setImplementation (localizedStringMethod, updatedImp);
}
@end
我用UIImagePickerController
拍电影。通过设置控制器的 videoMaximumDuration
属性 来限制电影的长度。
当人们试图拍摄一部较长的电影时,会如预期的那样显示警告。
但是 标题为 VIDEO_TOO_LONG_TITLE 的意外附加警报 直接显示在控件上方(见下图)。
显然这是一个 iOS 错误(仅部分本地化,未选择剪辑)。
是否可以隐藏这个不必要和不适当的警报?
imagePicker.allowsEditing = false
我知道这个问题很老了,但这里有一个 Apple 仍未解决的问题的解决方案。
@implementation NSBundle (UIImagePickerControllerLocalizationFix)
+ (void) load {
SEL const selector = @selector (localizedStringForKey:value:table:);
Method const localizedStringMethod = class_getInstanceMethod (self, selector);
NSString *(*originalImp) (NSBundle *, SEL, NSString *, NSString *, NSString *) = (typeof (originalImp)) method_getImplementation (localizedStringMethod);
IMP const updatedImp = (typeof (updatedImp)) imp_implementationWithBlock (^(NSBundle *bundle, NSString *key, NSString *value, NSString *tableName) {
NSString *const result = originalImp (bundle, selector, key, value, tableName);
if ([key isEqualToString:@"VIDEO_TOO_LONG_TITLE"] && [result isEqualToString:key]) {
static NSBundle *properLocalizationBundle = nil;
static NSString *properLocalizationTable = nil;
static dispatch_once_t onceToken;
dispatch_once (&onceToken, ^{
NSString *const originalBundleName = bundle.infoDictionary [(NSString *) kCFBundleNameKey];
NSArray <NSBundle *> *const frameworkBundles = [NSBundle allFrameworks];
for (NSBundle *frameworkBundle in frameworkBundles) {
NSString *const possibleTableName = [originalBundleName isEqualToString:tableName] ? frameworkBundle.infoDictionary [(NSString *) kCFBundleNameKey] : tableName;
NSString *const localizedKey = originalImp (frameworkBundle, selector, key, value, possibleTableName);
if (![localizedKey isEqualToString:key]) {
properLocalizationBundle = frameworkBundle;
properLocalizationTable = possibleTableName;
break;
}
}
if (!(properLocalizationBundle && properLocalizationTable)) { // Giving up
properLocalizationBundle = bundle;
properLocalizationTable = tableName;
}
});
return originalImp (properLocalizationBundle, selector, key, value, properLocalizationTable);
} else {
return result;
}
});
method_setImplementation (localizedStringMethod, updatedImp);
}
@end