UIAlertView已经过时,并且对于基于UIScene的应用程序不可用,请使用UIAlertController。

6 浏览
0 Comments

UIAlertView已经过时,并且对于基于UIScene的应用程序不可用,请使用UIAlertController。

我对Swift不熟悉,但我遇到了这个错误。

我不明白为什么会出错,因为我在代码中没有使用任何类型的警告。

这是我的ViewController:

import UIKit

import WebKit

class ViewController: UIViewController{

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {

super.viewDidLoad()

let url = URL(string: "https://www.google.com/maps")!

webView.load(URLRequest(url: url))

}

}

我只想在我的应用程序中使用WKWebView并使用位置。

我已经在`info.plist`中添加了`NSLocationAlwaysAndWhenInUseUsageDescription`。

如果你使用iOS 13、Xcode和这个示例以及任何使用位置的网站(如谷歌地图),你可以重现这个错误。

0
0 Comments

UIAlertView is deprecated and unavailable for UIScene based applications, please use UIAlertController的问题出现的原因是因为新的场景(Scene)基础应用程序不支持UIAlertView,所以在应用程序中使用UIAlertView会导致应用程序崩溃。解决这个问题的方法是将应用程序从场景(Scene)基础应用程序改为窗口(Window)基础应用程序。以下是解决方法的具体步骤:

1. 首先,删除SceneDelegate文件。

2. 其次,从AppDelegate文件中删除UISceneSession生命周期的两个方法。

3. 然后,打开info.plist文件并删除Application Scene Manifest Entry。

4. 接下来,构建并运行项目,确保在AppDelegate中有window属性的声明。

5. 对于Objective-C语言,需要在AppDelegate的类声明中添加strong, nonatomic属性的UIWindow *window声明。

以上就是解决UIAlertView is deprecated and unavailable for UIScene based applications, please use UIAlertController问题的原因和解决方法。通过按照上述步骤,可以成功解决这个问题。

0