Thursday, May 23, 2024
HomeiOS Developmentswift - swift_isUniquelyReferenced_nonNull_native causes random and systematic crash on iOS 17.x

swift – swift_isUniquelyReferenced_nonNull_native causes random and systematic crash on iOS 17.x


In my app, a crash happens solely on iOS 17.xx variations after I set up a BLE connection to a peripheral, scan wifi networks and connect with one in every of them through BLE.

non-public func writeData(writingMode: String) {
    
        guard let discoveredPeripheral = discoveredPeripheral,
                let transferCharacteristic = transferCharacteristic
            else { return }
        
        // test to see if variety of iterations accomplished and peripheral can settle for extra knowledge
  
            let mtu = discoveredPeripheral.maximumWriteValueLength (for: .withoutResponse)
            var rawPacket = [UInt8]()

            if( self.related && !self.wifiScanDone){
                self.knowledge.append(0x20)
                self.knowledge.append(0x04)
                self.knowledge.append(0x00)
                self.knowledge.append(0x00)
                self.knowledge.append(0x03)
                self.knowledge.append(0x47)
                self.knowledge.append(0x02)
                self.knowledge.append(0x10)
                self.knowledge.append(0x00)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0x56) }
        
            else if (self.related && self.wifiScanDone) {
                self.knowledge.append(0x20)
                self.knowledge.append(0x04)
                self.knowledge.append(0x00)
                self.knowledge.append(0x00)
                self.knowledge.append(0x03)
                self.knowledge.append(0x47)
                self.knowledge.append(0x03)
                self.knowledge.append(0x10)
                self.knowledge.append(0x00)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0xff)
                self.knowledge.append(0x57)
                }
                print("writing knowledge", String(describing: self.knowledge))
        
            let bytesToCopy: size_t = min(mtu, self.knowledge.depend)
            self.knowledge.copyBytes(to: &rawPacket, depend: bytesToCopy)
            var packetData = Knowledge(bytes: &rawPacket, depend: bytesToCopy)

            let stringFromData = String(knowledge: packetData, encoding: .utf8)
            os_log("Writing %d bytes: %s", bytesToCopy, String(describing: stringFromData))
            
            discoveredPeripheral.writeValue(packetData, for: transferCharacteristic, sort: .withResponse)
            
            packetData.removeAll()
            self.knowledge.removeAll()
            
            discoveredPeripheral.setNotifyValue(true, for: transferCharacteristic)
            self.writeIterationsComplete += 1
        
    
        if writeIterationsComplete == defaultIterations {
            // Cancel our subscription to the attribute
        }
    }
    
    override func put together(for segue: UIStoryboardSegue, sender: Any?) {
        tremendous.put together(for: segue, sender: sender)
        
        let wifiSelectionController = segue.vacation spot as? WifiSelectionTestViewController
       
        if segue.identifier == "skipSegue" {
            if EcojokoHelper.isEcojokoV2() {
                
                 wifiSelectionController?.wifiNetworksFromBle = wifiNetworks
              
            }
        }
        
    }
    
    non-public func writeDataScanDone() {
        
        guard let discoveredPeripheral = discoveredPeripheral,
              let transferCharacteristic = transferCharacteristic
        else { return }
        
        // test to see if variety of iterations accomplished and peripheral can settle for extra knowledge
            let mtu = discoveredPeripheral.maximumWriteValueLength (for: .withResponse)
            var rawPacket = [UInt8]()
            
            self.knowledge.append(0x20)
            self.knowledge.append(0x04)
            self.knowledge.append(0x00)
            self.knowledge.append(0x00)
            self.knowledge.append(0x03)
            self.knowledge.append(0x47)
            self.knowledge.append(0x03)
            self.knowledge.append(0x10)
            self.knowledge.append(0x00)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0xff)
            self.knowledge.append(0x57)
            
            
            let bytesToCopy: size_t = min(mtu, self.knowledge.depend)
            self.knowledge.copyBytes(to: &rawPacket, depend: bytesToCopy)
            var packetData = Knowledge(bytes: &rawPacket, depend: bytesToCopy)
            
            let stringFromData = String(knowledge: packetData, encoding: .utf8)
            os_log("Writing  scan mode  %d bytes: %s", bytesToCopy, String(describing: stringFromData))
            
            discoveredPeripheral.writeValue(packetData, for: transferCharacteristic, sort: .withResponse)
            
            packetData.removeAll()
            self.knowledge.removeAll()
            
            discoveredPeripheral.setNotifyValue(true, for: transferCharacteristic)
            self.writeIterationsComplete += 1
            self.centralManager.cancelPeripheralConnection(discoveredPeripheral)
            self.cleanup()
            print("**** AT THIS POINT THE WIFI SCAN IS DONE ")
            self.scanWritingData = true
            if (self.related && self.wifiScanDone && self.wifiNames.depend == self.wifiCount &&  self.fillListDone) {
                
                if let centralManager = self.centralManager {
                    centralManager.stopScan()
                    // os_log("Scanning stopped")
                }
                self.knowledge.removeAll(keepingCapacity: false)
            }
    }
    

    /*
     *  If the connection fails for no matter motive, we have to take care of it.
     */
    func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
        os_log("Failed to hook up with %@. %s", peripheral, String(describing: error))
        cleanup()
    }
    
    /*
     *  We have related to the peripheral, now we have to uncover the companies and traits to search out the 'switch' attribute.
     */
    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
        if( !wifiListing)
        {
            print("**** BEFORE CONNECTION ***** The accessible peripherals are : (String(describing: peripheral.companies))")
            os_log("Peripheral Linked")
            self.related = true
            
            // Cease scanning
            self.centralManager.stopScan()
            os_log("Scanning stopped")
            
            connectionIterationsComplete += 1
            writeIterationsComplete = 0
            
            // Clear the info that we might have already got
           // knowledge.removeAll(keepingCapacity: false)
            
            // Ensure we get the invention callbacks
            peripheral.delegate = self
            
            // Search just for companies that match our UUID
            peripheral.discoverServices(nil)
           
        }
    }
