question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🐛 [Banner Ad] 'Fatal Exception: NSInvalidArgumentException' in iOS

See original GitHub issue

Bug report

Describe the bug The iOS (Swift) app crashes randomly, but often, when banners are loaded with the error:

Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

Stack Trace

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x1a4b33180 __exceptionPreprocess
1  libobjc.A.dylib                0x1a3d0b9f8 objc_exception_throw
2  CoreFoundation                 0x1a4aacbec _CFArgv
3  CoreFoundation                 0x1a4a34898 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]
4  CoreFoundation                 0x1a4a25474 +[NSDictionary dictionaryWithObjects:forKeys:count:]
5  Runner                         0x1012cff2c -[FLTAdInstanceManager onAdLoaded:] + 82 (FLTAdInstanceManager_Internal.m:82)
6  Runner                         0x1012ce174 -[FLTBannerAd adViewDidReceiveAd:] + 150 (FLTAd_Internal.m:150)
7  Runner                         0x1011d4824 GAD_GADBannerView_arm64_7_69_0
8  Runner                         0x10122a058 __copy_helper_block_e8_32s40s48s56s64b72w
9  Runner                         0x10122a114 __copy_helper_block_e8_32s40s48s56s64b72w
10 Runner                         0x101229d08 GAD_GADInternalBannerView_arm64_7_69_0
11 Runner                         0x1012298d0 GAD_GADInternalBannerView_arm64_7_69_0
12 Runner                         0x101229f80 GAD_GADInternalBannerView_arm64_7_69_0
13 libdispatch.dylib              0x1a4570a38 _dispatch_call_block_and_release
14 libdispatch.dylib              0x1a45717d4 _dispatch_client_callout
15 libdispatch.dylib              0x1a451f008 _dispatch_main_queue_callback_4CF$VARIANT$mp
16 CoreFoundation                 0x1a4ac4b20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
17 CoreFoundation                 0x1a4abfa58 __CFRunLoopRun
18 CoreFoundation                 0x1a4abefb4 CFRunLoopRunSpecific
19 GraphicsServices               0x1a6cc079c GSEventRunModal
20 UIKitCore                      0x1d1320c38 UIApplicationMain
21 Runner                         0x100fb37d8 main + 6 (AppDelegate.swift:6)
22 libdyld.dylib                  0x1a45828e0 start

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a Flutter project (Swift).
  2. Insert an inline banner as described in the codelabs (in a ListView).
  3. The error will appear randomly.

Expected behavior

The app should not crash.


Additional context

I have not been able to reproduce the error continuously but many of my users have encountered it as I can see from the crashlytics logs.

I have mediation with MoPub, Facebook Audience Network and AdColony configured but the error also occurs if I pause it.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[✓] Flutter (Channel stable, 2.0.3, on Mac OS X 10.15.7 19H2 darwin-x64, locale it-IT)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.54.3)
[✓] Connected device (3 available)

• No issues found!

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
Dart SDK 2.12.2
Flutter SDK 2.0.3

