Skip to content

Commit 1b71626

Browse files
authored
feat(messaging): remove deprecated functions (#17563)
This PR removes the deprecated `sendMessage` method from the firebase_messaging package as part of preparing for a breaking change release. The method was deprecated due to Firebase decommissioning this functionality in June 2024. ## Changes - Removed `sendMessage` method from main FirebaseMessaging class - Removed method from platform interface - Removed method from method channel implementation - Updated tests to remove sendMessage test cases ## Migration Guide The `sendMessage` method was Android-only and allowed sending FCM messages from the client. To migrate, use Firebase Cloud Functions or your backend server to send messages instead of the client-side method. ## Breaking Change This removes the deprecated `sendMessage` method entirely. Apps using this method will need to migrate to server-side message sending before upgrading.
1 parent ea3034d commit 1b71626

File tree

4 files changed

+3
-70
lines changed

4 files changed

+3
-70
lines changed

packages/firebase_messaging/firebase_messaging/lib/src/messaging.dart

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,6 @@ class FirebaseMessaging extends FirebasePluginPlatform {
212212
);
213213
}
214214

215-
/// Send a new [RemoteMessage] to the FCM server. Android only.
216-
/// Firebase will decommission in June 2024: https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessaging#send
217-
@Deprecated(
218-
'This will be removed in a future release. Firebase will decommission in June 2024')
219-
Future<void> sendMessage({
220-
String? to,
221-
Map<String, String>? data,
222-
String? collapseKey,
223-
String? messageId,
224-
String? messageType,
225-
int? ttl,
226-
}) {
227-
if (ttl != null) {
228-
assert(ttl >= 0);
229-
}
230-
return _delegate.sendMessage(
231-
to: to ?? '${app.options.messagingSenderId}@fcm.googleapis.com',
232-
data: data,
233-
collapseKey: collapseKey,
234-
messageId: messageId,
235-
messageType: messageType,
236-
ttl: ttl,
237-
);
238-
}
239-
240215
/// Enable or disable auto-initialization of Firebase Cloud Messaging.
241216
Future<void> setAutoInitEnabled(bool enabled) async {
242217
return _delegate.setAutoInitEnabled(enabled);

packages/firebase_messaging/firebase_messaging_platform_interface/lib/src/method_channel/method_channel_messaging.dart

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -358,35 +358,6 @@ class MethodChannelFirebaseMessaging extends FirebaseMessagingPlatform {
358358
}
359359
}
360360

361-
@override
362-
Future<void> sendMessage({
363-
required String to,
364-
Map<String, String>? data,
365-
String? collapseKey,
366-
String? messageId,
367-
String? messageType,
368-
int? ttl,
369-
}) async {
370-
if (defaultTargetPlatform != TargetPlatform.android) {
371-
throw UnimplementedError(
372-
'Sending of messages from the Firebase Messaging SDK is only supported on Android devices.');
373-
}
374-
375-
try {
376-
await channel.invokeMapMethod('Messaging#sendMessage', {
377-
'appName': app.name,
378-
'to': to,
379-
'data': data,
380-
'collapseKey': collapseKey,
381-
'messageId': messageId,
382-
'messageType': messageType,
383-
'ttl': ttl,
384-
});
385-
} catch (e, stack) {
386-
convertPlatformException(e, stack);
387-
}
388-
}
389-
390361
@override
391362
Future<void> subscribeToTopic(String topic) async {
392363
await _APNSTokenCheck();

packages/firebase_messaging/firebase_messaging_platform_interface/lib/src/platform_interface/platform_interface_messaging.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,6 @@ abstract class FirebaseMessagingPlatform extends PlatformInterface {
295295
'setForegroundNotificationPresentationOptions() is not implemented');
296296
}
297297

298-
/// Send a new [RemoteMessage] to the FCM server.
299-
Future<void> sendMessage({
300-
required String to,
301-
Map<String, String>? data,
302-
String? collapseKey,
303-
String? messageId,
304-
String? messageType,
305-
int? ttl,
306-
}) {
307-
throw UnimplementedError('sendMessage() is not implemented');
308-
}
309-
310298
/// Subscribe to topic in background.
311299
///
312300
/// [topic] must match the following regular expression:

packages/firebase_messaging/firebase_messaging_platform_interface/test/method_channel_tests/method_channel_messaging_test.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
// Use of this source code is governed by a BSD-style license that can be
44
// found in the LICENSE file.
55

6-
import 'package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart';
6+
import 'package:firebase_core/firebase_core.dart';
77
import 'package:firebase_messaging_platform_interface/firebase_messaging_platform_interface.dart';
8+
import 'package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart';
89
import 'package:flutter/foundation.dart';
9-
import 'package:flutter_test/flutter_test.dart';
1010
import 'package:flutter/services.dart';
11-
import 'package:firebase_core/firebase_core.dart';
11+
import 'package:flutter_test/flutter_test.dart';
1212
import 'package:mockito/mockito.dart';
1313
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
1414

@@ -29,7 +29,6 @@ void main() {
2929
log.add(call);
3030
switch (call.method) {
3131
case 'Messaging#deleteToken':
32-
case 'Messaging#sendMessage':
3332
case 'Messaging#subscribeToTopic':
3433
case 'Messaging#unsubscribeFromTopic':
3534
return null;

0 commit comments

Comments
 (0)