diff --git a/packages/firebase_messaging/CHANGELOG.md b/packages/firebase_messaging/CHANGELOG.md index e8448c875253..aa1bc9f34cdb 100644 --- a/packages/firebase_messaging/CHANGELOG.md +++ b/packages/firebase_messaging/CHANGELOG.md @@ -1,3 +1,6 @@ +## 5.1.5 +* Add checkIosNotificationSettings method to check whether the user has previously accepted or declined the push notifications on iOS devices. + ## 5.1.4 * Update documentation to reflect new repository location. diff --git a/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m b/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m index 225b86f99599..bc5f5b8eebd7 100644 --- a/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m +++ b/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m @@ -122,6 +122,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSNumber *value = call.arguments; [FIRMessaging messaging].autoInitEnabled = value.boolValue; result(nil); + } else if ([@"iosCheckPermissions" isEqualToString:method]) { + UIUserNotificationSettings *currentSettings = + [[UIApplication sharedApplication] currentUserNotificationSettings]; + NSDictionary *settingsDictionary = @{ + @"sound" : [NSNumber numberWithBool:currentSettings.types & UIUserNotificationTypeSound], + @"badge" : [NSNumber numberWithBool:currentSettings.types & UIUserNotificationTypeBadge], + @"alert" : [NSNumber numberWithBool:currentSettings.types & UIUserNotificationTypeAlert], + }; + result(settingsDictionary); } else { result(FlutterMethodNotImplemented); } diff --git a/packages/firebase_messaging/lib/firebase_messaging.dart b/packages/firebase_messaging/lib/firebase_messaging.dart index f40420c6dbe5..bb5fa418872e 100644 --- a/packages/firebase_messaging/lib/firebase_messaging.dart +++ b/packages/firebase_messaging/lib/firebase_messaging.dart @@ -134,6 +134,11 @@ class FirebaseMessaging { throw UnsupportedError("Unrecognized JSON message"); } } + + Future checkIosNotificationSettings() async { + return IosNotificationSettings._fromMap( + await _channel.invokeMapMethod('iosCheckPermissions')); + } } class IosNotificationSettings { @@ -159,4 +164,14 @@ class IosNotificationSettings { @override String toString() => 'PushNotificationSettings ${toMap()}'; + + @override + int get hashCode => sound.hashCode ^ alert.hashCode ^ badge.hashCode; + + @override + bool operator ==(dynamic other) => + other is IosNotificationSettings && + other.sound == sound && + other.alert == alert && + other.badge == badge; } diff --git a/packages/firebase_messaging/pubspec.yaml b/packages/firebase_messaging/pubspec.yaml index aaf0a873c4a5..428a4c4ac19a 100644 --- a/packages/firebase_messaging/pubspec.yaml +++ b/packages/firebase_messaging/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Cloud Messaging, a cross-platform messaging solution that lets you reliably deliver messages on Android and iOS. author: Flutter Team homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_messaging -version: 5.1.4 +version: 5.1.5 flutter: plugin: @@ -27,5 +27,5 @@ dev_dependencies: sdk: flutter environment: - sdk: ">=2.0.0-dev.28.0 <3.0.0" - flutter: ">=1.5.0 <2.0.0" + sdk: '>=2.0.0-dev.28.0 <3.0.0' + flutter: '>=1.5.0 <2.0.0' diff --git a/packages/firebase_messaging/test/firebase_messaging_test.dart b/packages/firebase_messaging/test/firebase_messaging_test.dart index c0a47ba57366..a1ce99ac2232 100644 --- a/packages/firebase_messaging/test/firebase_messaging_test.dart +++ b/packages/firebase_messaging/test/firebase_messaging_test.dart @@ -166,6 +166,19 @@ void main() { verify(mockChannel.invokeMethod('setAutoInitEnabled', false)); }); + + test('checkIosNotificationSettings', () async { + when(mockChannel.invokeMapMethod('iosCheckPermissions')) + .thenAnswer((_) async => + const IosNotificationSettings(sound: true, alert: true, badge: true) + .toMap()); + + expect(await firebaseMessaging.checkIosNotificationSettings(), + const IosNotificationSettings(sound: true, alert: true, badge: true)); + verify(mockChannel.invokeMapMethod(captureAny)) + .captured + .single; + }); } class MockMethodChannel extends Mock implements MethodChannel {}