Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aravasio opened this issue Jun 26, 2024 · 1 comment

Comments

@aravasio
Copy link

aravasio commented Jun 26, 2024

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.

@akashvercetti
Copy link
Collaborator

@aravasio We have a sample app setup with notifications service and content extensions setup in our react native repo. Could you please try comparing its implementation with yours and checking it is different from yours?

Here is the sample app: https://github.com/CleverTap/clevertap-react-native/tree/master/Example/ios
Podfile: https://github.com/CleverTap/clevertap-react-native/blob/master/Example/ios/Podfile
Notification Service Extension: https://github.com/CleverTap/clevertap-react-native/tree/master/Example/ios/NotificationServiceSwift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants