sefidgaran / salesforce-marketing-cloud

Salesforce Marketing Cloud MobilePush Flutter SDK
https://pub.dev/packages/sfmc_plugin
MIT License
6 stars 21 forks source link

Crash during splash screen on some iOS devices #18

Open ifelsebreak opened 7 months ago

ifelsebreak commented 7 months ago

We implemented the sfmc_plugin and it looked like everything was working fine, however, after distributing our app through TestFlight for further testing we found out the app crashes on the splash screen on some devices. It happens randomly on specific devices so it's hard to reproduce.

The crash log seems to suggest the problem is caused by the sfmc_plugin

Incident Identifier: --- Hardware Model: iPhone13,1 Process: Runner [4646] Path: /private/var/containers/Bundle/Application/****/Runner.app/Runner Identifier: ***** Version: * AppStoreTools: 15C5500a AppVariant: 1:iPhone13,1:17 Beta: YES Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: ***** [908]

Date/Time: 2024-01-16 15:16:58.5795 +0100 Launch Time: 2024-01-16 15:15:39.6044 +0100 OS Version: iPhone OS 17.2.1 (21C66) Release Type: User Baseband Version: 4.20.05 Report Version: 104

Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Reason: * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]** Termination Reason: SIGNAL 6 Abort trap: 6 Terminating Process: Runner [4646]

Triggered by Thread: 0

Last Exception Backtrace: 0 CoreFoundation 0x19127269c exceptionPreprocess + 164 (NSException.m:249) 1 libobjc.A.dylib 0x18952fc80 objc_exception_throw + 60 (objc-exception.mm:356) 2 CoreFoundation 0x1911dc23c -[NSPlaceholderDictionary initWithObjects:forKeys:count:] + 728 (NSPlaceholderDictionary.m:0) 3 CoreFoundation 0x1911dbb60 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 52 (NSDictionary.m:614) 4 SFMCSDK 0x1017f125c +[SFMCKeychainItemWrapper updateKeychainAccessibleAttribute] + 1108 (SFMCKeychainItemWrapper.m:229) 5 SFMCSDK 0x1017f0de8 +[SFMCKeychainItemWrapper setAccessibleAttribute:] + 168 (SFMCKeychainItemWrapper.m:186) 6 sfmc_plugin 0x101dcfad4 specialized SwiftSfmcPlugin.setupSFMC(appId:accessToken:mid:sfmcURL:delayRegistration:analytics:onDone:) + 676 (SwiftSfmcPlugin.swift:181) 7 sfmcplugin 0x101dd2574 specialized SwiftSfmcPlugin**.handle(:result:) + 1756 (SwiftSfmcPlugin.swift:39) 8 sfmc_plugin 0x101dcf800 specialized SwiftSfmcPlugin.handle(_:result:) + 16 (:0) 9 sfmc_plugin 0x101dcf800 @objc SwiftSfmcPlugin.handle(_:result:) + 84 10 Flutter 0x104781e28 45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 172 (FlutterChannels.mm:268) 11 Flutter 0x1041ef5a4 + -1 (platform_message_handler_ios.mm:73) 12 libdispatch.dylib 0x1991776a8 _dispatch_call_block_and_release + 32 (init.c:1530) 13 libdispatch.dylib 0x199179300 _dispatch_client_callout + 20 (object.m:561) 14 libdispatch.dylib 0x199187998 _dispatch_main_queue_drain + 984 (queue.c:7813) 15 libdispatch.dylib 0x1991875b0 _dispatch_main_queue_callback_4CF + 44 (queue.c:7973) 16 CoreFoundation 0x1911bd01c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 16 (CFRunLoop.c:1780) 17 CoreFoundation 0x1911b9d28 CFRunLoopRun + 1996 (CFRunLoop.c:3149) 18 CoreFoundation 0x1911b9478 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420) 19 GraphicsServices 0x1d47124f8 GSEventRunModal + 164 (GSEvent.c:2196) 20 UIKitCore 0x1935dd62c -[UIApplication _run] + 888 (UIApplication.m:3685) 21 UIKitCore 0x1935dcc68 UIApplicationMain + 340 (UIApplication.m:5270) 22 Runner 0x1007e4694 main + 80 (main.m:7) 23 dyld 0x1b3ededcc start + 2240 (dyldMain.cpp:1269)

ifelsebreak commented 7 months ago

We were able to fix the crash by editing the SwiftSfmcPlugin.swift located in _sfmcplugin > ios > Classes.

We had to comment line 184:

//        To override the Keycahin accessibility attribute

//        SFMCSdk.setKeychainAccessibleAttribute(accessibleAttribute: kSecAttrAccessibleWhenUnlockedThisDeviceOnly)

I think they deprecated this mode since version 8.1.* of the SDK

BuildtTech commented 6 months ago

@sefidgaran Any idea of resolving this issue definitely?

sefidgaran commented 6 months ago

Thanks for the report I will update after my investigation results.

sefidgaran commented 6 months ago

Hi @ifelsebreak

I could not reproduce this reported issue but I can bring items below into your attention:

1- The crash log mentions SFMCKeychainItemWrapper, which suggests that the issue might be related to keychain access. iOS apps can face issues with keychain access, especially if there are changes in app entitlements, app groups, or if the app is being run in a different environment (like TestFlight). Review your app's keychain access settings and ensure they align with what the SFMC SDK expects.

2- This kind of issue often arises from incorrect or incomplete initialization parameters being passed to the SDK, or it might be due to a race condition where the SDK is being accessed before it's fully initialized or in a state that it doesn't expect. Make sure that all the parameters required for initializing the Salesforce Marketing Cloud SDK via sfmc_plugin are correct and non-nil. This includes appId, accessToken, mid, sfmcURL, and any other configuration parameters you're passing during the setup.

Also it's good to learn more from SFMC iOS SDK: Keychain crash

Regards, Farshid