Onesignal-ios-sdk: [Crash] Several crashes in OneSignalUserDefaults.m and once.h

Created on 5 Jan 2021  路  13Comments  路  Source: OneSignal/OneSignal-iOS-SDK

Description:
I have a lot of crashes in firebase Crashlytics from OneSignal SDK.
Updating to OneSignal SDK 3.0.0 didn't help. (2.15.3 -> 2.15.4 -> 3.0.0)
The first cases were December 14th (Google down?)

Environment

  1. OneSignal SDK 3.0.0
  2. CocoaPods
  3. Xcode 12

Steps to Reproduce Issue:

  1. Open App
  2. Crash

Crashes from Firebase Crashlytics

Stack traces:
OneSignalUserDefaults.m and once.h

Stack trace 1:

Crashed: com.apple.main-thread
0  libdispatch.dylib              0x188678550 _dispatch_once_wait.cold.1 + 28
1  libdispatch.dylib              0x188645708 _dispatch_gate_broadcast_slow + 194
*2  SuperDealProd                  0x104ddb8c8 +[OSMessagingController sharedInstance] + 84 (once.h:84) <-- here
3  SuperDealProd                  0x104dd5a20 +[OneSignal receivedInAppMessageJson:] + 1853 (OneSignal.m:1853)
4  SuperDealProd                  0x104dd54bc __33+[OneSignal registerUserInternal]_block_invoke + 1820 (OneSignal.m:1820)
5  libdispatch.dylib              0x18864324c _dispatch_call_block_and_release + 32
6  libdispatch.dylib              0x188644db0 _dispatch_client_callout + 20
7  libdispatch.dylib              0x1886527ac _dispatch_main_queue_callback_4CF + 836
8  CoreFoundation                 0x1889cc11c **CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE**
9  CoreFoundation                 0x1889c6120 __CFRunLoopRun + 2508
10 CoreFoundation                 0x1889c521c CFRunLoopRunSpecific + 600
11 SuperDealProd                  0x104be0eac GAIUncaughtExceptionHandler + 69 (GAIUncaughtExceptionHandler.m:69)
12 CoreFoundation                 0x188a50b80 __handleUncaughtException + 632
13 libobjc.A.dylib                0x19cfa6f58 _objc_terminate() + 132
14 libc++abi.dylib                0x19d0ac0e0 std::__terminate(void (*)()) + 20
15 libc++abi.dylib                0x19d0ac06c std::terminate() + 44
16 libobjc.A.dylib                0x19cfa6ed4 _objc_terminate() + 14
17 libdispatch.dylib              0x188644dc4 _dispatch_client_callout + 40
18 libdispatch.dylib              0x1886465c8 _dispatch_once_callout + 32
19 SuperDealProd                  0x104ddb8c8 +[OSMessagingController sharedInstance] + 84 (once.h:84)
20 SuperDealProd                  0x104dd5a60 +[OneSignal receivedInAppMessageJson:] + 1858 (OneSignal.m:1858)
21 SuperDealProd                  0x104e043cc +[OneSignalTracker applicationForegrounded] + 122 (OneSignalTracker.m:122)
22 SuperDealProd                  0x104df99e4 -[OneSignalLifecycleObserver didBecomeActive] + 86 (OneSignalLifecycleObserver.m:86)
23 CoreFoundation                 0x1889ad9a0 **CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER** + 28
24 CoreFoundation                 0x1889ad948 ___CFXRegistrationPost_block_invoke + 52
25 CoreFoundation                 0x1889aceb0 _CFXRegistrationPost + 440
26 CoreFoundation                 0x1889ac870 _CFXNotificationPost + 716
27 Foundation                     0x189c704bc -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
28 UIKitCore                      0x18b3f9180 -[UIApplication _stopDeactivatingForReason:] + 1496
29 UIKitCore                      0x18aa5a5b0 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke_2 + 112
30 UIKitCore                      0x18afc7404 _UIScenePerformActionsWithLifecycleActionMask + 112
31 UIKitCore                      0x18aa5a4a8 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 224
32 UIKitCore                      0x18aa59f68 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 484
33 UIKitCore                      0x18aa5a2b8 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 768
34 UIKitCore                      0x18aa59af4 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 340
35 UIKitCore                      0x18aa62040 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 196
36 UIKitCore                      0x18aed4030 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 892
37 UIKitCore                      0x18afdfb2c _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 272
38 UIKitCore                      0x18aa61d38 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 384
39 UIKitCore                      0x18a889bb4 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 776
40 UIKitCore                      0x18a888528 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 256
41 UIKitCore                      0x18a8897dc -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 248
42 UIKitCore                      0x18b4001a4 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 572
43 UIKitCore                      0x18aefd85c -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 388
44 FrontBoardServices             0x197d5947c -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 432
45 FrontBoardServices             0x197d84dc4 __94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke.200 + 128
46 FrontBoardServices             0x197d68560 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240
47 FrontBoardServices             0x197d84a88 __94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke + 372
48 libdispatch.dylib              0x188644db0 _dispatch_client_callout + 20
49 libdispatch.dylib              0x188648738 _dispatch_block_invoke_direct + 268
50 FrontBoardServices             0x197dad310 **FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK** + 48
51 FrontBoardServices             0x197dacfa0 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 448
52 FrontBoardServices             0x197dad4f4 -[FBSSerialQueue _performNextFromRunLoopSource] + 32
53 CoreFoundation                 0x1889cc76c **CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION** + 28
54 CoreFoundation                 0x1889cc668 __CFRunLoopDoSource0 + 208
55 CoreFoundation                 0x1889cb960 __CFRunLoopDoSources0 + 268
56 CoreFoundation                 0x1889c5a8c __CFRunLoopRun + 824
57 CoreFoundation                 0x1889c521c CFRunLoopRunSpecific + 600
58 GraphicsServices               0x19fa44784 GSEventRunModal + 164
59 UIKitCore                      0x18b3fe200 -[UIApplication _run] + 1072
60 UIKitCore                      0x18b403a74 UIApplicationMain + 168
61 SuperDealProd                  0x1049321a8 main + 23 (main.swift:23)
62 libdyld.dylib                  0x1886856c0 start + 4

