Skip to content

Commit 6fd738b

Browse files
authored
Merge pull request #9 from Eurofunk/add-notification-settings-getter
Add notification settings getter
2 parents 8fb1100 + 848b47c commit 6fd738b

File tree

6 files changed

+37
-25
lines changed

6 files changed

+37
-25
lines changed

example/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ packages:
156156
path: "../flutter_apns"
157157
relative: true
158158
source: path
159-
version: "1.7.3"
159+
version: "1.7.5"
160160
flutter_apns_only:
161161
dependency: transitive
162162
description:
163163
path: "../flutter_apns_only"
164164
relative: true
165165
source: path
166-
version: "1.7.3"
166+
version: "1.7.5"
167167
flutter_local_notifications:
168168
dependency: "direct main"
169169
description:

flutter_apns/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ packages:
116116
path: "../flutter_apns_only"
117117
relative: true
118118
source: path
119-
version: "1.7.3"
119+
version: "1.7.5"
120120
flutter_test:
121121
dependency: "direct dev"
122122
description: flutter

flutter_apns/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_apns
22
description: APNS push notification plugin. Uses firebase_messaging on Android, but replaces it on iOS with custom implementation.
3-
version: 1.7.3
3+
version: 1.7.5
44
homepage: https://github.com/mwaylabs/flutter-apns
55

66
publish_to: 'none'

flutter_apns_only/ios/Classes/FlutterApnsPlugin.swift

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func getFlutterError(_ error: Error) -> FlutterError {
4848
case "setNotificationCategories":
4949
setNotificationCategories(arguments: call.arguments!)
5050
result(nil)
51+
case "getNotificationSettings":
52+
getNotificationSettings(){(value) in
53+
result(value)
54+
}
5155
default:
5256
assertionFailure(call.method)
5357
result(FlutterMethodNotImplemented)
@@ -105,6 +109,23 @@ func getFlutterError(_ error: Error) -> FlutterError {
105109
}
106110
}
107111

112+
func getNotificationSettings(completion: @escaping (([String: Bool]) -> Void)){
113+
let center = UNUserNotificationCenter.current()
114+
let application = UIApplication.shared
115+
116+
assert(center.delegate != nil)
117+
118+
center.getNotificationSettings { (settings) in
119+
let map = [
120+
"sound": settings.soundSetting == .enabled,
121+
"badge": settings.badgeSetting == .enabled,
122+
"alert": settings.alertSetting == .enabled,
123+
"carPlay": settings.carPlaySetting == .enabled,
124+
]
125+
completion(map)
126+
}
127+
}
128+
108129
func requestNotificationPermissions(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
109130
let center = UNUserNotificationCenter.current()
110131
let application = UIApplication.shared
@@ -130,14 +151,6 @@ func getFlutterError(_ error: Error) -> FlutterError {
130151
if readBool("carPlay") {
131152
options.append(.carPlay)
132153
}
133-
134-
var provisionalRequested = false
135-
if #available(iOS 12.0, *) {
136-
if readBool("provisional") {
137-
options.append(.provisional)
138-
provisionalRequested = true
139-
}
140-
}
141154

142155

143156
let optionsUnion = UNAuthorizationOptions(options)
@@ -148,16 +161,9 @@ func getFlutterError(_ error: Error) -> FlutterError {
148161
return
149162
}
150163

151-
center.getNotificationSettings { (settings) in
152-
let map = [
153-
"sound": settings.soundSetting == .enabled,
154-
"badge": settings.badgeSetting == .enabled,
155-
"alert": settings.alertSetting == .enabled,
156-
"carPlay": settings.carPlaySetting == .enabled,
157-
"provisional": granted && provisionalRequested
158-
]
159-
160-
self.channel.invokeMethod("onIosSettingsRegistered", arguments: map)
164+
self.getNotificationSettings(){(value) in
165+
self.channel.invokeMethod("onIosSettingsRegistered", arguments: value)
166+
161167
}
162168

163169
result(granted)

flutter_apns_only/lib/flutter_apns_only.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class ApnsPushConnectorOnly {
6868
return null;
6969
case 'onIosSettingsRegistered':
7070
final obj = IosNotificationSettings._fromMap(call.arguments.cast<String, bool>());
71-
71+
_iosSettingsStreamController.add(obj);
7272
isDisabledByUser.value = obj.alert == false;
73-
return null;
73+
return;
7474
case 'onMessage':
7575
return _onMessage?.call(_extractMessage(call));
7676
case 'onLaunch':
@@ -128,6 +128,12 @@ class ApnsPushConnectorOnly {
128128
);
129129
}
130130

131+
/// https://developer.apple.com/documentation/usernotifications/unnotificationsettings/
132+
Future<IosNotificationSettings> getNotificationSettings() async {
133+
final result = await _channel.invokeMethod<Map<String, dynamic>>('getNotificationSettings');
134+
return IosNotificationSettings._fromMap(result as Map<String, bool>);
135+
}
136+
131137
Future<void> unregister() async {
132138
await _channel.invokeMethod('unregister');
133139
token.value = null;

flutter_apns_only/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_apns_only
22
description: APNS push notification plugin. Works only on iOS. See flutter_apns for apns & firebase combo
3-
version: 1.7.3
3+
version: 1.7.5
44
homepage: https://github.com/mwaylabs/flutter-apns
55

66
environment:

0 commit comments

Comments
 (0)