capacitor-community / intercom

Enable Intercom for Capacitor apps
https://capacitorjs.com/docs
MIT License
59 stars 77 forks source link

Type 'Intercom' has no member XXX #96

Open brennanbatalla opened 1 year ago

brennanbatalla commented 1 year ago

Describe the bug After upgrading this plugin to 5.0.0 my ios package fails to build.

Shows three errors:

Expected behavior The package builds correctly

Screenshots

Screenshot 2023-10-04 at 12 56 54 PM
GavrilF commented 1 year ago

I'm having the exact same issue! Any progress ?

brennanbatalla commented 1 year ago

Not yet, trying everything in the book. If you find a solution, please post it here. I will do the same.

Update: Tried downgrading back and I cannot get rid of this issue now, even in the older versions 🤯

nseb commented 1 year ago

The Intercom SDK was changed , you need for the moment change the controller swift

stwalez commented 1 year ago

The Intercom SDK was changed, you need for the moment change the controller swift

@nseb How and where should the controller swift be changed?

stwalez commented 1 year ago

Downgrading Intercom dependency seems to be a good hack. You'd have to modify _nodemodules...CapacitorCommunityIntercom.podspec for this.

s.dependency 'Intercom', '<= 15.2.3'

Hopefully a better solution is presented.

nseb commented 1 year ago

Here my code :

Import Foundation import Capacitor import Intercom

