Skip to content

Commit 2d07082

Browse files
authored
Merge pull request #804 from OneSignal/feat/getTags
[Feature] Get tags
2 parents eb6ea37 + e9e82b1 commit 2d07082

File tree

7 files changed

+33
-3
lines changed

7 files changed

+33
-3
lines changed

MIGRATION_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ The User name space is accessible via `OneSignal.User` and provides access to us
221221
| `OneSignal.User.addTags({"KEY_01": "VALUE_01", "KEY_02": "VALUE_02"});` | *Add multiple tags for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here.* |
222222
| `OneSignal.User.removeTag("KEY");` | *Remove the data tag with the provided key from the current user.* |
223223
| `OneSignal.User.removeTags(["KEY_01", "KEY_02"]);` | *Remove multiple tags with the provided keys from the current user.* |
224-
224+
| `OneSignal.User.getTags();` | *Returns the local tags for the current user.* |
225225

226226

227227
## Push Subscription Namespace

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ android {
3434
}
3535

3636
dependencies {
37-
implementation 'com.onesignal:OneSignal:5.0.4'
37+
implementation 'com.onesignal:OneSignal:5.0.5'
3838
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ else if (call.method.contentEquals("OneSignal#addTags"))
4848
this.addTags(call, result);
4949
else if (call.method.contentEquals("OneSignal#removeTags"))
5050
this.removeTags(call, result);
51+
else if (call.method.contentEquals("OneSignal#getTags"))
52+
this.getTags(call, result);
5153
else
5254
replyNotImplemented(result);
5355
}
@@ -124,4 +126,8 @@ private void removeTags(MethodCall call, Result result) {
124126
replyError(result, "OneSignal", "deleteTags failed with error: " + e.getMessage() + "\n" + e.getStackTrace(), null);
125127
}
126128
}
129+
130+
private void getTags(MethodCall call, Result result) {
131+
replySuccess(result, OneSignal.getUser().getTags());
132+
}
127133
}

example/lib/main.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ class _MyAppState extends State<MyApp> {
132132
OneSignal.User.removeTags(['test']);
133133
}
134134

135+
void _handleGetTags() async {
136+
print("Get tags");
137+
138+
var tags = await OneSignal.User.getTags();
139+
print(tags);
140+
}
141+
135142
void _handlePromptForPushPermission() {
136143
print("Prompting for Permission");
137144
OneSignal.Notifications.requestPermission(true);
@@ -262,6 +269,10 @@ class _MyAppState extends State<MyApp> {
262269
new OneSignalButton(
263270
"Send Tags", _handleSendTags, !_enableConsentButton)
264271
]),
272+
new TableRow(children: [
273+
new OneSignalButton(
274+
"Get Tags", _handleGetTags, !_enableConsentButton)
275+
]),
265276
new TableRow(children: [
266277
new OneSignalButton("Prompt for Push Permission",
267278
_handlePromptForPushPermission, !_enableConsentButton)

ios/Classes/OSFlutterUser.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
5555
[self addTags:call withResult:result];
5656
else if ([@"OneSignal#removeTags" isEqualToString:call.method])
5757
[self removeTags:call withResult:result];
58+
else if ([@"OneSignal#getTags" isEqualToString:call.method])
59+
[self getTags:call withResult:result];
5860
else if ([@"OneSignal#addEmail" isEqualToString:call.method])
5961
[self addEmail:call withResult:result];
6062
else if ([@"OneSignal#removeEmail" isEqualToString:call.method])
@@ -102,6 +104,10 @@ - (void)removeTags:(FlutterMethodCall *)call withResult:(FlutterResult)result {
102104
result(nil);
103105
}
104106

107+
- (void)getTags:(FlutterMethodCall *)call withResult:(FlutterResult)result {
108+
result([OneSignal.User getTags]);
109+
}
110+
105111
- (void)addEmail:(FlutterMethodCall *)call withResult:(FlutterResult)result {
106112
NSString *email = call.arguments;
107113
[OneSignal.User addEmail:email];

ios/onesignal_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
1313
s.source_files = 'Classes/**/*'
1414
s.public_header_files = 'Classes/**/*.h'
1515
s.dependency 'Flutter'
16-
s.dependency 'OneSignalXCFramework', '5.0.4'
16+
s.dependency 'OneSignalXCFramework', '5.0.5'
1717
s.ios.deployment_target = '11.0'
1818
s.static_framework = true
1919
end

lib/src/user.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ class OneSignalUser {
7777
return await _channel.invokeMethod("OneSignal#removeTags", tags);
7878
}
7979

80+
/// Returns the local tags of the current user.
81+
Future<Map<String, String>> getTags() async {
82+
Map<dynamic, dynamic> tags =
83+
await _channel.invokeMethod("OneSignal#getTags");
84+
return tags.cast<String, String>();
85+
}
86+
8087
/// Add a new [email] subscription to the current user.
8188
Future<void> addEmail(String email) async {
8289
return await _channel.invokeMethod("OneSignal#addEmail", email);

0 commit comments

Comments
 (0)