1

实际上,在我的应用程序中,我从他们更新共享组文件夹中的领域数据库中获得了通知服务扩展,并且主应用程序也写入相同的内容。

有时我的应用程序由于出现死锁而停止工作,并且应用程序总是无法写入。应用程序在主应用程序初始化过程中有数据库编写代码。所以只有手机重启才能让用户摆脱问题。

这是我的通知扩展代码

func updateInTime(userId: Int) {

        let container = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.****")
        let realmURL = container!.appendingPathComponent("default.realm")
        do {
            let config = Realm.Configuration(
                fileURL: realmURL,
                schemaVersion: schemaVersion)
            Realm.Configuration.defaultConfiguration = config
            updateUserTime(userId: userId)
        }
    }


    func updateUserTime(userId: Int) {
       do {
            let realm = try Realm()
            let predicate = NSPredicate(format: "userID == %d", userId)
            let inTimes = realm.objects(UserInTime.self).filter(predicate)
            if let inTime = inTimes.first {
                try realm.write {
                    inTime.inRadiusTime = Date()
                }

            }
        } catch {
            //Logger.KWLogDebug("Failed to access the Realm database")
        }
        do {
            let realm = try Realm()
            let inTime = UserInTime()
            inTime.userID = userId
            inTime.inRadiusTime = Date()

            try realm.write {
                realm.addOrUpdate(inTime)
            }
        } catch {
            print(error)
        }

    }

来自 didReceive(_ request: contentHandler:) 的 updateInTime 函数调用

境界版:

3.10.0

这是来自设备的崩溃日志信息

**Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
Termination Description: SPRINGBOARD, scene-create watchdog transgression: application<com.myapp>:9023 exhausted real (wall clock) time allowance of 29.25 seconds | ProcessVisibility: Background | ProcessState: Running | WatchdogEvent: scene-create | WatchdogVisibility: Background | WatchdogCPUStatistics: ( | "Elapsed total CPU time (seconds): 52.630 (user 52.630, system 0.000), 29% CPU", | "Elapsed application CPU time (seconds): 0.725, 0% CPU" | )
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001b7eae27c 0x1b7e87000 + 160380
1   Realm                           0x00000001084644e4 realm::util::File::lock+ 2802916 (bool, bool) + 64
2   Realm                           0x0000000108396800 realm::SharedGroup::do_begin_write+ 1959936 () + 88
3   Realm                           0x00000001082e5c68 realm::_impl::transaction::begin(std::__1::unique_ptr<realm::SharedGroup, std::__1::default_delete<realm::SharedGroup> > const&, realm::BindingContext*, realm::_impl::NotifierPackage&) + 1236072 (group_shared.hpp:986)
4   Realm                           0x00000001081fc568 realm::_impl::RealmCoordinator::promote_to_write(realm::Realm&) + 279912 (realm_coordinator.cpp:856)
5   Realm                           0x00000001082c04f4 realm::Realm::begin_transaction() + 1082612 (shared_realm.cpp:667)
6   Realm                           0x000000010828f43c -[RLMRealm beginWriteTransaction] + 881724 (RLMRealm.mm:577)
7   myapp-ios                       0x00000001050d0630 specialized static UserSettings.update+ 1082928 (_:) + 460**

我该如何解决这个问题。

4

0 回答 0