在重新启动手机之前,iOS应用程序不会启动

在重新启动手机之前,iOS应用程序不会启动,ios,swift,realm,crashlytics,Ios,Swift,Realm,Crashlytics,我不完全确定从哪里开始。我在Swift for iOS 10.3中有一个iOS应用程序,它使用Crashlytics和Realm,每天有好几次,当我启动我的应用程序时,它就在启动屏幕上,然后立即关闭。发生这种情况时(通过crashlytics或在设备上),我不会得到任何日志,解决这种问题的唯一方法是重新启动手机、重新安装应用程序,或者在几个小时后重试。我不知道如何调试这个问题 我的应用程序启动功能如下: func application(_ application: UIApplication,

我不完全确定从哪里开始。我在Swift for iOS 10.3中有一个iOS应用程序,它使用Crashlytics和Realm,每天有好几次,当我启动我的应用程序时,它就在启动屏幕上,然后立即关闭。发生这种情况时(通过crashlytics或在设备上),我不会得到任何日志,解决这种问题的唯一方法是重新启动手机、重新安装应用程序,或者在几个小时后重试。我不知道如何调试这个问题

我的应用程序启动功能如下:

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)
}
func应用程序(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptions:[UIApplicationLaunchOptions:Any]?)->Bool{
Fabric.with([Crashlytics.self])
//应用程序启动后自定义的覆盖点。
self.createDirectory()
var performShortcutDelegate=true
let dir:URL=FileManager.default.containerURL(用于安全应用程序组标识符:“group.BackloggerSharing”)!
让realmPath=dir.appendingPathComponent(“db.realm”)
让config=Realm.Configuration(fileURL:realmPath,schemaVersion:1,migrationBlock:{
移民,旧模式厌恶
如果oldschemaversation<1{
//自动迁移
}
})
Realm.Configuration.defaultConfiguration=config
self.compactRealm(at:realmPath)
(UITextField.appearance(当包含instancesof:[UISearchBar.self])).tintColor=Util.appColor
UISlider.appearance().tintColor=Util.appColor
self.window?.tintColor=Util.appColor
如果让shortcutItem=launchOptions?[UIApplicationLaunchOptions.shortcutItem]作为?UIApplicationShortcutItem{
self.shortcutItem=shortcutItem
performShortcutDelegate=false
}
返回performShortcutDelegate
}
func createDirectories(){
让playlisfolder=Util.GetPlaylisImagesDirectory()
如果!FileManager.default.fileExists(路径:playlisfolder.absoluteString){
做{
请尝试FileManager.default.createDirectory(位于:playlisfolder,带中间目录:true,属性:nil)
}将let错误捕获为NSError{
NSLog(错误。本地化描述)
}
}
}
func compactRealm(位于realmPath:URL){
让defaultParentURL=realmPath.deletingLastPathComponent()
让compactedURL=defaultParentURL.appendingPathComponent(“default compact.realm”)
自动释放池{
让realm=try?realm()
try!realm?.writeCopy(toFile:compactedURL)
}
try!FileManager.default.removietem(位于:realmPath)
try!FileManager.default.moveItem(位于:compactedURL,至:realmPath)
}

在此问题上的任何帮助都将不胜感激

如果您使用Realm,并在数据库中进行更改,则应重新安装该应用程序,否则它会在启动屏幕上崩溃,
如果以上不是问题,那么可能是您的应用程序使用了最大内存,或者您的某些代码导致内存泄漏。

结果是,我的Today扩展中打开了一个领域,但没有关闭该领域实例。当我加载我的应用程序时,我会尝试打开另一个领域(现在处于不受支持的第二个进程中),并执行迁移和压缩。我已经更新了Today扩展,以在不需要时关闭领域实例


此调试是根据我的应用程序未保存日志确定的,因为我已达到应用程序允许的最大值(25)。我清除了日志,找到了它们,对它们进行了符号化,发现领域在打开时遇到了困难。

您是否尝试在application:didFinishLaunchingWithOptions:中设置断点?它输入了这个方法吗?如果我从xcode重新启动应用程序,它可以正常工作。只是如果我已经使用我的应用程序一段时间了,无论是从xcode还是从testflight,这都会发生。我无法在附加了调试器的情况下捕捉到这种情况。是否在AppDelegate中重新定义了+initialize方法?此外,如果从该方法返回FALSE,则应用程序可能不会启动,也不会对任何内容进行更改。该应用程序将正常工作,然后有一次它将停止工作。从xcode重新启动效果很好,但如果我只是从springboard点击应用程序,它有时会挂起并崩溃,无论我尝试了多少次,我都无法打开它。我想杀死一个应用程序也会释放它的内存,但我不确定是否是这样。当你从springboard点击应用程序时,你的应用程序是处于后台状态还是不存在于后台可能在
中返回false didfishlaunchingwithoptions
导致问题。