Reason: Crashed: com.apple.main-thread
EXC_BREAKPOINT 0x000000019594dc70
keyboard_arrow_up

Keys: crash_info_entry_0
BUG IN CLIENT OF LIBDISPATCH: trying to lock recursively

Stack trace 2:

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x1ab8b8878 __exceptionPreprocess
1  libobjc.A.dylib                0x1bfe0ec50 objc_exception_throw
2  CoreFoundation                 0x1ab7bf95c -[NSOrderedSet initWithSet:copyItems:]
3  CoreFoundation                 0x1ab8bb444 **_forwarding_**
4  CoreFoundation                 0x1ab8bd740 _CF_forwarding_prep_0
5  Foundation                     0x1acae2cc8 -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]
6  Foundation                     0x1acb2fff4 -[NSKeyedUnarchiver initForReadingWithData:]
7  Foundation                     0x1acb30618 +[NSKeyedUnarchiver unarchiveObjectWithData:]
*8  SuperDealProd                  0x100f49260 -[OneSignalUserDefaults getSavedCodeableDataForKey:defaultValue:] + 154 (OneSignalUserDefaults.m:154) <-- here
9  SuperDealProd                  0x100f13ca4 -[OSMessagingController init] + 142 (OSMessagingController.m:142)
10 SuperDealProd                  0x100f1390c __39+[OSMessagingController sharedInstance]_block_invoke + 92 (OSMessagingController.m:92)
11 libdispatch.dylib              0x1ab4acdb0 _dispatch_client_callout
12 libdispatch.dylib              0x1ab4ae5c8 _dispatch_once_callout
13 SuperDealProd                  0x100f138c8 +[OSMessagingController sharedInstance] + 84 (once.h:84)
14 SuperDealProd                  0x100f0da20 +[OneSignal receivedInAppMessageJson:] + 1853 (OneSignal.m:1853)
15 SuperDealProd                  0x100f0d4bc __33+[OneSignal registerUserInternal]_block_invoke + 1820 (OneSignal.m:1820)
16 libdispatch.dylib              0x1ab4ab24c _dispatch_call_block_and_release
17 libdispatch.dylib              0x1ab4acdb0 _dispatch_client_callout
18 libdispatch.dylib              0x1ab4ba7ac _dispatch_main_queue_callback_4CF
19 CoreFoundation                 0x1ab83411c **CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE**
20 CoreFoundation                 0x1ab82e120 __CFRunLoopRun
21 CoreFoundation                 0x1ab82d21c CFRunLoopRunSpecific
22 GraphicsServices               0x1c28ac784 GSEventRunModal
23 UIKitCore                      0x1ae266200 -[UIApplication _run]
24 UIKitCore                      0x1ae26ba74 UIApplicationMain
25 SuperDealProd                  0x100a6a1a8 main + 23 (main.swift:23)
26 libdyld.dylib                  0x1ab4ed6c0 start

Reason: Fatal Exception: NSInvalidArgumentException
-[__NSDictionary0 bytes]: unrecognized selector sent to instance 0x20715e9e0
keyboard_arrow_up

