clevertap-ios-sdk icon indicating copy to clipboard operation
clevertap-ios-sdk copied to clipboard

CleverTapSDK dyld crash on NotificationService extension when importing CleverTapSDK and receiving a PushNotification

Open aravasio opened this issue 8 months ago • 1 comments

Describe the bug Context: React Native. Issue: I'm trying to implement Push Impressions on the iOS platform by adding a new Notification Service Extension to the project and the application crashes (probably) when it tries to dynamically load the CleverTapSDK on runtime.

To Reproduce I can successfully setup a simple NSE and put a breakpoint on it that stops when the device receives a Push Notification and prints some message. The problem, however, arises when I try to use CleverTap code in it. When following the Push Impressions guide, it's indicated that the necessary code to implement it on iOS is:

import CleverTapSDK // This import is not specified in the documentation, but my understanding is that it's necessary to acces the `CleverTap` namespace.

class NotificationService: UNNotificationServiceExtension {
  var contentHandler: ((UNNotificationContent) -> Void)?
  var bestAttemptContent: UNMutableNotificationContent?
  
  override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    CleverTap.sharedInstance()?.recordNotificationViewedEvent(withData: request.content.userInfo)
    super.didReceive(request, withContentHandler: contentHandler)
  }
  
  override func serviceExtensionTimeWillExpire() {
    if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
      contentHandler(bestAttemptContent)
    }
  }
}

However, when trying to include the necessary import (import CleverTapSDK), after adding it to the podfile like so:

target 'NotificationServiceExtension' do
  use_frameworks! :linkage => :dynamic
  pod 'CleverTap-iOS-SDK'
  #pod 'clevertap-react-native', :path => '../node_modules/clevertap-react-native'
end

(I have also tried without :linkage => :dynamic, or using clevertap-react-native ... to no success, either)

I start getting application crashes when I receive a Push on the device, and the NSE launches:

dyld[8764]: Library not loaded: @rpath/CleverTapSDK.framework/CleverTapSDK
  Referenced from: <43C0D5B0-B598-3B09-8910-7E84ECC63AEA> /private/var/containers/Bundle/Application/D66E599F-EC8B-42E7-8A46-3A39CD4AE0C9/mobileapp.app/PlugIns/NotificationServiceExtension.appex/NotificationServiceExtension
  Reason: tried: '/usr/lib/swift/CleverTapSDK.framework/CleverTapSDK' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/CleverTapSDK.framework/CleverTapSDK' (no such file), '/private/var/containers/Bundle/Application/D66E599F-EC8B-42E7-8A46-3A39CD4AE0C9/mobileapp.app/PlugIns/NotificationServiceExtension.appex/Frameworks/CleverTapSDK.framework/CleverTapSDK' (no such file), '/private/var/containers/Bundle/Application/D66E599F-EC8B-42E7-8A46-3A39CD4AE0C9/mobileapp.app/PlugIns/NotificationServiceExtension.appex/Frameworks/CleverTapSDK.framework/CleverTapSDK' (no such file), '/private/var/containers/Bundle/Application/D66E599F-EC8B-42E7-8A46-3A39CD4AE0C9/mobileapp.app/Frameworks/CleverTapSDK.framework/CleverTapSDK' (no such file), '/usr/lib/swift/CleverTapSDK.framework/CleverTapSDK' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/CleverTapSDK.framework/CleverTapSDK' (no such file), '/private/var/containers/Bundle/Application/D66E599F-EC8B-42E7-8A46-3A39CD4AE0C9/mobileapp.app/PlugIns/NotificationServiceExtension.appex/Frameworks/CleverTapSDK.framework/CleverTapSDK' (no such file), '/private/var/containers/Bundle/Application/D66E599F-EC8B-42E7-8A46-3A39CD4AE0C9/mobileapp.app/PlugIns/NotificationServiceExtension.appex/Frameworks/CleverTapSDK.framework/CleverTapSDK' (no such file), '/private/var/containers/Bundle/Application/D66E599F-EC8B-42E7-8A46-3A39CD4AE0C9/mobileapp.app/Frameworks/CleverTapSDK.framework/CleverTapSDK' (no such file)

Expected behaviour A received Push Notification would trigger the NSE and it will call didReceiveRequest successfully, allowing us to track impressions.

Screenshots Pictured: The crash itself. Screenshot 2024-06-26 at 16 42 09

Environment (please complete the following information):

  • Xcode version: Version 15.4 (15F31d)
  • CleverTap SDK Version: CleverTap-iOS-SDK (6.2.1) / clevertap-react-native (2.2.1)
  • Device: iPhone 8+
  • OS: iOS 16.7.8

Possible Solution I'm not 100% sure. Maybe if linking / setting up the SDK in the NSR requires extra steps, document them?

Additional Info This seems to only stop crashing when I comment the pod 'CleverTap-iOS-SDK' and remove import / code from the NSE. Just adding the pod on the NSE target seems to be reason for the crash.

aravasio avatar Jun 26 '24 19:06 aravasio