ios - AppDelegate valueForUndefinedKey

标签 ios swift service delegates appdelegate

我正在快速制作一个应用程序,但我遇到了一些问题。我正在尝试运行我的应用程序,但每次都会出现错误。

这是完整的错误: *** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[ valueForUndefinedKey:]:此类与键 currentUnityController 不兼容键值编码。”

在 AppDelegate 中我使用这样的服务:

@UIApplicationMain
final class AppDelegate: AppwiseCore.AppDelegate<Config> {
override var services: [ApplicationService] {
    return [
        UnityApplicationService(),
        FabricApplicationService(),
        KeyboardManagerApplicationService()
    ]
}
}

然后我像这样调用 UnityAppcontroller:

var window: UIWindow?

var application: UIApplication?
@objc var currentUnityController: UnityAppController!
var isUnityRunning = false

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    self.application = application
    unity_init(CommandLine.argc, CommandLine.unsafeArgv)
    currentUnityController = UnityAppController()
    currentUnityController.application(application, didFinishLaunchingWithOptions: launchOptions)

    startUnity()
    return true
}

最后,这就是我访问应用程序 Controller 的方式。

NS_INLINE UnityAppController* GetAppController()
{
NSObject<UIApplicationDelegate>* delegate = [UIApplication sharedApplication].delegate;
UnityAppController* currentUnityController = (UnityAppController*)[delegate valueForKey: @"currentUnityController"];
return currentUnityController;

}

安妮帮忙吗?

最佳答案

如果您的 nib(xib 文件)中有一个链接到 View Controller 中的属性 (IBOutlet) 或方法 (IBAction) 的控件,并且您已删除或重命名该属性或方法,则运行时可以'找不到它,因为它已被重命名,因此崩溃了。

关于ios - AppDelegate valueForUndefinedKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49610115/

相关文章:

ios - 如何在自动布局中强制更新约束

Swift AnyObject 变量,使用或链接向下转换(as)以访问不同类的属性

c# - 作为 LocalSystem 运行的 .NET c# 服务更改注册表中的 ProxyServer,但浏览器在(重新)启动之前不会注意到

安装窗口服务时Python已停止工作(3.7)

ios - 使物理体响应场但不响应其他物理体

ios - 如果您的应用程序使用的 API 在您的应用程序发布后被弃用,会发生什么情况?

IOS : Button click not getting registered, xcode 未并行显示代码和 Storyboard

linux - 如何在Linux中将程序作为监听服务运行?

ios - xcode 5 - 打开一个没有 Storyboard的项目

ios - NSNotificationCenter 改变观察者顺序