Stack trace 3:

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x1a856586c __exceptionPreprocess
1  libobjc.A.dylib                0x1bd4d4c50 objc_exception_throw
2  CoreFoundation                 0x1a85d5e1c -[__NSCFString characterAtIndex:].cold.1
3  CoreFoundation                 0x1a852f7c4 _CFPrefsValidateValueForKey
4  CoreFoundation                 0x1a852fea0 createDeepCopyOfValueForKey
5  CoreFoundation                 0x1a852fb88 -[CFPrefsSource setValues:forKeys:count:copyValues:removeValuesForKeys:count:from:]
6  CoreFoundation                 0x1a8530000 -[CFPrefsSource setValues:forKeys:count:copyValues:from:]
7  CoreFoundation                 0x1a8446b2c -[CFPrefsSource setValue:forKey:from:]
8  CoreFoundation                 0x1a85c16e0 __76-[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:]_block_invoke
9  CoreFoundation                 0x1a8584178 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke
10 CoreFoundation                 0x1a8583720 normalizeQuintuplet
11 CoreFoundation                 0x1a8583fbc -[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:]
12 CoreFoundation                 0x1a8446580 -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:]
13 CoreFoundation                 0x1a85c4dd8 _CFPreferencesSetAppValueWithContainerAndConfiguration
14 Foundation                     0x1a97c3f6c -[NSUserDefaults(NSUserDefaults) setObject:forKey:]
*15 SuperDealProd                  0x104e2cff4 -[OneSignalUserDefaults saveDictionaryForKey:withValue:] + 136 (OneSignalUserDefaults.m:136) <-- here
16 SuperDealProd                  0x104df858c -[OSMessagingController deleteOldRedisplayedInAppMessages] + 203 (OSMessagingController.m:203)
17 SuperDealProd                  0x104df1a3c +[OneSignal receivedInAppMessageJson:] + 1853 (OneSignal.m:1853)
18 SuperDealProd                  0x104df14bc __33+[OneSignal registerUserInternal]_block_invoke + 1820 (OneSignal.m:1820)
19 libdispatch.dylib              0x1a815824c _dispatch_call_block_and_release
20 libdispatch.dylib              0x1a8159db0 _dispatch_client_callout
21 libdispatch.dylib              0x1a81677ac _dispatch_main_queue_callback_4CF
22 CoreFoundation                 0x1a84e111c **CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE**
23 CoreFoundation                 0x1a84db120 __CFRunLoopRun
24 CoreFoundation                 0x1a84da21c CFRunLoopRunSpecific
25 GraphicsServices               0x1bffde784 GSEventRunModal
26 UIKitCore                      0x1aaf18fe0 -[UIApplication _run]
27 UIKitCore                      0x1aaf1e854 UIApplicationMain
28 SuperDealProd                  0x10494e1a8 main + 23 (main.swift:23)
29 libdyld.dylib                  0x1a819a6b0 start

Reason:
Fatal Exception: NSInvalidArgumentException
Attempt to insert non-property list object { "f54eeab8-1205-4ba9-801f-faa76e0e15fc" = "OSInAppMessage: \nmessageId: f54eeab8-1205-4ba9-801f-faa76e0e15fc \ntriggers: (\n) \ndisplayed_in_session: NO \ndisplayStats: OSInAppMessageDisplayStats: redisplayEnabled: NO \nlastDisplayTime: 1594294586.690239 \ndisplayDelay: 0.000000 \ndisplayQuantity: 3 \ndisplayLimit: 2147483647"; } for key OS_IAM_REDISPLAY_DICTIONARY

Low Priority Possible Bug

All 13 comments

Updating to 3.1.0 didn't help

Podfile:

use_frameworks!
inhibit_all_warnings!

platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'

def common_pods
    pod 'FBSDKLoginKit'
    pod 'FBSDKShareKit'
    pod 'FacebookCore'
    pod 'FacebookSDK'

    pod 'GoogleSignIn'
    pod 'GoogleAnalytics'
    pod 'myTrackerSDK', '~> 2.0.3'
    pod 'Cluster'
    pod 'IQKeyboardManagerSwift'

    pod 'Firebase/Analytics'
    pod 'AlamofireImage'
    pod 'AlamofireNetworkActivityIndicator'
    pod 'SDWebImage', '~> 4.0'
    pod 'TTTAttributedLabel', '~> 2.0'
    pod 'BadgeSwift'
    pod 'HFSwipeView', :git => 'https://github.com/NikitaSkripchenko/HFSwipeView', :commit => '9fbf335262cbf3b212ce622591c81b1c84325910'
    pod 'ImageSlideshow', '~> 1.8.3'
    pod 'MBProgressHUD', '~> 1.0.0'
    pod 'Gifu'
    pod 'Cosmos'


    pod 'lottie-ios'
    pod 'CardIO', '~> 5.4'
    pod 'BKMoneyKit', '~> 0.0.11'
    pod 'JSQMessagesViewController'
    pod 'INSPhotoGallery'
    pod 'AssetsPickerViewController', '~> 2'
    pod 'Branch', :git => 'https://github.com/BranchMetrics/ios-branch-deep-linking-attribution', :branch => 'staging'
    pod 'SwiftEntryKit', '1.0.1'
