只支持iOS10.3以上的系统
也可以在info.plist文件右键查看xml格式,直接复制Demo中的info.plist节点
注意点:默认添加的Icon files(iOS 5)键是没有CFBundleAlternateIcons的! 需要手动写进去!
UIVIewController+Present.m分类
+ (void)load {
staticdispatch_once_tonceToken;
dispatch_once(&onceToken, ^{
MethodpresentM =class_getInstanceMethod(self.class,@selector(presentViewController:animated:completion:));
MethodpresentSwizzlingM =class_getInstanceMethod(self.class,@selector(dy_presentViewController:animated:completion:));
method_exchangeImplementations(presentM, presentSwizzlingM);
});
}
- (void)dy_presentViewController:(UIViewController*)viewControllerToPresent animated:(BOOL)flag completion:(void(^)(void))completion {
if([viewControllerToPresentisKindOfClass:[UIAlertControllerclass]]) {
NSLog(@"title : %@",((UIAlertController*)viewControllerToPresent).title);
NSLog(@"message : %@",((UIAlertController*)viewControllerToPresent).message);
UIAlertController*alertController = (UIAlertController*)viewControllerToPresent;
if(alertController.title==nil&& alertController.message==nil) {
return;
}else{
[selfdy_presentViewController:viewControllerToPresentanimated:flagcompletion:completion];
return;
}
}
[selfdy_presentViewController:viewControllerToPresentanimated:flagcompletion:completion];
}
导入分类后,直接调用
privatelazyvarweather = ["晴","多云","小雨","大雨","雪"]
overridefuncviewDidLoad() {
super.viewDidLoad()
}
@IBActionfuncbtnAction(_sender:Any) {
letweatherRdm =weather[Int(arc4random()) % (weather.countasInt)]
setAppIconWithName(iconName: weatherRdm)
}
funcsetAppIconWithName(iconName:String) {
if#available(iOS10.3, *) {
if !UIApplication.shared.supportsAlternateIcons {
return
}
ificonName ==""{
return
}
UIApplication.shared.setAlternateIconName(iconName) { (error)in
iferror !=nil{
}
}
}else{
}
}
完结.