只支持iOS10.3以上的系統(tǒng)
image
也可以在info.plist文件右鍵查看xml格式,直接復(fù)制Demo中的info.plist節(jié)點(diǎn)
image
注意點(diǎn):默認(rèn)添加的Icon files(iOS 5)鍵是沒有CFBundleAlternateIcons的! 需要手動(dòng)寫進(jìn)去!
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];
}
導(dǎo)入分類后,直接調(diào)用
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{
}
}
完結(jié).