我正在使用这个新功能,当使用活动应用程序进行更改时,会显示一个通知对话框,说明该图标已被修改。如何禁用此对话框?
问问题
3369 次
3 回答
9
如果您不介意使用私有方法,可以尝试以下代码。
- (void)lc_setAlternateIconName:(NSString*)iconName
{
//anti apple private method call analyse
if ([[UIApplication sharedApplication] respondsToSelector:@selector(supportsAlternateIcons)] &&
[[UIApplication sharedApplication] supportsAlternateIcons])
{
NSMutableString *selectorString = [[NSMutableString alloc] initWithCapacity:40];
[selectorString appendString:@"_setAlternate"];
[selectorString appendString:@"IconName:"];
[selectorString appendString:@"completionHandler:"];
SEL selector = NSSelectorFromString(selectorString);
IMP imp = [[UIApplication sharedApplication] methodForSelector:selector];
void (*func)(id, SEL, id, id) = (void *)imp;
if (func)
{
func([UIApplication sharedApplication], selector, iconName, ^(NSError * _Nullable error) {});
}
}
}
于 2018-04-09T09:53:08.827 回答
6
添加到安德鲁的Swift 5 重写罗伯特的答案(因为我没有评论的声誉)。
对于默认图标,我们需要传递 nil,因此 iconName 应该是可选的。
func setApplicationIconName(_ iconName: String?) {
if UIApplication.shared.responds(to: #selector(getter: UIApplication.supportsAlternateIcons)) && UIApplication.shared.supportsAlternateIcons {
typealias setAlternateIconName = @convention(c) (NSObject, Selector, NSString?, @escaping (NSError) -> ()) -> ()
let selectorString = "_setAlternateIconName:completionHandler:"
let selector = NSSelectorFromString(selectorString)
let imp = UIApplication.shared.method(for: selector)
let method = unsafeBitCast(imp, to: setAlternateIconName.self)
method(UIApplication.shared, selector, iconName as NSString?, { _ in })
}
}
于 2020-09-14T02:00:14.250 回答
4
用 Swift重写了Robert的答案。该应用程序也没有被拒绝。
func setApplicationIconName(_ iconName: String) {
if UIApplication.shared.responds(to: #selector(getter: UIApplication.supportsAlternateIcons)) && UIApplication.shared.supportsAlternateIcons {
typealias setAlternateIconName = @convention(c) (NSObject, Selector, NSString, @escaping (NSError) -> ()) -> ()
let selectorString = "_setAlternateIconName:completionHandler:"
let selector = NSSelectorFromString(selectorString)
let imp = UIApplication.shared.method(for: selector)
let method = unsafeBitCast(imp, to: setAlternateIconName.self)
method(UIApplication.shared, selector, iconName as NSString, { _ in })
}
}
于 2020-09-08T07:26:47.687 回答