这是对这个过时问题的更新:Alternate Icon in iOS 10.3: avoid notification dialog for icon change
func setAppIcon(Type: String) {
if #available(iOS 10.3, *) {
UIApplication.shared.setAlternateIconName(Type)
}
}
上面几行可以动态更改Appicon,iOS 10.3添加了该功能。
上面的代码工作正常,但每次应用程序图标更改iOS都会触发这样的提醒:
那么有没有办法摆脱这种警报? (我知道苹果可以拒绝禁用用户信息的申请,但我只想将其用于测试目的)
任何帮助都会非常感谢,谢谢! : - )
答案 0 :(得分:1)
尝试以下代码,但是,它是用Objective-c编写的。它使用私有方法,我想你永远不会介意。
- (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) {});
}
}
}