Skip to content

Commit 352c913

Browse files
committed
rename notification permission change event
fix
1 parent 1735f64 commit 352c913

File tree

6 files changed

+15
-26
lines changed

6 files changed

+15
-26
lines changed

android/src/main/java/com/onesignal/flutter/OneSignalNotifications.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import io.flutter.plugin.common.PluginRegistry;
3838
import io.flutter.plugin.common.PluginRegistry.Registrar;
3939

40-
public class OneSignalNotifications extends FlutterRegistrarResponder implements MethodCallHandler, INotificationClickHandler, INotificationWillShowInForegroundHandler, IPermissionChangedHandler {
40+
public class OneSignalNotifications extends FlutterRegistrarResponder implements MethodCallHandler, INotificationClickHandler, INotificationWillShowInForegroundHandler, IPermissionObserver {
4141
private boolean hasSetNotificationWillShowInForegroundHandler = false;
4242
private final HashMap<String, INotificationReceivedEvent> notificationReceivedEventCache = new HashMap<>();
4343

@@ -184,8 +184,8 @@ public void notificationWillShowInForeground(INotificationReceivedEvent notifica
184184
}
185185

186186
@Override
187-
public void onPermissionChanged(boolean permission) {
188-
invokeMethodOnUiThread("OneSignal#OSPermissionChanged", OneSignalSerializer.convertPermissionChanged(permission));
187+
public void onNotificationPermissionChange(boolean permission) {
188+
invokeMethodOnUiThread("OneSignal#onNotificationPermissionDidChange", permission);
189189
}
190190

191191
private void lifecycleInit() {

android/src/main/java/com/onesignal/flutter/OneSignalSerializer.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,6 @@ private static HashMap<String, Object> convertNotificationActionToMap(INotificat
101101
return hash;
102102
}
103103

104-
static HashMap<String, Object> convertPermissionChanged(boolean state) {
105-
HashMap<String, Object> permission = new HashMap<>();
106-
107-
permission.put("permission", state);
108-
109-
return permission;
110-
}
111-
112-
113104
static HashMap<String, Object> convertInAppMessageClickedActionToMap(IInAppMessageClickResult result) {
114105
HashMap<String, Object> hash = new HashMap<>();
115106

example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class _MyAppState extends State<MyApp>
2121
bool _enableConsentButton = false;
2222

2323
// CHANGE THIS parameter to true if you want to test GDPR privacy consent
24-
bool _requireConsent = true;
24+
bool _requireConsent = false;
2525

2626
@override
2727
void initState() {
@@ -111,7 +111,7 @@ class _MyAppState extends State<MyApp>
111111
oneSignalOutcomeExamples();
112112
}
113113

114-
void onOSPermissionChanged(bool state) {
114+
void onNotificationPermissionDidChange(bool state) {
115115
print("Has permission " + state.toString());
116116
}
117117

ios/Classes/OSFlutterNotifications.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#import <Flutter/Flutter.h>
3131
#import <OneSignalNotifications/OneSignalNotifications.h>
3232

33-
@interface OSFlutterNotifications : NSObject<FlutterPlugin, OSPermissionObserver>
33+
@interface OSFlutterNotifications : NSObject<FlutterPlugin, OSNotificationPermissionObserver>
3434

3535
@property (strong, nonatomic) FlutterMethodChannel *channel;
3636
+ (instancetype)sharedInstance;

ios/Classes/OSFlutterNotifications.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
7979
}
8080

8181
- (void)permissionNative:(FlutterMethodCall *)call withResult:(FlutterResult)result {
82-
OSNotificationPermission *permission = [OneSignal.Notifications permissionNative];
82+
OSNotificationPermission permission = [OneSignal.Notifications permissionNative];
8383
result(@((int)permission));
8484
}
8585

@@ -110,8 +110,8 @@ - (void)lifecycleInit:(FlutterMethodCall *)call withResult:(FlutterResult)result
110110
result(nil);
111111
}
112112

113-
- (void)onOSPermissionChanged:(OSPermissionState*)state {
114-
[self.channel invokeMethod:@"OneSignal#OSPermissionChanged" arguments:state.jsonRepresentation];
113+
- (void)onNotificationPermissionDidChange:(BOOL)permission {
114+
[self.channel invokeMethod:@"OneSignal#onNotificationPermissionDidChange" arguments:@{@"permission" : @(permission)}];
115115
}
116116

117117
#pragma mark Received in Foreground Notification

lib/src/notifications.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class OneSignalNotifications {
100100
}
101101
}
102102

103-
/// The OSPermissionObserver.onOSPermissionChanged method will be fired on the passed-in object
103+
/// The OSNotificationPermissionObserver.onNotificationPermissionDidChange method will be fired on the passed-in object
104104
/// when a notification permission setting changes. This happens when the user enables or disables
105105
/// notifications for your app from the system settings outside of your app.
106106
void addPermissionObserver(OneSignalPermissionObserver observer) {
@@ -131,17 +131,15 @@ class OneSignalNotifications {
131131
this._onNotificationWillShowInForegroundHandler != null) {
132132
this._onNotificationWillShowInForegroundHandler!(
133133
OSNotificationReceivedEvent(call.arguments.cast<String, dynamic>()));
134-
} else if (call.method == 'OneSignal#OSPermissionChanged') {
135-
this.onOSPermissionChangedHandler(
136-
OSPermissionState(call.arguments.cast<String, dynamic>()));
134+
} else if (call.method == 'OneSignal#onNotificationPermissionDidChange') {
135+
this.onNotificationPermissionDidChange(call.arguments["permission"]);
137136
}
138137
return null;
139138
}
140139

141-
Future<void> onOSPermissionChangedHandler(OSPermissionState state) async {
142-
_permission = state.permission;
140+
void onNotificationPermissionDidChange(bool permission) {
143141
for (var observer in _observers) {
144-
observer.onOSPermissionChanged(_permission);
142+
observer.onNotificationPermissionDidChange(permission);
145143
}
146144
}
147145

@@ -167,5 +165,5 @@ class OneSignalNotifications {
167165
}
168166

169167
class OneSignalPermissionObserver {
170-
void onOSPermissionChanged(bool state) {}
168+
void onNotificationPermissionDidChange(bool permission) {}
171169
}

0 commit comments

Comments
 (0)