Skip to content

Commit cfffdce

Browse files
shepherd-lnan-li
authored andcommitted
Merge pull request #804 from OneSignal/feat/getTags
[Feature] Get tags
2 parents 40f7e92 + 346b5eb commit cfffdce

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
@@ -38,5 +38,5 @@ android {
3838
}
3939

4040
dependencies {
41-
implementation 'com.onesignal:OneSignal:5.0.4'
41+
implementation 'com.onesignal:OneSignal:5.0.5'
4242
}

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
@@ -140,6 +140,13 @@ class _MyAppState extends State<MyApp> {
140140
OneSignal.User.removeTags(['test']);
141141
}
142142

143+
void _handleGetTags() async {
144+
print("Get tags");
145+
146+
var tags = await OneSignal.User.getTags();
147+
print(tags);
148+
}
149+
143150
void _handlePromptForPushPermission() {
144151
print("Prompting for Permission");
145152
OneSignal.Notifications.requestPermission(true);
@@ -270,6 +277,10 @@ class _MyAppState extends State<MyApp> {
270277
new OneSignalButton(
271278
"Send Tags", _handleSendTags, !_enableConsentButton)
272279
]),
280+
new TableRow(children: [
281+
new OneSignalButton(
282+
"Get Tags", _handleGetTags, !_enableConsentButton)
283+
]),
273284
new TableRow(children: [
274285
new OneSignalButton("Prompt for Push Permission",
275286
_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)