添加子控制器或 Present 时奇怪的情况在故事板中的 Mapview 上崩溃(添加了示例代码)
Weird situation Crashes on Mapview in storyboard when Add child controller or Present (Sample code added)
我在故事板中只有 mapview 的视图控制器。
class MapVC: UIViewController {
class func viewController () -> MapVC {
let storyboard = UIStoryboard(name: "Dashboard", bundle: nil)
return storyboard.instantiateViewController(withIdentifier: "MapVC") as! MapVC
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
我有简单的登录屏幕
在登录按钮操作上我调用此方法
private func addChildVC (_ vc:UIViewController) {
self.removeAllChild()
self.addChild(vc)
vc.view.frame = self.view.bounds
self.view.addSubview(vc.view)
vc.didMove(toParent: self)
self.currentCenterViewController = vc
}
与
MapVC.viewController()
应用程序崩溃于
vc.view.frame = self.view.bounds
奇怪的是,如果我像附加调试器一样进行调试,当我按下登录应用程序时没有崩溃,但是当调试器未在启动时附加时,然后我在模拟器中启动应用程序然后附加进程,当我按下登录按钮时应用程序崩溃
当前视图控制器也不工作导致应用程序崩溃
如果我从 Storyboard 应用程序中删除 Mapview 在这两种情况下都工作正常
当我检查 vc.isViewLoaded
返回时 false
尝试了 loadViewIfRequired()
清理派生数据,清理项目重新启动 xcode。
确认我添加了正确的标识符
我无法理解原因请帮助
编辑
示例应用程序
https://drive.google.com/open?id=1-otaZhhhDEH4p29CgQP7xZSX9tizceq8
重现步骤
1) 运行 在 ios 12
的任何模拟器中
2) 从 xcode
按停止
3) 从模拟器启动应用程序
4) 按下按钮
EDIT2
发布视频https://drive.google.com/file/d/1z9C3Re_oVYkRncnE22xRoef2Kv2WyzId/view
提交错误 https://bugreport.apple.com/web/?problemID=46774084
我不知道实际问题是什么以及您的应用崩溃的原因。但我找到了解决方案。
在 Link 中添加 MapKit.framework Binary With Libraries 将解决您的问题。
希望对您有所帮助。
我找到了真正的原因。
是因为查看调试器框架
这里是苹果开发团队的回复
Engineering has provided the following information regarding this issue:
The sample project provided is not configured correctly.
The application is using the MapKit framework, but has not been configured to link with MapKit. When run using the debugger, MapKit is pulled in because it’s linked by the view debugger framework.
When the app is launched from the simulator, without the view debugger, MapKit will not be loaded into the runtime as the app has not specified this as a dependency and therefor it crashes.
Updating your sample project to link MapKit solves the issue with the application crashing.
我在故事板中只有 mapview 的视图控制器。
class MapVC: UIViewController {
class func viewController () -> MapVC {
let storyboard = UIStoryboard(name: "Dashboard", bundle: nil)
return storyboard.instantiateViewController(withIdentifier: "MapVC") as! MapVC
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
我有简单的登录屏幕
在登录按钮操作上我调用此方法
private func addChildVC (_ vc:UIViewController) {
self.removeAllChild()
self.addChild(vc)
vc.view.frame = self.view.bounds
self.view.addSubview(vc.view)
vc.didMove(toParent: self)
self.currentCenterViewController = vc
}
与
MapVC.viewController()
应用程序崩溃于
vc.view.frame = self.view.bounds
奇怪的是,如果我像附加调试器一样进行调试,当我按下登录应用程序时没有崩溃,但是当调试器未在启动时附加时,然后我在模拟器中启动应用程序然后附加进程,当我按下登录按钮时应用程序崩溃
当前视图控制器也不工作导致应用程序崩溃
如果我从 Storyboard 应用程序中删除 Mapview 在这两种情况下都工作正常
当我检查 vc.isViewLoaded
返回时 false
尝试了 loadViewIfRequired() 清理派生数据,清理项目重新启动 xcode。 确认我添加了正确的标识符
我无法理解原因请帮助
编辑
示例应用程序
https://drive.google.com/open?id=1-otaZhhhDEH4p29CgQP7xZSX9tizceq8
重现步骤
1) 运行 在 ios 12
的任何模拟器中
2) 从 xcode
按停止
3) 从模拟器启动应用程序
4) 按下按钮
EDIT2
发布视频https://drive.google.com/file/d/1z9C3Re_oVYkRncnE22xRoef2Kv2WyzId/view
提交错误 https://bugreport.apple.com/web/?problemID=46774084
我不知道实际问题是什么以及您的应用崩溃的原因。但我找到了解决方案。 在 Link 中添加 MapKit.framework Binary With Libraries 将解决您的问题。
希望对您有所帮助。
我找到了真正的原因。
是因为查看调试器框架
这里是苹果开发团队的回复
Engineering has provided the following information regarding this issue:
The sample project provided is not configured correctly.
The application is using the MapKit framework, but has not been configured to link with MapKit. When run using the debugger, MapKit is pulled in because it’s linked by the view debugger framework.
When the app is launched from the simulator, without the view debugger, MapKit will not be loaded into the runtime as the app has not specified this as a dependency and therefor it crashes.
Updating your sample project to link MapKit solves the issue with the application crashing.