@@ -17,7 +17,8 @@ import FirebaseInstallations
1717
1818let kFLTFirebaseInstallationsChannelName = " plugins.flutter.io/firebase_app_installations "
1919
20- public class FirebaseInstallationsPlugin : NSObject , FLTFirebasePluginProtocol , FlutterPlugin {
20+ public class FirebaseInstallationsPlugin : NSObject , FLTFirebasePluginProtocol ,
21+ FlutterPlugin , FirebaseAppInstallationsHostApi {
2122 private var eventSink : FlutterEventSink ?
2223 private var messenger : FlutterBinaryMessenger
2324 private var streamHandler = [ String: IdChangedStreamHandler? ] ( )
@@ -42,6 +43,9 @@ public class FirebaseInstallationsPlugin: NSObject, FLTFirebasePluginProtocol, F
4243 let instance = FirebaseInstallationsPlugin ( messenger: binaryMessenger)
4344 FLTFirebasePluginRegistry . sharedInstance ( ) . register ( instance)
4445 registrar. addMethodCallDelegate ( instance, channel: channel)
46+
47+ // Set up Pigeon host API handlers for Dart-side FirebaseAppInstallationsHostApi.
48+ SetUpFirebaseAppInstallationsHostApi ( binaryMessenger, instance)
4549 }
4650
4751 public func firebaseLibraryVersion( ) -> String {
@@ -71,6 +75,10 @@ public class FirebaseInstallationsPlugin: NSObject, FLTFirebasePluginProtocol, F
7175 return Installations . installations ( app: app)
7276 }
7377
78+ private func getInstallations( app: AppInstallationsPigeonFirebaseApp ) -> Installations {
79+ getInstallations ( appName: app. appName)
80+ }
81+
7482 /// Gets Installations Id for an instance.
7583 /// - Parameter arguments: the arguments passed by the Dart calling method
7684 /// - Parameter result: the result instance used to send the result to Dart.
@@ -122,6 +130,80 @@ public class FirebaseInstallationsPlugin: NSObject, FLTFirebasePluginProtocol, F
122130 }
123131 }
124132
133+ // MARK: - FirebaseAppInstallationsHostApi (Pigeon)
134+
135+ public func initializeAppApp(
136+ _ app: AppInstallationsPigeonFirebaseApp ,
137+ settings: AppInstallationsPigeonSettings ,
138+ completion: @escaping ( FlutterError ? ) -> Void
139+ ) {
140+ // Currently no per-app settings are applied on iOS; ensure the instance is created.
141+ _ = getInstallations ( app: app)
142+ completion ( nil )
143+ }
144+
145+ public func deleteApp(
146+ _ app: AppInstallationsPigeonFirebaseApp ,
147+ completion: @escaping ( FlutterError ? ) -> Void
148+ ) {
149+ let instance = getInstallations ( app: app)
150+ instance. delete { error in
151+ if let error = error as NSError ? {
152+ let code = self
153+ . mapInstallationsErrorCodes ( code: UInt ( error. code) ) as String
154+ completion ( FlutterError ( code: code, message: error. localizedDescription, details: nil ) )
155+ } else {
156+ completion ( nil )
157+ }
158+ }
159+ }
160+
161+ public func getIdApp(
162+ _ app: AppInstallationsPigeonFirebaseApp ,
163+ completion: @escaping ( String ? , FlutterError ? ) -> Void
164+ ) {
165+ let instance = getInstallations ( app: app)
166+ instance. installationID { id, error in
167+ if let error = error as NSError ? {
168+ let code = self
169+ . mapInstallationsErrorCodes ( code: UInt ( error. code) ) as String
170+ completion ( nil , FlutterError ( code: code, message: error. localizedDescription, details: nil ) )
171+ } else {
172+ completion ( id, nil )
173+ }
174+ }
175+ }
176+
177+ public func getTokenApp(
178+ _ app: AppInstallationsPigeonFirebaseApp ,
179+ forceRefresh: Bool ,
180+ completion: @escaping ( String ? , FlutterError ? ) -> Void
181+ ) {
182+ let instance = getInstallations ( app: app)
183+ instance. authTokenForcingRefresh ( forceRefresh) { tokenResult, error in
184+ if let error = error as NSError ? {
185+ let code = self
186+ . mapInstallationsErrorCodes ( code: UInt ( error. code) ) as String
187+ completion (
188+ nil ,
189+ FlutterError ( code: code, message: error. localizedDescription, details: nil )
190+ )
191+ } else {
192+ completion ( tokenResult? . authToken, nil )
193+ }
194+ }
195+ }
196+
197+ public func onIdChangeApp(
198+ _ app: AppInstallationsPigeonFirebaseApp ,
199+ newId: String ,
200+ completion: @escaping ( FlutterError ? ) -> Void
201+ ) {
202+ // The Dart side currently uses an EventChannel-based listener, so this Pigeon hook
203+ // is a no-op placeholder to satisfy the interface.
204+ completion ( nil )
205+ }
206+
125207 /// Registers a listener for changes in the Installations Id.
126208 /// - Parameter arguments: the arguments passed by the Dart calling method
127209 /// - Parameter result: the result instance used to send the result to Dart.
0 commit comments