# Crashlytics - Stack hint
# Platform: apple
# Model: 1.1 (1.9)
# Difficulty: 412239cf1ac3c946eb36a0f8fcd03787
# Session: 411b37f768814760898b918fa9d8c1b3_DNE_0_v2
# Date: Wed Apr 17 2024 08:14:28 GMT+0200 (heure d’été d’Europe centrale)

com.apple.main-thread
0  libsystem_kernel.dylib         0x1af8 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x1890 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x17a8 mach_msg_overwrite + 436
3  libsystem_kernel.dylib         0x15e8 mach_msg + 24
4  CoreFoundation                 0x3601c __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x33f04 __CFRunLoopRun + 1208
6  CoreFoundation                 0x33968 CFRunLoopRunSpecific + 608
7  GraphicsServices               0x34e0 GSEventRunModal + 164
8  UIKitCore                      0x22aedc -[UIApplication _run] + 888
9  UIKitCore                      0x22a518 UIApplicationMain + 340
10 Vattenfall                     0xb4ec principal + 20 (AppDelegate.swift:20)
11 ???                            0x1b33d6d84 (Manquant)

com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1af8 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x1890 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x17a8 mach_msg_overwrite + 436
3  libsystem_kernel.dylib         0x15e8 mach_msg + 24
4  CoreFoundation                 0x3601c __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x33f04 __CFRunLoopRun + 1208
6  CoreFoundation                 0x33968 CFRunLoopRunSpecific + 608
7  Basis                     0x2b4a8 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  Basis                     0x554e8 -[NSRunLoop(NSRunLoop) runUntilDate:] + 64
9  UIKitCore                      0x18dac8 -[UIEventFetcher threadMain] + 420
10 Basis                     0x9ca9c __NSThread__start__ + 732
11 libsystem_pthread.dylib        0x2a90 _pthread_start + 136
12 libsystem_pthread.dylib        0x1fcc thread_start + 8

com.google.firebase.crashlytics.MachExceptionServer
0  FirebaseCrashlytics            0x1ef18 FIRCLSProcessRecordAllThreads + 184
1  FirebaseCrashlytics            0x1f2f8 FIRCLSProcessRecordAllThreads + 1176
2  FirebaseCrashlytics            0x16598 FIRCLSHandler + 48
3  FirebaseCrashlytics            0x18d58 FIRCLSMachExceptionServer + 688
4  libsystem_pthread.dylib        0x2a90 _pthread_start + 136
5  libsystem_pthread.dylib        0x1fcc thread_start + 8

com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x1af8 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x1890 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x17a8 mach_msg_overwrite + 436
3  libsystem_kernel.dylib         0x15e8 mach_msg + 24
4  CoreFoundation                 0x3601c __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x33f04 __CFRunLoopRun + 1208
6  CoreFoundation                 0x33968 CFRunLoopRunSpecific + 608
7  CFNetwork                      0x25ac48 estimatedPropertyListSize + 38228
8  Basis                     0x9ca9c __NSThread__start__ + 732
9  libsystem_pthread.dylib        0x2a90 _pthread_start + 136
10 libsystem_pthread.dylib        0x1fcc thread_start + 8

