File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
56
56
- (void )handleMethodCall : (FlutterMethodCall*)call result : (FlutterResult)result {
57
57
if ([@" OneSignal#permission" isEqualToString: call.method])
58
58
result (@([OneSignal.Notifications permission ]));
59
+ else if ([@" OneSignal#permissionNative" isEqualToString: call.method])
60
+ [self permissionNative: call withResult: result];
59
61
else if ([@" OneSignal#canRequest" isEqualToString: call.method])
60
62
result (@([OneSignal.Notifications canRequestPermission ]));
61
63
else if ([@" OneSignal#clearAll" isEqualToString: call.method])
@@ -76,6 +78,11 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
76
78
result (FlutterMethodNotImplemented);
77
79
}
78
80
81
+ - (void )permissionNative : (FlutterMethodCall *)call withResult : (FlutterResult)result {
82
+ OSNotificationPermission *permission = [OneSignal.Notifications permissionNative ];
83
+ result (@((int )permission));
84
+ }
85
+
79
86
- (void )clearAll : (FlutterMethodCall *)call withResult : (FlutterResult)result {
80
87
[OneSignal.Notifications clearAll ];
81
88
result (nil );
Original file line number Diff line number Diff line change 1
1
import 'dart:async' ;
2
2
import 'dart:io' ;
3
3
import 'package:flutter/services.dart' ;
4
+ import 'package:onesignal_flutter/src/defines.dart' ;
4
5
import 'package:onesignal_flutter/src/notification.dart' ;
5
6
import 'package:onesignal_flutter/src/permission.dart' ;
6
7
@@ -31,6 +32,24 @@ class OneSignalNotifications {
31
32
return _permission;
32
33
}
33
34
35
+ /// iOS only
36
+ /// enum OSNotificationPermission {
37
+ /// notDetermined,
38
+ /// denied,
39
+ /// authorized,
40
+ /// provisional, // only available in iOS 12
41
+ /// ephemeral, // only available in iOS 14
42
+ Future <OSNotificationPermission > permissionNative () async {
43
+ if (Platform .isIOS) {
44
+ return OSNotificationPermission
45
+ .values[await _channel.invokeMethod ("OneSignal#permissionNative" )];
46
+ } else {
47
+ return _permission
48
+ ? OSNotificationPermission .authorized
49
+ : OSNotificationPermission .denied;
50
+ }
51
+ }
52
+
34
53
/// Whether attempting to request notification permission will show a prompt.
35
54
/// Returns true if the device has not been prompted for push notification permission already.
36
55
Future <bool > canRequest () async {
You can’t perform that action at this time.
0 commit comments