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

bug: can't retrieve fcm_token on iOS devices #738

Open
5 of 17 tasks
Excel1 opened this issue Oct 18, 2024 · 2 comments
Open
5 of 17 tasks

bug: can't retrieve fcm_token on iOS devices #738

Excel1 opened this issue Oct 18, 2024 · 2 comments

Comments

@Excel1
Copy link

Excel1 commented Oct 18, 2024

Plugin(s)

  • Analytics
  • App
  • App Check
  • Authentication
  • Crashlytics
  • Cloud Firestore
  • Cloud Functions
  • Cloud Messaging
  • Cloud Storage
  • Performance
  • Remote Config

Version

6.0.0

Platform(s)

  • Android
  • iOS
  • Web

Current behavior

I start the App and got warnings like:

objc[66371]: Class _TtC20FirebaseCoreInternal16HeartbeatStorage is implemented in both /Users/MAC/Library/Developer/CoreSimulator/Devices/8D98A354-2473-4486-8BF5-3493D3481439/data/Containers/Bundle/Application/85026241-D4ED-40B3-A36E-68A924BD6BE8/App.app/Frameworks/FirebaseCoreInternal.framework/FirebaseCoreInternal (0x105c716c8) and /Users/MAC/Library/Developer/CoreSimulator/Devices/8D98A354-2473-4486-8BF5-3493D3481439/data/Containers/Bundle/Application/85026241-D4ED-40B3-A36E-68A924BD6BE8/App.app/App.debug.dylib (0x10652d310). One of the two will be used. Which one is undefined.

Then the biggest Problem appears:

10.29.0 - [FirebaseCore][I-COR000003] The default Firebase app has not yet been configured. Add `FirebaseApp.configure()` to your application initialization. This can be done in in the App Delegate's application(_:didFinishLaunchingWithOptions:)` (or the `@main` struct's initializer in SwiftUI). Read more: https://goo.gl/ctyzm8.

Expected behavior

No warnings, no errors and receiving the dcm_token to send push notifications to my iOS device like it works on android.

Reproduction

https://reproductionexampleisfollowing.com

Steps to reproduce

  1. Init a Quasar (quasar.dev / vue) project.
  2. Implement Capacitor-Firebase Plugin (following the docs)
  3. Build and run the App on IOS Device --> Error

(Android works perfectly)

Other information

IOS 16 Pro (18.0.1)

// PodFile
require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'

platform :ios, '13.0'
use_frameworks!

# workaround to avoid Xcode caching of Pods that requires
# Product -> Clean Build Folder after new Cordova plugins installed
# Requires CocoaPods 1.6 or newer
install! 'cocoapods', :disable_input_output_paths => true

def capacitor_pods
  pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
  pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
  pod 'CapacitorCommunityAdmob', :path => '../../node_modules/@capacitor-community/admob'
  pod 'CapacitorFirebaseMessaging', :path => '../../node_modules/@capacitor-firebase/messaging'
  pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
  pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
  pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network'
  pod 'CapacitorPreferences', :path => '../../node_modules/@capacitor/preferences'
  pod 'CapacitorNativeSettings', :path => '../../node_modules/capacitor-native-settings'
end

target 'App' do
  capacitor_pods
  # Add your Pods here
  pod 'FirebaseMessaging'
end

post_install do |installer|
  assertDeploymentTarget(installer)
end

{
  ...
  "private": true,
  "scripts": {
    "lint": "eslint --ext .js,.ts,.vue ./",
    "format": "prettier --write \"**/*.{js,ts,vue,scss,html,md,json}\" --ignore-path .gitignore",
    "test": "echo \"No test specified\" && exit 0",
    "dev": "quasar dev",
    "build": "quasar build"
  },
  "dependencies": {
    "@capacitor-community/admob": "^6.0.0",
    "@capacitor-firebase/messaging": "^6.0.0",
    "@capacitor/app": "^6.0.0",
    "@capacitor/device": "^6.0.0",
    "@capacitor/network": "^6.0.1",
    "@capacitor/preferences": "^6.0.1",
    "@paypal/paypal-js": "^8.0.5",
    "@quasar/extras": "^1.16.12",
    "axios": "^1.2.1",
    "capacitor-native-settings": "^6.0.0",
    "firebase": "^10.12.3",
    "keycloak-js": "^22.0.5",
    "oidc-client-ts": "2.4.0",
    "pinia": "^2.0.11",
    "pinia-plugin-persistedstate": "^3.2.1",
    "quasar": "^2.14.2",
    "vue": "^3.4.32",
    "vue-advanced-cropper": "^2.8.8",
    "vue-i18n": "^9.2.2",
    "vue-router": "^4.2.5",
    "vue-writer": "^2.0.2"
  },
  "devDependencies": {
    "@intlify/vite-plugin-vue-i18n": "^3.3.1",
    "@quasar/app-vite": "^1.9.3",
    "@types/node": "^12.20.21",
    "@types/vue-writer": "^1.2.0",
    "@typescript-eslint/eslint-plugin": "^5.10.0",
    "@typescript-eslint/parser": "^5.10.0",
    "autoprefixer": "^10.4.2",
    "eslint": "^8.10.0",
    "eslint-config-prettier": "^8.1.0",
    "eslint-plugin-vue": "^9.0.0",
    "prettier": "^2.5.1",
    "typescript": "^4.5.4"
  },
  "engines": {
    "node": "^18 || ^16 || ^14.19",
    "npm": ">= 6.13.4",
    "yarn": ">= 1.21.1"
  }
}

