Loading... ## 背景 IOS18场景下无法点击更新程序按钮,点击后无效果 经过各种排查之后发现: ```shell BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(_:) needs to migrate to the non-deprecated UIApplication.open(_:options:completionHandler:). Force returning false (NO). ``` ![](https://oss-image.taowiki.com/blog-image/2024/11/20/673d541964c3e.png) 好吧,`UIApplication.openURL(_:)` 已经被废弃了,需要更新成新的方式 ## 更正 ### 原 ```flutter -(void)openAppStore:(NSString *)iOSUrl{ NSString *url = [iOSUrl stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@""] invertedSet]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; } ``` ### 新 ```flutter -(void)openAppStore:(NSString *)iOSUrl { // 对URL进行编码 NSString *encodedUrl = [iOSUrl stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@""] invertedSet]]; // 将 NSString 转换为 NSURL NSURL *url = [NSURL URLWithString:encodedUrl]; // 检查是否可以打开该 URL if ([[UIApplication sharedApplication] canOpenURL:url]) { // 打开 URL [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { if (success) { NSLog(@"Successfully opened the URL."); } else { NSLog(@"Failed to open the URL."); } }]; } else { NSLog(@"Cannot open the URL."); } } ``` ## 开源项目 我用的项目是:https://github.com/azhon/flutter_app_update 提交了issues并且被合并了,但是用它更新后的版本与我本地有依赖冲突,所以我自己改了一个版本 https://github.com/almightyYantao/flutter_app_update ```flutter flutter_app_update: git: url: https://github.com/almightyYantao/flutter_app_update ``` 最后修改:2024 年 11 月 20 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