dependencies:
- admob_consent 1.1.2 [flutter]
- apple_sign_in 0.1.0 [flutter]
- async 2.5.0 [collection]
- auto_size_text 2.1.0 [flutter]
- cached_network_image 3.0.0-nullsafety [flutter flutter_cache_manager octo_image]
- camera 0.8.0 [flutter camera_platform_interface pedantic quiver]
- carousel_slider 3.0.0 [flutter]
- circular_check_box 1.0.4 [flutter]
- cloud_firestore 1.0.2 [cloud_firestore_platform_interface cloud_firestore_web firebase_core firebase_core_platform_interface flutter meta]
- connectivity_widget 0.1.7 [flutter rxdart connectivity stream_disposable http]
- cupertino_icons 1.0.2
- dio 4.0.0-prev3 [http_parser path]
- easy_debounce 1.0.2 [flutter]
- equatable 2.0.0 [collection meta]
- expandable 5.0.1 [flutter]
- extended_image 3.0.0 [extended_image_library flutter meta]
- firebase_analytics 7.1.1 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta]
- firebase_auth 1.0.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.0.2 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 1.0.0 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_messaging 9.0.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_storage 8.0.0 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flag 5.0.0-nullsafety [flutter flutter_svg]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_facebook_auth 3.1.1 [flutter flutter_facebook_auth_platform_interface flutter_facebook_auth_web]
- flutter_image_compress 0.7.0 [flutter]
- flutter_localizations 0.0.0 [flutter intl characters clock collection meta path typed_data vector_math]
- flutter_rating_bar 4.0.0 [flutter]
- flutter_signin_button 2.0.0-nullsafety.0 [flutter font_awesome_flutter]
- font_awesome_flutter 9.0.0 [flutter]
- get 3.26.0 [flutter]
- google_fonts 2.0.0 [flutter http path_provider crypto]
- google_mobile_ads 0.11.0+4 [meta flutter]
- google_sign_in 5.0.1 [google_sign_in_platform_interface google_sign_in_web flutter meta]
- http 0.13.1 [http_parser meta path pedantic]
- image 3.0.2 [archive meta xml]
- image_editor 1.0.0 [flutter]
- image_gallery_saver 1.6.8 [flutter]
- image_picker 0.7.3 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface image_picker_for_web]
- in_app_review 2.0.1 [flutter in_app_review_platform_interface]
- intl 0.17.0 [clock path]
- intl_utils 2.1.0 [analyzer archive args http intl path petitparser yaml]
- introduction_screen 2.0.0 [flutter dots_indicator]
- isolate 2.0.3
- lottie 1.0.1 [archive characters charcode collection flutter logging meta path vector_math]
- matrix4_transform 2.0.0 [flutter]
- modal_bottom_sheet 2.0.0 [flutter]
- native_shared_preferences 1.0.5 [flutter meta]
- ndialog 4.0.1 [flutter]
- ntp 1.0.8 [universal_io]
- package_info 2.0.0 [flutter]
- page_view_indicators 2.0.0 [flutter]
- path_drawing 0.5.0-nullsafety.0 [vector_math meta path_parsing flutter]
- path_provider 2.0.1 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- permission_handler 6.1.1 [flutter meta permission_handler_platform_interface]
- photo_view 0.11.1 [flutter]
- provider 5.0.0 [collection flutter nested]
- purchases_flutter 3.1.0 [flutter collection]
- rxdart 0.26.0
- screenshot 0.3.0 [flutter]
- share_plus 2.0.0 [meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web]
- shared_preferences 2.0.5 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- svg_path_parser 1.0.0 [string_scanner flutter]
- syncfusion_flutter_charts 18.4.49 [flutter intl vector_math syncfusion_flutter_core]
- timeago 3.0.2
- trotter 1.2.0
- url_launcher 6.0.2 [flutter url_launcher_platform_interface url_launcher_linux url_launcher_macos url_launcher_windows url_launcher_web]
- video_player 2.0.2 [meta video_player_platform_interface video_player_web flutter flutter_test]

