Skip to content

Commit 481edd7

Browse files
committed
Updating privacy consent method names
There are now no getters for privacy consent. Instead we have 2 setters consentRequired(bool) and consentGiven(bool)
1 parent 3479d92 commit 481edd7

File tree

6 files changed

+33
-61
lines changed

6 files changed

+33
-61
lines changed

MIGRATION_GUIDE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ The SDK is still accessible via a `OneSignal` static class. It provides access t
154154
| -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
155155
| `OneSignal.shared.initialize("YOUR_ONESIGNAL_APP_ID");` | *Initializes the OneSignal SDK. This should be called during startup of the application.* |
156156
| `OneSignal.shared.login("USER_EXTERNAL_ID");` | *Login to OneSignal under the user identified by the [externalId] provided. The act of logging a user into the OneSignal SDK will switch the [user] context to that specific user.<br><br> - If the [externalId] exists, the user will be retrieved and the context will be set from that user information. If operations have already been performed under a device-scoped user, they ***will not*** be applied to the now logged in user (they will be lost).<br> - If the [externalId] does not exist the user, the user will be created and the context set from the current local state. If operations have already been performed under a device-scoped user, those operations ***will*** be applied to the newly created user.<br><br>***Push Notifications and In App Messaging***<br>Logging in a new user will automatically transfer the push notification and in app messaging subscription from the current user (if there is one) to the newly logged in user. This is because both push notifications and in- app messages are owned by the device.* |
157-
| `OneSignal.shared.logout();` | *Logout the user previously logged in via [login]. The [user] property now references a new device-scoped user. A device-scoped user has no user identity that can later be retrieved, except through this device as long as the app remains installed and the app data is not cleared.* |
158-
| `var consent = await OneSignal.shared.getPrivacyConsent();`<br><br>`OneSignal.shared.setPrivacyConsent(true);` | *Indicates whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections. See [requiresPrivacyConsent].* |
159-
| `OneSignal.shared.setRequiresPrivacyConsent(true);` | *Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to `true` prior to the invocation of `initialize` to ensure compliance.* |
157+
| `OneSignal.shared.logout();` | *Logout the user previously logged in via [login]. The [user] property now references a new device-scoped user. A device-scoped user has no user identity that can later be retrieved, except through this device as long as the app remains installed and the app data is not cleared.* | |
158+
| `OneSignal.shared.setConsentRequired(true);` | *Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to `true` prior to the invocation of `initialize` to ensure compliance.*
159+
|
160+
| `OneSignal.shared.setConsentGiven(true);` | *Sets whether a user has consented to privacy prior to their user data being sent up to OneSignal. * |
160161
| `OneSignal.shared.setLaunchURLsInApp(true);` | *(iOS only) This method can be used to set if launch URLs should be opened in safari or within the application. Set to `true` to launch all notifications with a URL in the app instead of the default web browser. Make sure to call `setLaunchURLsInApp` before the `initialize` call.* |
161162
| `OneSignal.shared.enterLiveActivity("ACTIVITY_ID", "TOKEN");`<br><br>***See below for usage of callbacks***|*(iOS only) Entering a Live Activity associates an `activityId` with a live activity temporary push `token` on OneSignal's server. The activityId is then used with the OneSignal REST API to update one or multiple Live Activities at one time.* |
162163
| `OneSignal.shared.exitLiveActivity("ACTIVITY_ID");`<br><br>***See below for usage of callbacks*** |*(iOS only) Exiting a Live activity deletes the association between a customer defined `activityId` with a Live Activity temporary push `token` on OneSignal's server.* |

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,10 @@ public boolean onViewDestroy(FlutterNativeView flutterNativeView) {
109109
public void onMethodCall(MethodCall call, Result result) {
110110
if (call.method.contentEquals("OneSignal#initialize"))
111111
this.initWithContext(call, result);
112-
else if (call.method.contentEquals("OneSignal#requiresPrivacyConsent"))
113-
replySuccess(result, OneSignal.getRequiresPrivacyConsent());
114-
else if (call.method.contentEquals("OneSignal#setRequiresPrivacyConsent"))
115-
this.setRequiresPrivacyConsent(call, result);
116-
else if (call.method.contentEquals("OneSignal#getPrivacyConsent"))
117-
replySuccess(result, OneSignal.getPrivacyConsent());
118-
else if (call.method.contentEquals("OneSignal#setPrivacyConsent"))
119-
this.setPrivacyConsent(call, result);
112+
else if (call.method.contentEquals("OneSignal#consentRequired"))
113+
this.setConsentRequired(call, result);
114+
else if (call.method.contentEquals("OneSignal#consentGiven"))
115+
this.setConsentGiven(call, result);
120116
else if (call.method.contentEquals("OneSignal#login"))
121117
this.login(call, result);
122118
else if (call.method.contentEquals("OneSignal#loginWithJWT"))
@@ -133,13 +129,13 @@ private void initWithContext(MethodCall call, Result reply) {
133129
replySuccess(reply, null);
134130
}
135131

136-
private void setRequiresPrivacyConsent(MethodCall call, Result reply) {
132+
private void setConsentRequired(MethodCall call, Result reply) {
137133
boolean required = call.argument("required");
138134
OneSignal.setRequiresPrivacyConsent(required);
139135
replySuccess(reply, null);
140136
}
141137

142-
private void setPrivacyConsent(MethodCall call, Result reply) {
138+
private void setConsentGiven(MethodCall call, Result reply) {
143139
boolean granted = call.argument("granted");
144140
OneSignal.setPrivacyConsent(granted);
145141
replySuccess(reply, null);

example/lib/main.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class _MyAppState extends State<MyApp>
3636
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
3737

3838
OneSignal.Debug.setAlertLevel(OSLogLevel.none);
39-
OneSignal.shared.setRequiresPrivacyConsent(_requireConsent);
39+
OneSignal.shared.consentRequired(_requireConsent);
4040

4141
// NOTE: Replace with your own app ID from https://www.onesignal.com
4242
OneSignal.shared.initialize("77e32082-ea27-42e3-a898-c72e141824ef");
@@ -100,10 +100,8 @@ class _MyAppState extends State<MyApp>
100100
// iOS-only method to open launch URLs in Safari when set to false
101101
OneSignal.shared.setLaunchURLsInApp(false);
102102

103-
bool requiresConsent = await OneSignal.shared.requiresPrivacyConsent();
104-
105103
this.setState(() {
106-
_enableConsentButton = requiresConsent;
104+
_enableConsentButton = _requireConsent;
107105
});
108106

109107
// Some examples of how to use In App Messaging public methods with OneSignal SDK
@@ -182,7 +180,7 @@ class _MyAppState extends State<MyApp>
182180

183181
void _handleConsent() {
184182
print("Setting consent to true");
185-
OneSignal.shared.setPrivacyConsent(true);
183+
OneSignal.shared.consentGiven(true);
186184

187185
print("Setting state");
188186
this.setState(() {

ios/Classes/OneSignalPlugin.m

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
7979
[self login:call withResult:result];
8080
else if ([@"OneSignal#login" isEqualToString:call.method])
8181
[self logout:call withResult:result];
82-
else if ([@"OneSignal#getPrivacyConsent" isEqualToString:call.method])
83-
result(@(OneSignal.getPrivacyConsent));
84-
else if ([@"OneSignal#setPrivacyConsent" isEqualToString:call.method])
85-
[self setPrivacyConsent:call withResult:result];
86-
else if ([@"OneSignal#requiresPrivacyConsent" isEqualToString:call.method])
87-
result(@(OneSignal.requiresPrivacyConsent));
88-
else if ([@"OneSignal#setRequiresPrivacyConsent" isEqualToString:call.method])
89-
[self setRequiresPrivacyConsent:call withResult:result];
82+
else if ([@"OneSignal#consentRequired" isEqualToString:call.method])
83+
[self setConsentRequired:call withResult:result];
84+
else if ([@"OneSignal#consentGiven" isEqualToString:call.method])
85+
[self setConsentGiven:call withResult:result];
9086
else if ([@"OneSignal#setLaunchURLsInApp" isEqualToString:call.method])
9187
[self setLaunchURLsInApp:call withResult:result];
9288
else if ([@"OneSignal#enterLiveActivity" isEqualToString:call.method])
@@ -118,15 +114,15 @@ - (void)logout:(FlutterMethodCall *)call withResult:(FlutterResult)result{
118114

119115
#pragma mark Privacy Consent
120116

121-
- (void)setPrivacyConsent:(FlutterMethodCall *)call withResult:(FlutterResult)result{
117+
- (void)setConsentGiven:(FlutterMethodCall *)call withResult:(FlutterResult)result{
122118
BOOL granted = [call.arguments[@"granted"] boolValue];
123-
[OneSignal setPrivacyConsent:granted];
119+
[OneSignal setConsentGiven:granted];
124120
result(nil);
125121
}
126122

127-
- (void)setRequiresPrivacyConsent:(FlutterMethodCall *)call withResult:(FlutterResult)result{
123+
- (void)setConsentRequired:(FlutterMethodCall *)call withResult:(FlutterResult)result{
128124
BOOL required = [call.arguments[@"required"] boolValue];
129-
[OneSignal setRequiresPrivacyConsent:required];
125+
[OneSignal setConsentRequired:required];
130126
result(nil);
131127
}
132128

0 commit comments

Comments
 (0)