AppConnect Error : AppConnect cannot be instantiated directly

AppConnect Error : AppConnect cannot be instantiated directly

我正在尝试在 swift 1.2 中使用 AppConnect SDK 访问 MDM,但出现以下错误:

[AppConnect:Error] AppConnect cannot be instantiated directly. Instead, call +initWithDelegate: and then +sharedInstance.

代码片段:

 import UIKit

    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate, AppConnectDelegate {

        var window: UIWindow?        
        var appct = AppConnect()

        func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
            // Override point for customization after application launch.   

            // Initialize the AppConnect library
            AppConnect.initWithDelegate(self)
            self.appct = AppConnect.sharedInstance()
            self.appct.startWithLaunchOptions(launchOptions)

            return true
        } 
}

应用程序在访问 MobileIron 后端配置文件的密钥时崩溃。

还有其他实现方法吗?

您正在没有委托的情况下初始化 AppConnect

改变

var appct = AppConnect();

var appct : AppConnect!;

我的解决方案是在 plist 中设置一个新的 key/value:

Principal class AppConnectUIApplication

或在源代码模式下:

  <key>NSPrincipalClass</key>
    <string>AppConnectUIApplication</string>

希望对你有帮助