transitive dependencies:
- _fe_analyzer_shared 19.0.0 [meta]
- analyzer 1.3.0 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml pedantic]
- archive 3.1.2 [crypto path]
- args 2.0.0
- boolean_selector 2.1.0 [source_span string_scanner]
- camera_platform_interface 2.0.1 [flutter meta plugin_platform_interface cross_file stream_transform]
- characters 1.1.0
- charcode 1.2.0
- cli_util 0.3.0 [meta path]
- clock 1.1.0
- cloud_firestore_platform_interface 4.0.0 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 1.0.2 [cloud_firestore_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.15.0
- connectivity 3.0.3 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web]
- connectivity_for_web 0.4.0 [connectivity_platform_interface flutter_web_plugins flutter]
- connectivity_macos 0.2.0 [flutter]
- connectivity_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- convert 3.0.0 [typed_data]
- cross_file 0.3.1+1 [flutter meta]
- crypto 3.0.0 [collection typed_data]
- dots_indicator 2.0.0 [flutter]
- extended_image_library 2.0.2 [crypto flutter http_client_helper path path_provider]
- fake_async 1.2.0 [clock collection]
- ffi 1.0.0
- file 6.1.0 [meta path]
- firebase 9.0.1 [http http_parser js]
- firebase_analytics_platform_interface 1.1.0 [flutter meta]
- firebase_analytics_web 0.2.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta]
- firebase_auth_platform_interface 4.0.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 1.0.3 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.0.0 [flutter meta plugin_platform_interface]
- firebase_core_web 1.0.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics_platform_interface 2.0.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 2.0.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 1.0.2 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_storage_platform_interface 2.0.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 1.0.2 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- flutter_blurhash 0.5.4-nullsafety.0 [flutter meta pedantic]
- flutter_cache_manager 3.0.0-nullsafety.2 [clock collection file flutter http image path path_provider pedantic rxdart sqflite uuid]
- flutter_facebook_auth_platform_interface 2.1.1 [flutter plugin_platform_interface]
- flutter_facebook_auth_web 2.1.1 [flutter flutter_web_plugins js flutter_facebook_auth_platform_interface]
- flutter_plugin_android_lifecycle 2.0.0 [flutter]
- flutter_svg 0.21.0-nullsafety.0 [flutter meta path_drawing vector_math xml]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- glob 2.0.0 [async collection file path pedantic string_scanner]
- google_sign_in_platform_interface 2.0.1 [flutter meta quiver]
- google_sign_in_web 0.10.0 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
- http_client_helper 2.0.2 [http]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image_picker_for_web 2.0.0 [image_picker_platform_interface meta flutter flutter_web_plugins]
- image_picker_platform_interface 2.0.1 [flutter meta http plugin_platform_interface]
- in_app_review_platform_interface 2.0.2 [flutter url_launcher plugin_platform_interface platform]
- js 0.6.3
- logging 1.0.0
- matcher 0.12.10 [stack_trace]
- meta 1.3.0
- mime 1.0.0
- nested 1.0.0 [flutter]
- octo_image 1.0.0-nullsafety.1 [flutter flutter_blurhash]
- package_config 2.0.0 [path]
- path 1.8.0
- path_parsing 0.2.0-nullsafety.0 [vector_math meta]
- path_provider_linux 2.0.0 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 2.0.0 [flutter]
- path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface]
- path_provider_windows 2.0.0 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.11.0
- permission_handler_platform_interface 3.1.1 [flutter meta plugin_platform_interface]
- petitparser 4.0.2 [meta]
- platform 3.0.0
- plugin_platform_interface 2.0.0 [meta]
- process 4.2.0 [file path platform]
- pub_semver 2.0.0 [collection]
- quiver 3.0.0 [matcher]
- share_plus_linux 2.0.0 [share_plus_platform_interface file flutter meta url_launcher]
- share_plus_macos 2.0.0 [share_plus_platform_interface flutter]
- share_plus_platform_interface 2.0.0 [flutter meta mime plugin_platform_interface]
- share_plus_web 2.0.0 [share_plus_platform_interface url_launcher flutter flutter_web_plugins meta]
- share_plus_windows 2.0.0 [share_plus_platform_interface flutter meta url_launcher]
- shared_preferences_linux 2.0.0 [flutter file meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 2.0.0 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.0 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 2.0.0 [shared_preferences_platform_interface flutter file meta path path_provider_platform_interface path_provider_windows]
- sky_engine 0.0.99
- source_span 1.8.0 [charcode collection path term_glyph]
- sqflite 2.0.0+3 [flutter sqflite_common path]
- sqflite_common 2.0.0+2 [synchronized path meta]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_disposable 0.1.0 [flutter]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- syncfusion_flutter_core 18.4.49 [flutter]
- synchronized 3.0.0
- term_glyph 1.2.0
- test_api 0.2.19 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0 [collection]
- universal_io 1.0.1 [meta zone_local]
- url_launcher_linux 2.0.0 [flutter]
- url_launcher_macos 2.0.0 [flutter]
- url_launcher_platform_interface 2.0.2 [flutter plugin_platform_interface]
- url_launcher_web 2.0.0 [url_launcher_platform_interface meta flutter flutter_web_plugins]
- url_launcher_windows 2.0.0 [flutter]
- uuid 3.0.2 [crypto]
- vector_math 2.1.0
- video_player_platform_interface 4.0.0 [flutter meta flutter_test]
- video_player_web 2.0.0 [flutter flutter_web_plugins meta video_player_platform_interface]
- watcher 1.0.0 [async path pedantic]
- win32 2.0.4 [ffi]
- xdg_directories 0.2.0 [meta path process]
- xml 5.0.2 [collection meta petitparser]
- yaml 3.1.0 [collection source_span string_scanner]
- zone_local 0.1.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:13
  • Comments:25

github_iconTop GitHub Comments

7reactions
numen31337commented, Apr 7, 2021

Crashes here as adIdFor might return nil:

- (void)onAdFailedToLoad:(id<FLTAd> _Nonnull)ad error:(FLTLoadAdError *_Nonnull)error {
  [_channel invokeMethod:@"onAdEvent"
               arguments:@{
                 @"adId" : [self adIdFor:ad],  //<=== Crash
                 @"eventName" : @"onAdFailedToLoad",
                 @"loadAdError" : error
               }];
}

adIdFor implementation:

- (NSNumber *_Nullable)adIdFor:(id<FLTAd> _Nonnull)ad {
  NSArray<NSNumber *> *keys = [_ads allKeysForObject:ad];

  if (keys.count > 1) {
    NSLog(@"%@Error: Multiple keys for a single ad.",
          NSStringFromClass([FLTAdInstanceManager class]));
  }

  if (keys.count > 0) {
    return keys[0];
  }

  return nil; //<=== This will crash dictionary creation
}
5reactions
ThrowJojocommented, May 29, 2021

Someone has been assigned to this issue now so I think it will be fixed sometime soon 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fatal Exception: NSInvalidArgument… - Apple Developer
Crash log Fatal Exception: NSInvalidArgumentException 0 CoreFoundation ... Open a bug report with a focused sample that reproduces the issue on iOS 15....
Read more >
Crash when running app after banner ad integration
Hi everyone,. Just to clarify, the error message seems to indicate that Luke was using an unknown class ADBannerView in Interface Builder file...
Read more >
iOS crash after using Unity Ads 2019.2.12f1
A fatal crash? I'm leaving the banner out as it doesn't always display even and rolling an app out when I know it...
Read more >
iOS app error - Can't add self as subview - Stack Overflow
I received this crash report, but I don't know how to debug it. Fatal Exception ...
Read more >
Troubleshooting - Helpshift for iOS
Fatal error : Unexpectedly found nil while unwrapping an Optional ... Terminating app due to uncaught exception NSInvalidArgumentException, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found