/**

if DEBUG

    Intercom.enableLogging()

endif

    NotificationCenter.default.addObserver(self, selector: #selector(self.didRegisterWithToken(notification:)), name: Notification.Name.capacitorDidRegisterForRemoteNotifications, object: nil)
}

@objc func didRegisterWithToken(notification: NSNotification) {
    guard let deviceToken = notification.object as? Data else {
        return
    }
    Intercom.setDeviceToken(deviceToken)
}

@objc func loadWithKeys(_ call: CAPPluginCall) {
    let appId = call.getString("appId")  as? String ?? "NO_APP_ID_PASSED"
    let apiKey = call.getString("apiKeyIOS") as? String ?? "NO_API_KEY_PASSED"

    Intercom.setApiKey(apiKey, forAppId: appId)

    NotificationCenter.default.addObserver(self, selector: #selector(self.didRegisterWithToken(notification:)), name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: nil)
}

@objc func registerIdentifiedUser(_ call: CAPPluginCall) {
    let userId = call.getString("userId")
    let email = call.getString("email")
    let attributes = ICMUserAttributes()

    if ((email) != nil) {
        attributes.email = email
        Intercom.loginUser(with: attributes) { result in
            switch result {
            case .success: call.resolve()
            case .failure(let error): call.reject("Error logging in: \(error.localizedDescription)")
            }
        }
    }

    if ((userId) != nil) {
        attributes.userId = userId
        Intercom.loginUser(with: attributes) { result in
            switch result {
            case .success: call.resolve()
            case .failure(let error): call.reject("Error logging in: \(error.localizedDescription)")
            }
        }
    }
}

@objc func registerUnidentifiedUser(_ call: CAPPluginCall) {
    Intercom.loginUnidentifiedUser()
    call.resolve()
}

@objc func updateUser(_ call: CAPPluginCall) {
    let userAttributes = ICMUserAttributes()
    let userId = call.getString("userId")
    if (userId != nil) {
        userAttributes.userId = userId
    }
    let email = call.getString("email")
    if (email != nil) {
        userAttributes.email = email
    }
    let name = call.getString("name")
    if (name != nil) {
        userAttributes.name = name
    }
    let phone = call.getString("phone")
    if (phone != nil) {
        userAttributes.phone = phone
    }
    let languageOverride = call.getString("languageOverride")
    if (languageOverride != nil) {
        userAttributes.languageOverride = languageOverride
    }
    let customAttributes = call.getObject("customAttributes")
    userAttributes.customAttributes = customAttributes
    Intercom.updateUser(with: userAttributes)
    call.resolve()
}

@objc func logout(_ call: CAPPluginCall) {
    Intercom.logout()
    call.resolve()
}

@objc func logEvent(_ call: CAPPluginCall) {
    let eventName = call.getString("name")
    let metaData = call.getObject("data")

    if (eventName != nil && metaData != nil) {
        Intercom.logEvent(withName: eventName!, metaData: metaData!)

    }else if (eventName != nil) {
        Intercom.logEvent(withName: eventName!)
    }

    call.resolve()
}

@objc func displayMessenger(_ call: CAPPluginCall) {
    Intercom.present();
    call.resolve()
}

@objc func displayMessageComposer(_ call: CAPPluginCall) {
    guard let initialMessage = call.getString("message") else {
        call.reject("Enter an initial message")
        return
    }
    Intercom.presentMessageComposer(initialMessage);
    call.resolve()
}

@objc func displayHelpCenter(_ call: CAPPluginCall) {
    Intercom.present(.helpCenter)
    call.resolve()
}

@objc func hideMessenger(_ call: CAPPluginCall) {
    Intercom.hide()
    call.resolve()
}

@objc func displayLauncher(_ call: CAPPluginCall) {
    Intercom.setLauncherVisible(true)
    call.resolve()
}

@objc func hideLauncher(_ call: CAPPluginCall) {
    Intercom.setLauncherVisible(false)
    call.resolve()
}

@objc func displayInAppMessages(_ call: CAPPluginCall) {
    Intercom.setInAppMessagesVisible(true)
    call.resolve()
}

@objc func hideInAppMessages(_ call: CAPPluginCall) {
    Intercom.setInAppMessagesVisible(false)
    call.resolve()
}

@objc func displayCarousel(_ call: CAPPluginCall) {
    if let carouselId = call.getString("carouselId") {
        Intercom.presentContent(.carousel(id:carouselId))
        call.resolve()
    }else{
        call.reject("carouselId not provided to displayCarousel.")
    }
}

@objc func setUserHash(_ call: CAPPluginCall) {
    let hmac = call.getString("hmac")

    if (hmac != nil) {
        Intercom.setUserHash(hmac!)
        call.resolve()
        print("hmac sent to intercom")
    }else{
        call.reject("No hmac found. Read intercom docs and generate it.")
    }
}

@objc func setBottomPadding(_ call: CAPPluginCall) {

    if let value = call.getString("value"),
       let number = NumberFormatter().number(from: value) {

        Intercom.setBottomPadding(CGFloat(truncating: number))
        call.resolve()
        print("set bottom padding")
    } else {
        call.reject("Enter a value for padding bottom")
    }
}

@objc func displayArticle(_ call: CAPPluginCall) {
    if let articleId = call.getString("articleId") {
        Intercom.presentContent(.article(id:articleId))
        call.resolve()
    } else {
        call.reject("articleId not provided to presentArticle.")
    }
}

}

maylorsan commented 1 year ago

Same issue when building via Ionic Appflow, any updates?

nseb commented 1 year ago

@maylorsan my code above work this code with the latest Intercom sdk IOS

maylorsan commented 1 year ago

Hello @nseb,

Thank you for sharing your solution! However, directly modifying the source files of installed libraries isn't a viable long-term solution for our use case due to our continuous deployment setup with Ionic Appflow.

Can you contribute your solution directly to this plugin?

maylorsan commented 1 year ago

Observations:

Hypothesis:

It seems plausible that the error in question occurs when building with a version of Xcode that is older than 15. Could this be the root cause of the build failure issues we're observing?

ArtBoguslavskiy commented 1 year ago

I'm on Xcode 15, encountering the same issue. It appears to be contingent on the pod version. When I updated to 1.13.0, I ran into this problem.

maylorsan commented 1 year ago

@ArtBoguslavskiy I and my team have pod 1.13.0 locally, and everything works well, but with pod 1.12.1 in Ionic Appflow, the build fails.

nseb commented 1 year ago

For your information , I use XCode 15

ArtBoguslavskiy commented 1 year ago

I'm using Ionic in conjunction with the Capacitor plugin @capacitor-community/intercom v5.0.0. Initially, after I reinstalled the plugin, the build process was successful. However, on the second build attempt, it crashed.

Upon inspecting the PodFile, I noticed that the Intercom version specified was 16.0.3. When I downgraded it to version 15.2.3, as suggested by @stwalez, the build succeeded. However, I observed that in Xcode, many of the methods appeared to be deprecated. This appears to be a potential issue, and I suspect that the problem may be related to the usage of new methods introduced in version 16 of Intercom.

juandl commented 1 year ago

Please update "Podfile" under ios/App/Podfile

target 'App' do
  capacitor_pods

  #Downgrade intercom due to issues with latest version
  pod 'Intercom', '<= 15.2.3'
  # Add your Pods here
end

this should help to avoid "hardcoding"

maylorsan commented 1 year ago

@juandl works for me!Thank you ❤️

choffmeyer commented 1 year ago

@juandl you are Awesome !!!! where do i send the check !!!!

hopefully a new version of this component will be released to lock down the version or support the latests. this actually causes historical code and builds to break .. even though no code changes were made. not good.

brennanbatalla commented 1 year ago

Solution worked for me! Thanks! It was a major blocker.

brennanbatalla commented 1 year ago

Anyone using AppFlow and now their buid is failing after fixing the above issue:

image

supermario commented 1 year ago

@brennanbatalla I resolved the issue by ensuring the pod actually got updated given for me it was stuck with the wrong version in the existing Podfile.lock:

cd ios/App
rm Podfile.lock
pod install

Do gem install cocoapods if you don't have it globally.

jbird84 commented 8 months ago

In the latest build (version: 16.5.8) this presenter has been renamed to Intercom.present()

nitinw631 commented 6 months ago

Any update on this? Intercom is not working on IOS

Screenshot 2024-04-22 at 6 22 25 PM