File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
packages/firebase_messaging Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
122
122
NSNumber *value = call.arguments ;
123
123
[FIRMessaging messaging ].autoInitEnabled = value.boolValue ;
124
124
result (nil );
125
+ } else if ([@" iosCheckPermissions" isEqualToString: method]) {
126
+ UIUserNotificationSettings *currentSettings =
127
+ [[UIApplication sharedApplication ] currentUserNotificationSettings ];
128
+ NSDictionary *settingsDictionary = @{
129
+ @" sound" : [NSNumber numberWithBool: currentSettings.types & UIUserNotificationTypeSound],
130
+ @" badge" : [NSNumber numberWithBool: currentSettings.types & UIUserNotificationTypeBadge],
131
+ @" alert" : [NSNumber numberWithBool: currentSettings.types & UIUserNotificationTypeAlert],
132
+ };
133
+ result (settingsDictionary);
125
134
} else {
126
135
result (FlutterMethodNotImplemented);
127
136
}
Original file line number Diff line number Diff line change @@ -134,6 +134,11 @@ class FirebaseMessaging {
134
134
throw UnsupportedError ("Unrecognized JSON message" );
135
135
}
136
136
}
137
+
138
+ Future <IosNotificationSettings > checkIosNotificationSettings () async {
139
+ return IosNotificationSettings ._fromMap (
140
+ await _channel.invokeMapMethod <String , bool >('iosCheckPermissions' ));
141
+ }
137
142
}
138
143
139
144
class IosNotificationSettings {
@@ -159,4 +164,14 @@ class IosNotificationSettings {
159
164
160
165
@override
161
166
String toString () => 'PushNotificationSettings ${toMap ()}' ;
167
+
168
+ @override
169
+ int get hashCode => sound.hashCode ^ alert.hashCode ^ badge.hashCode;
170
+
171
+ @override
172
+ bool operator == (dynamic other) =>
173
+ other is IosNotificationSettings &&
174
+ other.sound == sound &&
175
+ other.alert == alert &&
176
+ other.badge == badge;
162
177
}
Original file line number Diff line number Diff line change @@ -166,6 +166,19 @@ void main() {
166
166
167
167
verify (mockChannel.invokeMethod <void >('setAutoInitEnabled' , false ));
168
168
});
169
+
170
+ test ('checkIosNotificationSettings' , () async {
171
+ when (mockChannel.invokeMapMethod <String , bool >('iosCheckPermissions' ))
172
+ .thenAnswer ((_) async =>
173
+ const IosNotificationSettings (sound: true , alert: true , badge: true )
174
+ .toMap ());
175
+
176
+ expect (await firebaseMessaging.checkIosNotificationSettings (),
177
+ const IosNotificationSettings (sound: true , alert: true , badge: true ));
178
+ verify (mockChannel.invokeMapMethod <String , bool >(captureAny))
179
+ .captured
180
+ .single;
181
+ });
169
182
}
170
183
171
184
class MockMethodChannel extends Mock implements MethodChannel {}
You can’t perform that action at this time.
0 commit comments