'What is the difference between app instance id and instance id in Firebase?

What is the difference between app instance id and instance id in Firebase?

We can get the two different values seperatedly by:

print("app instance id: \(Analytics.appInstanceID())")

InstanceID.instanceID().getID { (idString, error) in
    print("instance id: \(idString)")
}

Both of them seem to have the same behavior, which is they will be different after uninstalling and reinstalling the app. Then why does Firebase need to have two properties? I can not see the difference from the document.

Example values:

InstanceID.instanceID().getID(): fPuHFoJSGEJYsguI_2IPXF

Analytics.appInstanceID(): 8F1C7C2C9A554DECAF27DB6AEFF5B301



Solution 1:[1]

Assuming you are using Firebase Analytics in your app (otherwise you wouldn't have the Analytics.appInstanceID() method available to you). From the docs, the Firebase Analytics object is:

The top level Firebase Analytics singleton that provides methods for logging events and setting user properties.

This analytics singleton has an ID associated with it, which is unique to the instance of the app. ie: If the app is uninstalled and reinstalled, there will be a fresh instance of the singleton created and the ID will change. This ID is called the appInstanceId.


The InstanceID that you speak about is the ID associated with the Firebase Installation in your app. From the docs:

Each configured FirebaseApp has a corresponding single instance of Installations. An instance of the class provides access to the installation info for the FirebaseApp as well as the ability to delete it. A Firebase Installation is unique by FirebaseApp.name and FirebaseApp.options.googleAppID.

The Firebase Installation Service and its associated ID are used for a number of Firebase services, not just analytics. See here for a list.

There may be a case where you are using some Firebase services and therefore the instance ID will be used (possibly only used by the SDK in the background), but you are not using Firebase Analytics, so the appInstanceId may not feature at all.


In short, the appInstanceId is the ID associated with the Firebase Analytics instance in your app. Whereas the InstanceID (or Installation ID) covers a broader scope and is used for various Firebase services, and can be used for both identification and auth token generation, if needed.

Note that the InstanceID API is deprecated. Use FirebaseInstallations instead (this one for Android).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Teagan O'Gorman