Thread
0  libsystem_kernel.dylib         0xa084 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1f6c _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1fc0 start_wqthread + 8

Crashed: ZuluCalendar
0  libswiftCore.dylib             0x4065e4 swift_isUniquelyReferenced_nonNull_native + 48
1  Basis                     0x2e75c specialised Set._Variant.insert(_:) + 204
2  Basis                     0x2e8de4 _fromNSCalendarUnits(_:) + 176
3  Basis                     0x2e410 _NSSwiftCalendar._components(_:from:) + 60
4  Basis                     0x2e274 @objc _NSSwiftCalendar._components(_:from:) + 80
5  CoreFoundation                 0xc4e08 CFCalendarDecomposeAbsoluteTime + 348
6  Safety                       0x11df64 __SecAbsoluteTimeGetGregorianDate_block_invoke + 64
7  libdispatch.dylib              0x3dd4 _dispatch_client_callout + 20
8  libdispatch.dylib              0x132c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56
9  Safety                       0xaf0c SecCFCalendarDoWithZuluCalendar + 128
10 Safety                       0x7ad4 der_encode_generalizedtime_body_repair + 232
11 Safety                       0x76ac der_encode_plist_repair + 468
12 Safety                       0x7560 der_encode_plist_repair + 136
13 Safety                       0x7560 der_encode_plist_repair + 136
14 Safety                       0x740c add_sequence_to_array + 136
15 CoreFoundation                 0x2507c -[__NSDictionaryM __apply:context:] + 128
16 Safety                       0x13b80 der_encode_dictionary_repair + 124
17 Safety                       0x740c add_sequence_to_array + 136
18 CoreFoundation                 0x2507c -[__NSDictionaryM __apply:context:] + 128
19 Safety                       0x13b80 der_encode_dictionary_repair + 124
20 Safety                       0x7560 der_encode_plist_repair + 136
21 Safety                       0x740c add_sequence_to_array + 136
22 CoreFoundation                 0x2507c -[__NSDictionaryM __apply:context:] + 128
23 Safety                       0x13b80 der_encode_dictionary_repair + 124
24 Safety                       0xcc2c CFPropertyListCreateDERData + 100
25 Safety                       0xcb78 SecTrustSerialize + 216
26 CFNetwork                      0x1ef68 _CFNetworkSetHSTSStoragePath + 93612
27 CFNetwork                      0xab3ac CFURLDownloadStart + 74768
28 CFNetwork                      0xaaedc CFURLDownloadStart + 73536
29 CFNetwork                      0xbc780 CFURLDownloadStart + 145380
30 CFNetwork                      0x1da190 CFHTTPCookieStorageUnscheduleFromRunLoop + 158916
31 CFNetwork                      0xbaa64 CFURLDownloadStart + 137928
32 libboringssl.dylib             0x3b638 __boringssl_context_evaluate_trust_async_external_block_invoke + 448
33 libdispatch.dylib              0x213c _dispatch_call_block_and_release + 32
34 libdispatch.dylib              0x3dd4 _dispatch_client_callout + 20
35 libdispatch.dylib              0xb400 _dispatch_lane_serial_drain + 748
36 libdispatch.dylib              0xbf64 _dispatch_lane_invoke + 432
37 libdispatch.dylib              0xd284 _dispatch_workloop_invoke + 1756
38 libdispatch.dylib              0x16cb4 _dispatch_root_queue_drain_deferred_wlh + 288
39 libdispatch.dylib              0x16528 _dispatch_workloop_worker_thread + 404
40 libsystem_pthread.dylib        0x1f20 _pthread_wqthread + 288
41 libsystem_pthread.dylib        0x1fc0 start_wqthread + 8

First, the code establishes a BLE connection to a selected peripheral, when he finds the suitable companies and traits, it connects to them and asks the machine to do a wifi scan. Then, the machine searches for close by wifi networks and sends the record to the app. The person selects one of many listed networks, fills the password and sends a connection request to the BLE peripheral.
Right here is the crash’s stacktrace from Crashlytics. I might wish to get some assist resolving the crash:
Pattern code of BLE Alternate supply code: (cannot present full supply code as a consequence of safety and privateness compliance) :

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments