pendo-io / pendo-mobile-sdk

Pendo captures product usage data, gathers user feedback, and lets you communicate in-app to onboard, educate, and guide users to value
https://www.pendo.io
Other
57 stars 2 forks source link

Can't install Pendo SwiftUI beta #19

Closed Pigpocket closed 1 year ago

Pigpocket commented 1 year ago

I'm getting a consistent crash with the following when trying to run the beta with the branch set to swiftui:

  Referenced from: '/private/var/containers/Bundle/Application/1C03E581-27EE-4273-A06F-D68519681216/Workspaces.app/Frameworks/Pendo.framework/Pendo'
  Reason: tried: '/usr/lib/system/introspection/libswiftCore.dylib' (no such file), '/private/var/containers/Bundle/Application/1C03E581-27EE-4273-A06F-D68519681216/Workspaces.app/Frameworks/libswiftCore.dylib' (no such file), '/private/var/containers/Bundle/Application/1C03E581-27EE-4273-A06F-D68519681216/Workspaces.app/Frameworks/libswiftCore.dylib' (no such file), '/usr/local/lib/libswiftCore.dylib' (no such file), '/usr/lib/libswiftCore.dylib' (no such file)
Library not loaded: '@rpath/libswiftCore.dylib'
  Referenced from: '/private/var/containers/Bundle/Application/1C03E581-27EE-4273-A06F-D68519681216/Workspaces.app/Frameworks/Pendo.framework/Pendo'
  Reason: tried: '/usr/lib/system/introspection/libswiftCore.dylib' (no such file), '/private/var/containers/Bundle/Application/1C03E581-27EE-4273-A06F-D68519681216/Workspaces.app/Frameworks/libswiftCore.dylib' (no such file), '/private/var/containers/Bundle/Application/1C03E581-27EE-4273-A06F-D68519681216/Workspaces.app/Frameworks/libswiftCore.dylib' (no such file), '/usr/local/lib/libswiftCore.dylib' (no such file), '/usr/lib/libswiftCore.dylib' (no such file)

Also, in our non-beta implementation, we are calling this init method in the .onOpenUrl method:

PendoManager.shared().initWith(url)

According to the docs for SwiftUI in your package, it should be replaced with the below? Xcode autocompletes the optional version of application, but if I remove the question mark, it views the open parameter as an extra argument, so we wouldn’t be able to pass in the url. The below throws an error:

.onOpenURL { url in
    if url.absoluteString.contains(Constants.pendo) {
        appDelegate.application?(UIApplication.shared, open: url)
    } else {
        viewStore.send(.didOpenURL(url))
    }
}

To sort that out, I tried calling that function in my AppDelegate, so now my AppDelegate looks like this:


class AppDelegate: NSObject, UIApplicationDelegate {

    enum Constants {
        static let pendoAppKey = "PENDO_APP_KEY"
    }

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

            if !UITestsSupport.isRunningUITests,
               let pendoAppKey = ProcessInfo.processInfo.environment[Constants.pendoAppKey] {
                PendoManager.shared().setup(pendoAppKey)
            }
            return true
    }

    func application(_ app: UIApplication,
                     open url: URL,
                     options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        return true
    }
}

This is how the SPM is set up in our `Package Dependencies`:
![image](https://user-images.githubusercontent.com/23366254/199858459-8877e062-32ee-431c-8b6a-fa1feb0f4756.png)

I'm running Xcode 14.0, with a minimum target of iOS 15.0, deploying to an iPad Pro (12.9-inch) (3rd generation) running 15.6.1. 
MikePendo commented 1 year ago

The current implementation is still considered as open beta

  1. Regarding the crash at run time, it will be fixed in the next release and merged to official SDK, for current work around could you add @executable_path/Frameworks, @loader_path/Frameworks, /usr/lib/swift/ to your RunPath
  2. I would advice to use the the old AppDelegate approach stand alone with @UIApplicationMain(as you might need it in future for other implementation like push notifications etc). The below suggestion about Appdelegate make sense only if your app entry point is (@main) start from swiftUI app. Pay attention to @UIApplicationDelegateAdaptor the func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool should be visible
Pigpocket commented 1 year ago

That did it, thanks, no more crash.

Our app is fully SwiftUI. So to be clear, we should have:

_ = appDelegate.application(UIApplication.shared, open: url)

in our .onOpenURL method and the AppDelegate configured as I have above, yes? I.e. no longer using PendoManager.shared().initWith(url)

MikePendo commented 1 year ago

ok if its fully swiftui UI, your app entry point should have @main on SwiftUI struct. In that case u still should have Appdelegete . In the entry point struct u must have @UIApplicationDelegateAdaptor like: @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate (please look at the example in the integration part here). and then appDelegate.application(UIApplication.shared, open: url, options: [:]) should work. (if It doesnt Iet me know I will look at it again maybe Apple has changed something). Dont forget to call the setup api with your key prior to pairing or doing something.

MikePendo commented 1 year ago

@Pigpocket I am closing the issue