Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/firebase_messaging/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 6.0.15

* During the `configure` method, only invoke `FcmDartService#start` for the Android platform, since
background message notification isn't working on iOS

## 6.0.14

* Fix for missing UserAgent.h compilation failures.
Expand Down
29 changes: 19 additions & 10 deletions packages/firebase_messaging/lib/firebase_messaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,23 @@ class FirebaseMessaging {
}

/// Sets up [MessageHandler] for incoming messages.
void configure({
///
/// @param onBackgroundMessage This callback must be a top-level or static function, otherwise an [ArgumentError] will
/// be raised
///
/// @returns true if a background handler was configured, false otherwise
/// @throws ArgumentError is onBackgroundMessage is invalid
Future<bool> configure({
MessageHandler onMessage,
MessageHandler onBackgroundMessage,
MessageHandler onLaunch,
MessageHandler onResume,
}) {
}) async {
_onMessage = onMessage;
_onLaunch = onLaunch;
_onResume = onResume;
_channel.setMethodCallHandler(_handleMethod);
_channel.invokeMethod<void>('configure');
await _channel.invokeMethod<void>('configure');
if (onBackgroundMessage != null) {
_onBackgroundMessage = onBackgroundMessage;
final CallbackHandle backgroundSetupHandle =
Expand All @@ -127,14 +133,17 @@ class FirebaseMessaging {
);
}

_channel.invokeMethod<bool>(
'FcmDartService#start',
<String, dynamic>{
'setupHandle': backgroundSetupHandle.toRawHandle(),
'backgroundHandle': backgroundMessageHandle.toRawHandle()
},
);
if (_platform.isAndroid) {
return await _channel.invokeMethod<bool>(
'FcmDartService#start',
<String, dynamic>{
'setupHandle': backgroundSetupHandle.toRawHandle(),
'backgroundHandle': backgroundMessageHandle.toRawHandle()
},
);
}
}
return false;
}

final StreamController<String> _tokenStreamController =
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_messaging/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: firebase_messaging
description: Flutter plugin for Firebase Cloud Messaging, a cross-platform
messaging solution that lets you reliably deliver messages on Android and iOS.
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_messaging
version: 6.0.14
version: 6.0.15

flutter:
plugin:
Expand Down
43 changes: 40 additions & 3 deletions packages/firebase_messaging/test/firebase_messaging_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import 'dart:async';

import 'package:flutter/services.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart' show TestWidgetsFlutterBinding;
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import 'package:test/test.dart';

const fcmDartServiceStart = 'FcmDartService#start';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

Expand All @@ -19,6 +21,8 @@ void main() {

setUp(() {
mockChannel = MockMethodChannel();
when(mockChannel.invokeMethod<bool>(fcmDartServiceStart, any))
.thenAnswer((_) => Future.value(true));
firebaseMessaging = FirebaseMessaging.private(
mockChannel, FakePlatform(operatingSystem: 'ios'));
});
Expand Down Expand Up @@ -182,13 +186,46 @@ void main() {
verify(mockChannel.invokeMethod<void>('setAutoInitEnabled', false));
});

test('configure bad onBackgroundMessage', () {
test('configure bad onBackgroundMessage iOS', () async {
expect(
firebaseMessaging.configure(
onBackgroundMessage: (dynamic message) => Future<dynamic>.value(),
),
throwsArgumentError,
);
// Even with the bad arg, configure still should have been called
verify(mockChannel.invokeMethod("configure"));
});

test('configure bad onBackgroundMessage android', () async {
final firebaseMessaging = FirebaseMessaging.private(
mockChannel, FakePlatform(operatingSystem: 'android'));
expect(
() => firebaseMessaging.configure(
firebaseMessaging.configure(
onBackgroundMessage: (dynamic message) => Future<dynamic>.value(),
),
throwsArgumentError,
);
// Even though there was an error, configure still should have been called.
verify(mockChannel.invokeMethod("configure"));
});

test('configure onBackgroundMessage android', () async {
final firebaseMessaging = FirebaseMessaging.private(
mockChannel, FakePlatform(operatingSystem: 'android'));
final result = await firebaseMessaging.configure(
onBackgroundMessage: validOnBackgroundMessage);
expect(result, isTrue);
verify(mockChannel.invokeMethod<void>("configure"));
verify(mockChannel.invokeMethod<bool>(fcmDartServiceStart, any));
});

test('configure onBackgroundMessage ios', () async {
final result = await firebaseMessaging.configure(
onBackgroundMessage: validOnBackgroundMessage);
expect(result, isFalse);
verify(mockChannel.invokeMethod("configure"));
verifyNever(mockChannel.invokeMethod(fcmDartServiceStart, any));
});
}

Expand Down