// capacitor package.json
{
  ...
  "private": true,
  "dependencies": {
    "@capacitor-community/admob": "^6.0.0",
    "@capacitor-firebase/messaging": "^6.0.0",
    "@capacitor/android": "^6.1.0",
    "@capacitor/app": "^6.0.0",
    "@capacitor/cli": "^6.1.0",
    "@capacitor/core": "^6.1.0",
    "@capacitor/device": "^6.0.0",
    "@capacitor/ios": "^6.1.2",
    "@capacitor/network": "^6.0.1",
    "@capacitor/preferences": "^6.0.1",
    "capacitor-native-settings": "^6.0.0",
    "firebase": "^10.12.3"
  }
}
//infoplist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleDisplayName</key>
	<string>XXXXXXXX</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>$(MARKETING_VERSION)</string>
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLName</key>
			<string>XXXXXXXX</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>XXXXXXX</string>
			</array>
		</dict>
	</array>
	<key>CFBundleVersion</key>
	<string>$(CURRENT_PROJECT_VERSION)</string>
	<key>GADApplicationIdentifier</key>
	<string>ca-app-pub-XXXXXXXX</string>
	<key>GADIsAdManagerApp</key>
	<true/>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>NSUserTrackingUsageDescription</key>
	<string>[Why you use NSUserTracking. ex: This identifier will be used to deliver personalized ads to you.]</string>
	<key>SKAdNetworkItems</key>
	<array>
		<dict>
			<key>SKAdNetworkIdentifier</key>
			<string>cstr6suwn9.skadnetwork</string>
		</dict>
	</array>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen.storyboard</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>armv7</string>
	</array>
	<key>UIRequiresFullScreen</key>
	<true/>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UIViewControllerBasedStatusBarAppearance</key>
	<true/>
	<key>GADIsAdManagerApp</key>
  <true/>
  <key>GADApplicationIdentifier</key>
  <string>ca-app-pub-XXXXXX</string>
  <key>SKAdNetworkItems</key>
  <array>
    <dict>
      <key>SKAdNetworkIdentifier</key>
      <string>cstr6suwn9.skadnetwork</string>
    </dict>
  </array>
  <key>NSUserTrackingUsageDescription</key>
  <string>[Why you use NSUserTracking. ex: This identifier will be used to deliver personalized ads to you.]</string>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsLocalNetworking</key>
    <true/>
</dict>
</dict>
</plist>

AppDelegate
import UIKit
import Capacitor
import FirebaseCore
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        return true
    }
  
  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().apnsToken = deviceToken
    print(deviceToken)
    Messaging.messaging().token(completion: { (token, error) in
      if let error = error {
          NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
      } else if let token = token {
          NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
      }
    })
  }

  func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
  }
  
  func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
      NotificationCenter.default.post(name: Notification.Name.init("didReceiveRemoteNotification"), object: completionHandler, userInfo: userInfo)
  }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        // Called when the app was launched with a url. Feel free to add additional processing here,
        // but if you want the App API to support tracking app url opens, make sure to keep this call
        return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
    }

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        // Called when the app was launched with an activity, including Universal Links.
        // Feel free to add additional processing here, but if you want the App API to support
        // tracking app url opens, make sure to keep this call
        return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler)
    }

}

Before asked: I imported my google info by using Xcode.

Capacitor doctor

(I don't used ionic)

Operating System - Darwin(24.0.0) - darwin/arm64
NodeJs - 18.18.2

Global packages
NPM - 9.8.1
yarn - Not installed
@quasar/cli - undefined
@quasar/icongenie - 4.0.0
cordova - Not installed

Important local packages
quasar - 2.17.0 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
@quasar/app-vite - 1.10.0 -- Quasar Framework App CLI with Vite
@quasar/extras - 1.16.12 -- Quasar Framework fonts, icons and animations
eslint-plugin-quasar - Not installed
vue - 3.5.11 -- The progressive JavaScript framework for building modern web UI.
vue-router - 4.4.5
pinia - 2.2.4 -- Intuitive, type safe and flexible Store for Vue
vuex - Not installed
vite - 2.9.18 -- Native-ESM powered web dev build tool
eslint - 8.57.1 -- An AST-based pattern checker for JavaScript.
electron - Not installed
electron-packager - Not installed
@electron/packager - Not installed
electron-builder - Not installed
register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
@capacitor/core - 6.1.0 -- Capacitor: Cross-platform apps with JavaScript and the web
@capacitor/cli - 6.1.0 -- Capacitor: Cross-platform apps with JavaScript and the web
@capacitor/android - 6.1.0 -- Capacitor: Cross-platform apps with JavaScript and the web
@capacitor/ios - 6.1.2 -- Capacitor: Cross-platform apps with JavaScript and the web

Quasar App Extensions
None installed

Networking
Host - MacBookPro.fritz.box
en0 - 192.168.179.3

Before submitting

  • I have read and followed the bug report guidelines.
  • I have attached links to possibly related issues and discussions.
  • I understand that incomplete issues (e.g. without reproduction) are closed.
@Excel1 Excel1 added bug/fix Something isn't working needs: triage labels Oct 18, 2024
@Excel1 Excel1 changed the title bug: can't retrieve fem_token on iOS devices bug: can't retrieve fcm_token on iOS devices Oct 18, 2024
Copy link
Contributor

This issue has been labeled as needs: reproduction. This label is added to issues that need a code reproduction.

Please provide a Minimal, Reproducible Example using this template in a public GitHub repository so we can debug the issue.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for us to reproduce the issue.

@Excel1
Copy link
Author

Excel1 commented Oct 18, 2024

As a supplement:
I don't know if the duplicate warning affects the Firebase configuration but it looks like....
It looks like it might have something to do with this:
firebase/firebase-ios-sdk#12540
CocoaPods/CocoaPods#10989
PS: In one or two weeks I will try to implement a reproduction repo, but it will not contain Googe-info.plist (for privacy reasons)

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

No branches or pull requests

2 participants