customerio / customerio-ios

Official Customer.io SDK for iOS. Track customers and send messages to your iOS app.
https://customer.io/docs/sdk/ios/
MIT License
28 stars 17 forks source link

MessagingInApp initialisation leading to crash #200

Closed alpha-sagar closed 2 years ago

alpha-sagar commented 2 years ago

Hello , Added Inapp messaging SDK via cocoa pods like , pod 'CustomerIO/Tracking','~> 1.2.0-beta.1' pod 'CustomerIO/MessagingPushAPN','~> 1.2.0-beta.1' pod 'CustomerIOMessagingInApp','~> 1.2.0-beta.1'

And Initialise in AppDelegate like , let customerIO = CustomerIO( siteId: customerSiteID , apiKey: customerAPIKey , region: Region.US) customerIO.config { $0.autoTrackDeviceAttributes = true $0.autoTrackPushEvents = true $0.logLevel = .debug $0.autoTrackScreenViews = true } MessagingInApp.shared.initialize(organizationId: customerOrgnizationID)

But when we try to run the app , its leading to crash on SDK File Name - MessagingInApp.swift private var diGraph: DIGraph { return diGraphOverride ?? DIGraph.getInstance(siteId: siteId) } Here SiteId coming nil , still its set on above CustomerIO instance.

ami-aman commented 2 years ago

Hi @alpha-sagar To help troubleshoot the issue, I would need to look at the logs. Would it be possible to submit the query to win@customer.io with the logs so that myself or someone from our team can investigate on this? Also, please add this issue's link in the query, so that we can map the ticket easily !

alpha-sagar commented 2 years ago

Okay 👍🏼

ami-aman commented 2 years ago

Hi @alpha-sagar Thanks for submitting the query. I wanted to let you know that we're working on it and will be back with a solution soon.

ami-aman commented 2 years ago

Hi @alpha-sagar On investigating further, we found that you are creating your own instance of CustomerIO's SDK and using shared instance to initialise MessagingInApp module. This is the reason that the in-app module is not able to find siteId which it returns a nil value, hence crashing.

We want to let you know that MessagingInApp uses shared instance only and we would suggest you to use the singleton instance of CustomerIO SDK to initialize the all modules and use functions of the SDK !

Apologies, as this is not mentioned in the docs and I would make sure to add this point so that you or any of our customers do not face this issue again in the future. Also, to keep you informed, we might deprecate the functionality to create own instances of the SDK in the future.

Please, let me know if this solution works for you !

alpha-sagar commented 2 years ago

Hi @ami-aman , Removed our own singleton class and write manually in AppDelegate still its leading to crash. Screenshot 2022-10-06 at 7 30 01 PM Screenshot 2022-10-06 at 7 29 35 PM

ami-aman commented 2 years ago

Hi @alpha-sagar As per the screenshot you just shared, it looks like you are still creating own instance and not using the singleton shared instance.

Would you try this and let us know if it works for you ?

CustomerIO.initialize(siteId: customerSiteID, apiKey: customerAPIKey, region: Region.US)
CustomerIO.config {
        $0.autoTrackDeviceAttributes = true
        $0.autoTrackPushEvents = true
        $0.logLevel = .debug
        $0.autoTrackScreenViews = true
 }
MessagingInApp.shared.initialize(organizationId: customerOrgnizationID)
alpha-sagar commented 2 years ago

Hooray !!! Its Worked ! Thank you so much.