I'm using this new feature and when the change is made with an active application, a notification dialog is displayed saying that icon has been modified. How to disable this dialog ?
Alternate Icon in iOS 10.3: avoid notification dialog for icon change
I don't think this is possible - this alert is shown by the system. Not displaying it could lead to potential abuse. –
Intervocalic
If you don't mind making use of private method, you can try the following code.
- (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) {});
}
}
}
Great.. will they reject the app? –
Shewmaker
My apps aren't been rejected, so you can have a try. Variable selectorString is anti code static analysis. –
Finfoot
how do you convert this to Swift 5 @Robert –
Disclosure
Scanbot is doing it in their app, so I guess it should be fine to use for now –
Aircondition
Adding to Andrew's Swift 5 rewrite of Robert's answer (as I don't have the reputation to comment).
For the default icon we need to pass nil, so iconName should be an optional.
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 })
}
}
Rewrote Robert's answer in Swift. The app hasn't been rejected as well.
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 })
}
}
I can confirm it works in iOS16, too. waiting to Store approval.. –
Sedimentary
Did you get the approve? –
Harvell
approved, BUT seems not working in iPad.. we will investigate further. –
Sedimentary
From the above Answer from Robert
- (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) {});
}
}
}
I couldn't make the line
void (*func)(id, SEL, id, id) = (void *)imp;
For me it had to be
void (*func)(id, SEL, id, id) = (void (*)(id, SEL, id, id))imp;
import UIKit
extension UIApplication {
func setAppIcon(_ appIcon: String?) {
typealias setAlternateIconName = @convention(c) (
NSObject, Selector, NSString?, @escaping (NSError?) -> Void
) -> Void
let selector = NSSelectorFromString(
"_setAlternateIconName:completionHandler:"
)
if let imp = method(for: selector) {
let method = unsafeBitCast(imp, to: setAlternateIconName.self)
method(self, selector, appIcon as NSString?, { _ in })
}
}
}
© 2022 - 2024 — McMap. All rights reserved.