You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS Swift4集成Firebase推送崩溃:GCM_SENDER_ID不可为空

Fixing Firebase InstanceID Crash: "GCM_SENDER_ID must not be nil or empty"

Hey there, let's work through this frustrating crash you're hitting. Your app was working fine with Firebase push notifications, then suddenly started throwing this error—super annoying, right? The root issue is clearly that Firebase InstanceID can't find a valid GCM_SENDER_ID, so let's go through the most common fixes step by step:

  • Double-check your GoogleService-Info.plist
    First, confirm this file is still in your project and correctly linked. Sometimes after Pod updates or project cleanups, it can get accidentally removed or unlinked.

    • Make sure the file has a GCM_SENDER_ID field with the correct value (you can grab this from your Firebase project's settings page).
    • Verify the Target Membership for the file is checked for your main app target (select the file, look in the right-hand inspector pane).
  • Verify Firebase initialization order
    In your AppDelegate's didFinishLaunchingWithOptions method, ensure you're initializing Firebase before setting up push notifications. The order matters here—InstanceID needs Firebase to be configured first to pull the Sender ID. Your code should look something like this:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Initialize Firebase first
        FirebaseApp.configure()
        
        // Then set up user notifications and Firebase Messaging
        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
            // Handle authorization result
        }
        application.registerForRemoteNotifications()
        
        Messaging.messaging().delegate = self
        return true
    }
    
  • Clean and reinstall your Pods
    Since you mentioned deleting some content already, let's do a full Pod reset to rule out cached issues:

    pod deintegrate
    pod clean
    rm Podfile.lock
    pod install
    

    This removes old Pod artifacts and pulls fresh copies of Firebase dependencies, which often fixes configuration mismatches.

  • Check Other Linker Flags in Build Settings
    Firebase relies on the -ObjC linker flag to properly load its components. Head to your target's Build Settings > Other Linker Flags and make sure -ObjC is present. If it was removed or modified during updates, this could prevent InstanceID from accessing the Sender ID.

  • Manually add GCM_SENDER_ID to Info.plist (as a last resort)
    If the GoogleService-Info.plist still isn't passing the value correctly, you can manually inject it into your Info.plist:

    1. Right-click your Info.plist file and select Open As > Source Code.
    2. Add the following snippet, replacing your-sender-id-here with your actual Sender ID from Firebase:
      <key>GCM_SENDER_ID</key>
      <string>your-sender-id-here</string>
      

If none of these steps work, try re-downloading the latest GoogleService-Info.plist from your Firebase project—sometimes the file gets outdated if you made changes to your project settings.

内容的提问来源于stack exchange,提问作者Dragan Todorovic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:21:29