归档应用并在设备上安装后,我处于应用崩溃的奇怪状态。还有很多其他类似的帖子在SO上有相同的标题我相信,但这是我的应用程序正在发生的事情 -
在AppDelegate中,我有以下内容 -
func loadInitialViews () {
let deviceLanguage = NSLocale.currentLocale().objectForKey(NSLocaleLanguageCode) as! String
DDLogVerbose("Device Language:\(deviceLanguage)")
let xtraStoryboard = UIStoryboard(name: "Main", bundle: nil)
if (appLanguageStatusDefault == false) {
if ((deviceLanguage != "fr") && (deviceLanguage != "nl")) {
let myInitialVc = xtraStoryboard.instantiateViewControllerWithIdentifier("languageVc")
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = myInitialVc
self.window?.makeKeyAndVisible()
}
else {
defaults.setValue(deviceLanguage, forKey: defaultsKeys.appLanguage)
defaults.setBool(true, forKey: defaultsKeys.appLanguageStatus)
defaults.synchronize()
let s = UIStoryboard (
name: "LoginStoryboard", bundle: NSBundle(forClass: UserLoginViewController.self)
)
frameworkViewController = s.instantiateViewControllerWithIdentifier("LoginViewControllerId") as? UserLoginViewController
frameworkViewController!.appUrl = "\(requestProtocol)://\(requestDomain)/\(requestBase)/\(requestVersion)/\(appLanguageDefault)/customer/logon?client=iziapp"
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = frameworkViewController
self.window?.makeKeyAndVisible()
frameworkViewController!.viewControllerId = "loginViewController"
}
}
else {
defaults.setValue(appLanguageDefault, forKey: defaultsKeys.appLanguage)
defaults.setBool(true, forKey: defaultsKeys.appLanguageStatus)
defaults.synchronize()
let s = UIStoryboard (
name: "LoginStoryboard", bundle: NSBundle(forClass: UserLoginViewController.self)
)
frameworkViewController = s.instantiateViewControllerWithIdentifier("LoginViewControllerId") as? UserLoginViewController
frameworkViewController!.appUrl = "\(requestProtocol)://\(requestDomain)/\(requestBase)/\(requestVersion)/\(appLanguageDefault)/customer/logon?client=iziapp"
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = frameworkViewController
self.window?.makeKeyAndVisible()
frameworkViewController!.viewControllerId = "loginViewController"
}
}
我的应用程序崩溃后,我将其存档并安装在设备上。应用程序崩溃信息(通过使用NSZombieEnabled)表示appLanguageDefault发生了崩溃。以下是设备崩溃日志的详细信息 -
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 Xtra 0x001b7700 globalinit_33_F56DB677A89F23933EFF171487480023_func9 (AppDelegate.swift:49)
1 libdispatch.dylib 0x23da3caa _dispatch_client_callout + 22
2 libdispatch.dylib 0x23da489a dispatch_once_f + 62
3 Xtra 0x0006ea4c AppDelegate.loadInitialViews() -> () (AppDelegate.swift:0)
4 Xtra 0x0007124c specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift:120)
5 Xtra 0x0006e028 @objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift:0)
我想要实现的目标是什么?
启动应用
检查设备语言(查看fr或nl是否为设备语言)。
如果是fr或nl,那么appLanguageDefault将设置为其中之一。 appLanguageStatusDefault设置为true(表示已为应用程序设置了一种语言)。然后,显示登录屏幕。
如果是fr或nl以外的任何语言,则会显示语言选择屏幕。 appLanguageDefault设置为选定的语言。 appLanguageStatusDefault设置为true,然后显示登录屏幕。
当我通过Xcode和模拟器在设备上安装应用程序时,上述过程很有效。但是当我在设备上存档并安装时,应用程序崩溃了。
有人可以帮忙搞清楚这次崩溃吗?
UPDATE1:我的设备/配置文件/证书没有问题,因为我可以在我以前的版本上升级安装。如果用户在升级安装时已经登录,则应用程序通常会与其他屏幕一起运行。问题仅出现在AppDelegate的loadInitialViews()