end

def prod_pods
    pod 'OneSignal'
    pod 'Firebase/Crashlytics'
end

def shared_pods
    pod 'Alamofire' 
    pod 'ZXingObjC', '~> 3.6.4'
end 

post_install do |installer|
 installer.pods_project.targets.each do |target|
     target.build_configurations.each do |config|
         config.build_settings['SWIFT_VERSION'] = '5.2.2'
     end
 end
end


target 'AppProd' do
    common_pods
    prod_pods
    shared_pods
end

target 'AppStaging' do
    common_pods
    prod_pods
    shared_pods
end

target 'AppWatchCouponsExtension' do
    platform :watchos,  '4.0'
    pod 'EFQRCode/watchOS', '5.1.6'
    pod 'Alamofire' 
end

target 'AppTests' do
    common_pods
    shared_pods
end

target 'OneSignalNotificationServiceExtension' do
  #only copy below line
  pod 'OneSignal'
end

Hey @emawby @rgomezp any thoughts on this?

Howdy,
We are investigating this issue.

Fatal Exception: NSInvalidArgumentException
Attempt to insert non-property list object 
{ "f54eeab8-1205-4ba9-801f-faa76e0e15fc" = "OSInAppMessage: \nmessageId: f54eeab8-1205-4ba9-801f-faa76e0e15fc \ntriggers: (\n) \ndisplayed_in_session: NO \ndisplayStats: OSInAppMessageDisplayStats: redisplayEnabled: NO \nlastDisplayTime: 1594294586.690239 \ndisplayDelay: 0.000000 \ndisplayQuantity: 3 \ndisplayLimit: 2147483647"; } for key OS_IAM_REDISPLAY_DICTIONARY

Appears to be coming from here.

Thank you for your patience.

Hi @rgomezp
Thanks for your reply

I managed to get a device that catches a crash. [1, 2 case]
I have enabled the logs that OneSignal outputs
The error depends on the following lines of code:

OneSignal.initWithLaunchOptions (launchOptions)
OneSignal.setAppId (oneSignalAppId)

If I remove them, then no error occurs
Error:
-[__NSDictionary0 bytes]: unrecognized selector sent to instance 0x1fca2adc0

Log:
device log.txt

I removed some of OneSignal's UserDefaults at first launch after updating app.
And it works!

fileprivate func cleanOneSignalDefaults() {
        let userDefaultskeys = ["OS_IAM_MESSAGES_ARRAY", "OS_IAM_SEEN_SET", "OS_IAM_CLICKED_SET", "OS_IAM_IMPRESSIONED_SET", "OS_IAM_REDISPLAY_DICTIONARY"]
        for key in userDefaultskeys {
            UserDefaults.standard.removeObject(forKey: key)
        }
    }

Hi Mark,
Yep. It looks like we're trying to insert a non-property list object (a custom object) into the UserDefaults, which is prohibited. This looks like a bug from first glance.

I'll have our iOS lead take a look and reply directly. Thanks for your cooperation.

Hi @rgomezp Any update on this issue because I'm facing same crashes in firebase crashlytics from OneSignal SDK.
I'm using OneSignal SDK 2.16.1, the crashes I'm getting mostly on iOS 14.3.

@pranjali420 Hi!
You can try to remove the values from "OS_IAM_REDISPLAY_DICTIONARY"(UserDefaults) before OneSignal initialization.
It needs to be done only 1 time.
It works for me 馃槑

I removed some of OneSignal's UserDefaults at first launch after updating app.
And it works!

fileprivate func cleanOneSignalDefaults() {
        let userDefaultskeys = ["OS_IAM_MESSAGES_ARRAY", "OS_IAM_SEEN_SET", "OS_IAM_CLICKED_SET", "OS_IAM_IMPRESSIONED_SET", "OS_IAM_REDISPLAY_DICTIONARY"]
        for key in userDefaultskeys {
            UserDefaults.standard.removeObject(forKey: key)
        }
    }

@ToMark1881 could you elaborate where you made that edit? I'm struggling to figure out what I need to change.

@bfarrgaynor in AppDelegate.swift
Before (!) OneSignal initialization

Howdy,
Unfortunately no update yet. Thanks for your patience.

Was this page helpful?
0 / 5 - 0 ratings