0

My app crashes in iPad Air,os 12.2.0.. the crashlytics in Fabric shows the crash at line 315

NSAssert( result == noErr, @"Couldn't add the Keychain Item." );

in KeychainItemWrapper.m file. This method is called to store UUID in app :

func getUUIDString() -> String {
        if !uuid.trimmed().isEmpty {
            print("uuid ==> \(uuid)")
            return uuid // return cached value
        }
        /// Generate A Dynamic UDID
        var toRet = ""
        /// Wrapper Object
        let keychainWrapperObj = KeychainItemWrapper(identifier: "ManDown", accessGroup: nil)
        /// Check is Any UDID Stored
        if let udidSavedVal = keychainWrapperObj?.object(forKey: kSecAttrService) {
            print("Old UDID is being Used now as ==> \(udidSavedVal as? String ?? "")")
            toRet = udidSavedVal as? String ?? ""
        }

        if toRet.trimmed().isEmpty {
            /// We have no UDID Saved Need to get New
            if UserDefaultManager.getUUIDSaved() != nil {
                toRet = UserDefaultManager.getUUIDSaved()!

//The line causing crash keychainwraper.setobject()

                keychainWrapperObj?.setObject(toRet, forKey: kSecAttrService)


            } else {
                /// Need to Get new UUID
                var newUUIDStr: String?
                newUUIDStr = UIDevice.current.identifierForVendor!.uuidString
                print(newUUIDStr!)
                UserDefaultManager.saveUUIDInDefaultAs(UUIDString: newUUIDStr!)
                toRet = newUUIDStr!
                keychainWrapperObj?.setObject(toRet, forKey: kSecAttrService)
            }
        }

        print("uuid ==> \(toRet)")
        uuid = toRet
        Crashlytics.sharedInstance().setUserName(uuid)
        return uuid
    }

Well my question is how can I solve this crash and how can I at least replicate this error for further debugging. Xcode 10.2 swift 4 The capability is not on for keychainSharing, but the app is still working fine.

Error logs: 
Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x191b53518 __exceptionPreprocess
1  libobjc.A.dylib                0x190d2e9f8 objc_exception_throw
2  CoreFoundation                 0x191a6d148 +[_CFXNotificationTokenRegistration keyCallbacks]
3  Foundation                     0x1925301c8 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
Rj19
  • 305
  • 1
  • 6
  • 20
  • Please share a crash-log and the line that is causing it. – koen Jan 14 '20 at 13:17
  • have you tried to debug the code? If so, which line is causing a problem? – Vanya Jan 14 '20 at 13:26
  • 2
    Given the amount of force unwrapping, it’s hard to identify it. You may consider to unwrap the values with the canonical if-let/guard let or ??. For example: ‘ let newUUIDstr = UIDevice.current.identifierForVendor?.uuidString ?? “fallbackValue” ‘ – Luca Iaco Jan 14 '20 at 13:27
  • well, I tried debugging it but its working fine. There is no crash at all. U can say I am unable to replicate the error. – Rj19 Jan 14 '20 at 13:29

0 Answers0