ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web āš”ļø
https://capacitorjs.com
MIT License
11.8k stars 993 forks source link

bug: Push Notification causing AppFlow Failure #4570

Closed beckyhilton closed 3 years ago

beckyhilton commented 3 years ago

Bug Report

Capacitor Version

šŸ’Š   Capacitor Doctor  šŸ’Š 

Latest Dependencies:

  @capacitor/cli: 2.4.7
  @capacitor/core: 2.4.7
  @capacitor/android: 2.4.7
  @capacitor/electron: 2.4.7
  @capacitor/ios: 2.4.7

Installed Dependencies:

  @capacitor/cli 2.4.7
  @capacitor/core 2.4.7
  @capacitor/ios 2.4.7
  @capacitor/android 2.4.7
  @capacitor/electron not installed

[success] Android looking great! šŸ‘Œ
  Found 6 Capacitor plugins for ios:
    @capacitor-community/firebase-analytics (0.3.0)
    @capacitor-community/native-market (0.1.4)
    call-number (1.0.1)
    cordova-plugin-androidx (2.0.0)
    cordova-plugin-androidx-adapter (1.1.3)
    phonegap-plugin-barcodescanner (8.1.0)
[success] iOS looking great! šŸ‘Œ

Platform(s)

iOS

Current Behavior

Build failure in App Flow

ios/App/App/AppDelegate.swift:67:7: cannot find 'InstanceID' in scope

      InstanceID.instanceID().instanceID { (result, error) in
                                                            ^~~~~~~~~~~~

Expected Behavior

Successful App Flow Build

Code Reproduction

I believe this is related to the code provided on this page https://capacitorjs.com/docs/guides/push-notifications-firebase

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
        InstanceID.instanceID().instanceID { (result, error) in
            if let error = error {
                NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidFailToRegisterForRemoteNotificationsWithError.name()), object: error)
            } else if let result = result {
                NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: result.token)
            }
        }
    }

Other Technical Details

npm --version output: 7.6.0

node --version output: v12.19.0

pod --version output (iOS issues only): 1.9.3

Additional Context

In XCode I see this error message

'InstanceID' is deprecated: FIRInstanceID is deprecated, please use FIRInstallations for installation identifier handling and use FIRMessaging for FCM registration token handling.

And in the firebase release notes I saw this "The deprecated Firebase InstanceID has been removed. Use Firebase Installations to manage app instance and use Firebase Messaging to manage FCM registration token instead" which I thought might be the cause

https://firebase.google.com/support/release-notes/ios

beckyhilton commented 3 years ago

I think this might be a partial solution but my swift isn't very good so its not handling the error like the other one was.

NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: Messaging.token(completion:))
samvimes01 commented 3 years ago

It fails even on import FirebaseInstanceID I assume it happened after the Firebase core was upgraded to v8 and some deprecated items were removed. As a temporary fix, versions of the firebase core and messaging could be hardcoded to the latest that was working without errors (7.11.0) ios/App/Podfile:

target 'App' do
  capacitor_pods
  # Add your Pods here
  pod 'FirebaseCore', '7.11.0' // add the version explicitly
  pod 'Firebase/Messaging', '7.11.0'
end
SyFlo commented 3 years ago

same problem here. any solutions in sight?

beckyhilton commented 3 years ago

@SyFlo switching to the v7.11.0 seems to be working for me for now as a work around.

SyFlo commented 3 years ago

@beckyhilton yes, I'm also using v7.11.0 as a workaround now

jcesarmobile commented 3 years ago

If you are using capacitor 2, we recommend fixing the FirebaseCore and Firebase/Messaging versions to 7.11.0

  pod 'FirebaseCore', '7.11.0'
  pod 'Firebase/Messaging', '7.11.0'

If using capacitor 3, follow this guide https://capacitorjs.com/docs/guides/push-notifications-firebase

If you want to use FirebaseCore and Firebase/Messaging 8, you can still check the capacitor 3 guide, but note that the capacitor notifications to send the token/error to the js side changed the name, so you need to use the old names instead of the names on that guide

beckyhilton commented 3 years ago

@jcesarmobile Thanks!

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.