前提環境
- Xcode 11.3
- Swift 5.1
info.plistの設定
謎の挙動
許諾アラートで「OK」をtapして、WKWebViewをいったん閉じて、再度WKWebViewを開いてもまた許諾アラートが表示されます。
2回目の「OK」で記憶されて、3回目は表示されなくなるようです。
この挙動の原因と回避方法は謎です。。。どなたかご存知でしたら教えてください。
注意点
Xcode 11.3で新規作成したプロジェクトでは、コンテンツが位置情報を取得しようとした際にコンソールに以下のログが出力されてクラッシュします。
*** Terminating app due to uncaught exception 'NSObjectNotAvailableException',
reason: 'UIAlertView is deprecated and unavailable for UIScene based applications,
please use UIAlertController!'
許諾アラートが表示されるタイミングで、Xcode 11で新規にプロジェクトを作成した時のデフォルトである「scene baseアプリケーション」の場合にクラッシュしてしまうようです。
許諾アラートはアプリ側で実装している訳ではないので、どうやらSDKのバグっぽい雰囲気です。
Xcode 11.3現在では、window baseアプリケーションにするしかなさそうです。
1.SceneDelegate.swiftをファイルごと削除
2.AppDelegate.swiftを修正
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? // この行を追加
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
// ここから下を削除
// // MARK: UISceneSession Lifecycle
//
// func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// // Called when a new scene session is being created.
// // Use this method to select a configuration to create the new scene with.
// return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
// }
//
// func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// // Called when the user discards a scene session.
// // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
// }
}
3.info.plistから"Application Scene Manifestを削除
この件については、Xcodeがバージョンアップされたら再確認しようと思います。