// An Instance ID sent from a client service SDKconstidToDelete='INSTANCE_ID';admin.instanceId().deleteInstanceId(idToDelete);
Java
// An Instance ID sent from a client service SDKStringidToDelete="INSTANCE_ID";FirebaseInstanceId.getInstance().deleteInstanceIdAsync(idToDelete).get();
Python
fromfirebase_adminimportinstance_id# An Instance ID sent from a client service SDKid_to_delete='INSTANCE_ID'instance_id.delete_instance_id(id_to_delete)
[null,null,["最后更新时间 (UTC):2025-04-10。"],[],[],null,["| **Warning:** **The Instance ID API is deprecated.** If you need to access unique app installation identifiers, use the [Firebase installations](/docs/projects/manage-installations) API. See also [Firebase installations and Instance ID](/docs/projects/manage-installations#fid-iid). The [server-side topic management API](https://developers.google.com/instance-id/reference/server#create_relationship_maps_for_app_instances) is still available.\n\nInstance IDs identify individual installations of your app. Since each Instance\nID is unique to a particular app and device, they give Firebase services a way\nto refer to specific app instances. For example, Cloud Messaging uses\nInstance IDs to determine which devices to send messages to.\n\nSeveral Firebase services use Instance IDs to power their features:\n\n- Analytics\n- Crashlytics\n- Cloud Messaging\n- Remote Config\n\nManage app data associated with Instance IDs\n\nServices that use Instance IDs to identify installations also use them as a key to\nassociate relevant data with that device. For example, Crashlytics uses\nInstance IDs to record crashes that happen on the device, Remote Config uses\nthem to fetch configurations, and Analytics uses Instance IDs to track\nparticular audiences.\n\nData associated with Instance IDs is generally *not* personally-identifying,\nbut it can still be helpful to give users an option to manage it. To that\nend, Firebase offers two ways to manage Instance-ID-related data collection:\n\n- **Delete Instance IDs.** You can delete an Instance ID with a server- or client-side API call. Deleting an Instance ID deletes the ID itself and all data associated with it.\n- **Disable services that generate IDs.** Most Firebase services that use Instance IDs automatically generate a new ID if there isn't one on the device when they start up. To ensure your app doesn't create unwanted Instance IDs, disable auto-initialization for those services.\n\nDelete an Instance ID\n\nDeleting an Instance ID also deletes data associated with that ID in any of the\nFirebase services listed above. That makes ID deletion a helpful tool in\nclearing user data, but also comes with a caveat: if you're using multiple\nservices that rely on Instance IDs, deleting an ID clears data from *all* of\nthem.\n\nThe Instance ID service creates a new ID within a few days, unless you\ndisable all Instance-ID-generating services in your app. Firebase considers the\nnewly-created ID to be a brand new app instance, and doesn't associate it with\nthe previous ID in any way.\n| **Note:** Google Analytics uses its own form of Instance ID to keep track of analytics data. Deleting a regular Instance ID does *not* delete Analytics data. Learn how to [delete Analytics data associated with end users](https://support.google.com/firebase/answer/9019185#delete-on-mobile-device).\n\nDelete an ID with a client API call\n\nTo delete IDs generated by Firebase services, call the appropriate method from\nthe Firebase Instance ID API: \n\nSwift \n\n InstanceID.instanceID().deleteID { error in\n if let error = error {\n print(\"Error deleting instance ID: \\(error)\")\n }\n }\n\nObjective-C \n\n [FIRInstanceID instanceID] deleteIDWithHandler:^(NSError *error) {\n if error != nil {\n NSLog(@\"Error deleting instance ID: %@\", error);\n }\n }];\n\nAndroid \n\n FirebaseInstanceId.deleteInstanceId();\n\nDelete an ID with a server API call\n\nTo delete an Instance ID with server API calls, [add the Firebase Admin SDK to your server](//firebase.google.com/docs/admin/setup),\nif you haven't already.\n\nOnce it's added, delete IDs through a call to the Instance ID deletion function\nin your language of choice: \n\nNode.js \n\n // An Instance ID sent from a client service SDK\n const idToDelete = 'INSTANCE_ID';\n\n admin.instanceId().deleteInstanceId(idToDelete);\n\nJava \n\n // An Instance ID sent from a client service SDK\n String idToDelete = \"INSTANCE_ID\";\n\n FirebaseInstanceId.getInstance().deleteInstanceIdAsync(idToDelete).get();\n\nPython \n\n from firebase_admin import instance_id\n\n # An Instance ID sent from a client service SDK\n id_to_delete = 'INSTANCE_ID'\n\n instance_id.delete_instance_id(id_to_delete)\n\nGo \n\n client, err := app.InstanceId(ctx)\n if err != nil {\n log.Fatalln(\"error initializing client\", err)\n }\n\n iidToDelete := \"INSTANCE_ID\"\n if err := client.DeleteInstanceId(ctx, iidToDelete); err != nil {\n log.Fatalln(\"error deleting iid\", err)\n }\n\nWhen you delete an Instance ID with a server API call, Firebase services delete\nthe associated data, stop accepting new data for that ID, and, within a few days,\nnotify the client app that the ID was deleted. Until Firebase notifies the client\napp, some of the app's services might experience reduced functionality.\n\nIf you want to delete the current Instance ID and immediately use Firebase\nservices with a new, independent ID, use one of the Client APIs above to\nhandle the deletion.\n\nDisable Instance ID generation\n\nServices that use Instance IDs automatically generate a new ID when they're\ninitialized in an app that doesn't currently have one. Typically, those services\nalso automatically initialize when your app launches. To disable Instance\nID generation, you have to disable auto-initialization for services that use\nthem.\n\nA common approach is to give users an option to\nopt-in to data collection: disable auto-initialization for\nthe services that use Instance IDs, implement a dialog that prompts\nusers for their consent to data collection, and re-enable the services manually\nonce you have consent.\n\nRead the guides below to find out how to disable auto-initialization for\nInstance-ID-using services and instead manually initialize them:\n\n- Cloud Messaging: [Prevent Auto-initialization (Android)](//firebase.google.com/docs/cloud-messaging/android/client#prevent-auto-init) or [Prevent Auto-initialization (iOS+)](//firebase.google.com/docs/cloud-messaging/ios/client#prevent_auto_initialization)\n- Crash Reporting: [Enable Opt-in Reporting](//firebase.google.com/docs/crash/disable-sdk)\n- Analytics: [Configure Analytics Data Collection](/docs/analytics/configure-data-collection)\n\n| **Note:** Firebase Remote Config also generates Instance IDs, but isn't automatically initialized on app start. To delay ID generation in Remote Config, don't use the service until you're ready to generate an ID."]]