iOS 10.3 中的备用图标:避免图标更改的通知对话框
Posted
技术标签:
【中文标题】iOS 10.3 中的备用图标:避免图标更改的通知对话框【英文标题】:Alternate Icon in iOS 10.3: avoid notification dialog for icon change 【发布时间】:2017-09-07 11:15:15 【问题描述】:我正在使用这项新功能,当使用活动应用程序进行更改时,会显示一个通知对话框,说明图标已被修改。 如何禁用此对话框?
【问题讨论】:
我认为这不可能 - 系统会显示此警报。不显示它可能会导致潜在的滥用。 【参考方案1】:如果你不介意使用私有方法,你可以试试下面的代码。
- (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) );
【讨论】:
太棒了.. 他们会拒绝这个应用吗? 我的应用没有被拒绝,你可以试试。变量selectorString是反代码静态分析。 如何将其转换为 Swift 5 @Robert Scanbot 正在他们的应用程序中执行此操作,所以我想现在应该可以使用了【参考方案2】:用 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 )
【讨论】:
【参考方案3】:添加到Andrew's Swift 5 重写 Robert's 答案(因为我没有评论的声誉)。
对于默认图标,我们需要传递 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 )
【讨论】:
以上是关于iOS 10.3 中的备用图标:避免图标更改的通知对话框的主要内容,如果未能解决你的问题,请参考以下文章