iOS 应用程序在重启前不会启动 phone
iOS app will not launch until restart phone
我不太确定从哪里开始。我在 Swift 中有一个用于 iOS 10.3 的 iOS 应用程序,它使用 Crashlytics 和 Realm,一天几次,当我启动我的应用程序时,它只是位于启动屏幕上,然后及时关闭。发生这种情况时(通过 crashlytics,或在设备上),我没有收到任何日志,而这个问题自行解决的唯一方法是,如果我重新启动 phone、重新安装应用程序,或者如果我在几个小时后重试。我不知道如何调试这个问题。
我的应用启动函数如下:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Fabric.with([Crashlytics.self])
// Override point for customization after application launch.
self.createDirectories()
var performShortcutDelegate = true
let dir: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.BackloggerSharing")!
let realmPath = dir.appendingPathComponent("db.realm")
let config = Realm.Configuration(fileURL: realmPath, schemaVersion: 1, migrationBlock: {
migration, oldSchemaVersion in
if oldSchemaVersion < 1 {
// auto migrate
}
})
Realm.Configuration.defaultConfiguration = config
self.compactRealm(at: realmPath)
(UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self])).tintColor = Util.appColor
UISlider.appearance().tintColor = Util.appColor
self.window?.tintColor = Util.appColor
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
self.shortcutItem = shortcutItem
performShortcutDelegate = false
}
return performShortcutDelegate
}
func createDirectories() {
let playlistsFolder = Util.getPlaylistImagesDirectory()
if !FileManager.default.fileExists(atPath: playlistsFolder.absoluteString) {
do {
try FileManager.default.createDirectory(at: playlistsFolder, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
NSLog(error.localizedDescription)
}
}
}
func compactRealm(at realmPath: URL) {
let defaultParentURL = realmPath.deletingLastPathComponent()
let compactedURL = defaultParentURL.appendingPathComponent("default-compact.realm")
autoreleasepool {
let realm = try? Realm()
try! realm?.writeCopy(toFile: compactedURL)
}
try! FileManager.default.removeItem(at: realmPath)
try! FileManager.default.moveItem(at: compactedURL, to: realmPath)
}
如有任何帮助,我们将不胜感激!
如果您使用 Realm,并且在数据库中进行了更改,您应该重新安装该应用程序,否则它会在启动屏幕上崩溃,
如果以上不是问题,那么可能是您的应用使用了最大内存,或者您的某些代码导致了内存泄漏。
原来是我的 Today Extension 中有一个未关闭领域实例的领域开放。当我加载我的应用程序时,我会尝试打开另一个领域(现在在不受支持的第二个进程中),并执行迁移和压缩。我已经更新了 Today Extension 以关闭不需要的领域实例。
此调试是由于我的应用程序未保存日志而确定的,因为我达到了应用程序允许的最大值 (25)。我清除了日志,找到了它们,对它们进行了符号化,发现 Realm 在打开时遇到了困难。
我不太确定从哪里开始。我在 Swift 中有一个用于 iOS 10.3 的 iOS 应用程序,它使用 Crashlytics 和 Realm,一天几次,当我启动我的应用程序时,它只是位于启动屏幕上,然后及时关闭。发生这种情况时(通过 crashlytics,或在设备上),我没有收到任何日志,而这个问题自行解决的唯一方法是,如果我重新启动 phone、重新安装应用程序,或者如果我在几个小时后重试。我不知道如何调试这个问题。
我的应用启动函数如下:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Fabric.with([Crashlytics.self])
// Override point for customization after application launch.
self.createDirectories()
var performShortcutDelegate = true
let dir: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.BackloggerSharing")!
let realmPath = dir.appendingPathComponent("db.realm")
let config = Realm.Configuration(fileURL: realmPath, schemaVersion: 1, migrationBlock: {
migration, oldSchemaVersion in
if oldSchemaVersion < 1 {
// auto migrate
}
})
Realm.Configuration.defaultConfiguration = config
self.compactRealm(at: realmPath)
(UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self])).tintColor = Util.appColor
UISlider.appearance().tintColor = Util.appColor
self.window?.tintColor = Util.appColor
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
self.shortcutItem = shortcutItem
performShortcutDelegate = false
}
return performShortcutDelegate
}
func createDirectories() {
let playlistsFolder = Util.getPlaylistImagesDirectory()
if !FileManager.default.fileExists(atPath: playlistsFolder.absoluteString) {
do {
try FileManager.default.createDirectory(at: playlistsFolder, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
NSLog(error.localizedDescription)
}
}
}
func compactRealm(at realmPath: URL) {
let defaultParentURL = realmPath.deletingLastPathComponent()
let compactedURL = defaultParentURL.appendingPathComponent("default-compact.realm")
autoreleasepool {
let realm = try? Realm()
try! realm?.writeCopy(toFile: compactedURL)
}
try! FileManager.default.removeItem(at: realmPath)
try! FileManager.default.moveItem(at: compactedURL, to: realmPath)
}
如有任何帮助,我们将不胜感激!
如果您使用 Realm,并且在数据库中进行了更改,您应该重新安装该应用程序,否则它会在启动屏幕上崩溃, 如果以上不是问题,那么可能是您的应用使用了最大内存,或者您的某些代码导致了内存泄漏。
原来是我的 Today Extension 中有一个未关闭领域实例的领域开放。当我加载我的应用程序时,我会尝试打开另一个领域(现在在不受支持的第二个进程中),并执行迁移和压缩。我已经更新了 Today Extension 以关闭不需要的领域实例。
此调试是由于我的应用程序未保存日志而确定的,因为我达到了应用程序允许的最大值 (25)。我清除了日志,找到了它们,对它们进行了符号化,发现 Realm 在打开时遇到了困难。