Question

iOS 12 crash: NetworkOperation.init(configuration:) on initialization

  • 14 September 2022
  • 3 replies
  • 123 views

Badge +1

We just migrated from the old Purchases pod (version 3.13.1) to the new RevenueCat (version 4.11.0).

In didFinishLaunchingWithOptions method we are configuring RevenueCat as follows:

let purchases = Purchases.configure(
with: Configuration.Builder(withAPIKey: "???")
.with(observerMode: true)
.build()
)

let instanceID = Analytics.appInstanceID()
purchases.attribution.setFirebaseAppInstanceID(instanceID)
if instanceID == nil {
// Track error
}

Until now, 5% of our users using iOS 12/iPadOS 12 are getting this crash 


Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x204ba0 specialized _assertionFailure(_:_:file:line:flags:) + 360
1 libswiftCore.dylib 0x282bc _assertionFailure(_:_:file:line:flags:) + 32
2 libswiftFoundation.dylib 0xa3d10 @objc static NSObject.__old_unswizzled_keyPathsForValuesAffectingValue(forKey:) + 84
3 libswiftFoundation.dylib 0xa436c static __KVOKeyPathBridgeMachinery.keyPathsForValuesAffectingValue(forKey:) + 272
4 libswiftFoundation.dylib 0xa4864 @objc static __KVOKeyPathBridgeMachinery.keyPathsForValuesAffectingValue(forKey:) + 88
5 Foundation 0x9d58 -[NSKeyValueUnnestedProperty _givenPropertiesBeingInitialized:getAffectingProperties:] + 196
6 Foundation 0x9a5c -[NSKeyValueUnnestedProperty _initWithContainerClass:key:propertiesBeingInitialized:] + 148
7 Foundation 0xfcb9c NSKeyValuePropertyForIsaAndKeyPathInner.llvm.8205242823520915647 + 288
8 Foundation 0xfd374 NSKeyValuePropertyForIsaAndKeyPath + 140
9 Foundation 0xfbbe0 _NSKeyValueCreateImplicitObservationInfo + 224
10 Foundation 0x1d174 -[NSOperation init] + 372
11 MyApp 0x40c2f4 specialized NetworkOperation.init(configuration:) + 79 (NetworkOperation.swift:79)
12 MyApp 0x37d700 specialized GetOfferingsOperation.init(configuration:offeringsCallbackCache:) + 4303165184 (<compiler-generated>:4303165184)
13 MyApp 0x3a2bd8 OfferingsAPI.getOfferings(appUserID:withRandomDelay:completion:) + 4303317976 (GetOfferingsOperation.swift:4303317976)
14 MyApp 0x3d11d8 closure #1 in Purchases.updateAllCaches(completion:) + 4303507928 (<compiler-generated>:4303507928)
15 MyApp 0x40dc6c closure #1 in SystemInfo.isApplicationBackgrounded(completion:) + 126 (SystemInfo.swift:126)
16 MyApp 0x7ed38 thunk for @escaping @callee_guaranteed () -> () + 4300025144 (<compiler-generated>:4300025144)
17 libdispatch.dylib 0x5fa38 _dispatch_call_block_and_release + 24
18 libdispatch.dylib 0x607d4 _dispatch_client_callout + 16
19 libdispatch.dylib 0xe008 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068
20 CoreFoundation 0xaab20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
21 CoreFoundation 0xa5a58 __CFRunLoopRun + 1924
22 CoreFoundation 0xa4fb4 CFRunLoopRunSpecific + 436
23 GraphicsServices 0xa79c GSEventRunModal + 104
24 UIKitCore 0x8bcc38 UIApplicationMain + 212
25 MyApp 0x1b3ec main + 16 (main.m:16)
26 libdyld.dylib 0x18e0 start + 4

 

 

Please, let me know if I am doing something wrong or if I can add more useful information.

Thanks!


3 replies

Userlevel 3
Badge +8

Avoid calling the SDK config in your didFinishLaunchingWithOptions, move it late, in my case I moved it when I created the tab controller, in yours maybe your first view controller.  This will avoid other issues down the road and maybe it will fix this.

Badge +1

Thank you @imougy!

I can try that out in a following release… I think it won’t introduce any issue. Anyway, the documentation states here that you can call it in that method (in my case, the user is not indentified so there is no problem with that). That’s why I did it there.

Userlevel 3
Badge +8

Thank you @imougy!

I can try that out in a following release… I think it won’t introduce any issue. Anyway, the documentation states here that you can call it in that method (in my case, the user is not indentified so there is no problem with that). That’s why I did it there.

True about the documentation but since iOS 15, Apple made a major changed that can have major effect if you init in the ‘didFinishLaunchingWithOptions’.  Here is Apple link for details (please pay attention to the “Prepare your app for prewarming”) but take my word for it, init later to avoid random failures.

Reply