From a5498b0c126416d5e77f7e3e7030467fdbf2492f Mon Sep 17 00:00:00 2001 From: Nan Date: Tue, 14 Nov 2023 12:38:45 -0800 Subject: [PATCH 1/3] add getTags public method * Add `getTags` public method that will return local tags for the current user * Rename an existing internal `getTags` method used for IAM processing by appending the internal keyword. I chose not to combine these two methods as one may be called without privacy consent while the public one should be guarded for privacy consent. --- .../OneSignalInAppMessages/UI/OSInAppMessageView.m | 2 +- .../Source/OneSignalUserManagerImpl.swift | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageView.m b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageView.m index 26423c762..f89832c43 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageView.m +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageView.m @@ -53,7 +53,7 @@ - (instancetype _Nonnull)initWithMessage:(OSInAppMessageInternal *)inAppMessage - (NSString *)getTagsString { NSError *error; - NSDictionary *tags = [OneSignalUserManagerImpl.sharedInstance getTags]; + NSDictionary *tags = [OneSignalUserManagerImpl.sharedInstance getTagsInternal]; if (tags == nil || tags.count <= 0 ) { [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"[getTagsString] no tags found for the player"]; return nil; diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index cf694a1b4..f58aa1208 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -58,6 +58,7 @@ import OneSignalNotifications func addTags(_ tags: [String: String]) func removeTag(_ tag: String) func removeTags(_ tags: [String]) + func getTags() -> [String: String] // Email func addEmail(_ email: String) func removeEmail(_ email: String) @@ -466,7 +467,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { } @objc - public func getTags() -> [String: String]? { + public func getTagsInternal() -> [String: String]? { guard let user = _user else { return nil } @@ -661,6 +662,13 @@ extension OneSignalUserManagerImpl: OSUser { user.removeTags(tags) } + public func getTags() -> [String: String] { + guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "getTags") else { + return [:] + } + return user.propertiesModel.tags + } + public func addEmail(_ email: String) { guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "addEmail") else { return From 5a253b9ec51a9e6ac486edf2438c4763fd1908d8 Mon Sep 17 00:00:00 2001 From: Nan Date: Tue, 14 Nov 2023 12:43:45 -0800 Subject: [PATCH 2/3] add getTags method to migration guide --- MIGRATION_GUIDE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index 438cb08f5..c1bd170a7 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -331,6 +331,7 @@ The User name space is accessible via `OneSignal.User` and provides access to us | `OneSignal.User.addTag(key: "KEY", value: "VALUE")` | `[OneSignal.User addTagWithKey:@"KEY" value:@"VALUE"]` | *Add a tag 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.* | | `OneSignal.User.addTags(["KEY_01": "VALUE_01", "KEY_02": "VALUE_02"])` | `[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.* | | `OneSignal.User.removeTag("KEY")` | `[OneSignal.User removeTag:@"KEY"]` | *Remove the data tag with the provided key from the current user.* | +| `let tags = OneSignal.User.getTags()` | `NSDictionary *tags = [OneSignal.User getTags]` | *Returns the local tags for the current user.* | | `OneSignal.User.removeTags(["KEY_01", "KEY_02"])` | `[OneSignal.User removeTags:@[@"KEY_01", @"KEY_02"]]` | *Remove multiple tags with the provided keys from the current user.* | From 494ad470059592c045221ddfe4bb3d2960bce4ea Mon Sep 17 00:00:00 2001 From: Nan Date: Tue, 14 Nov 2023 12:29:02 -0800 Subject: [PATCH 3/3] [dev app] add get tags button --- .../Base.lproj/Main.storyboard | 18 ++++++------- .../OneSignalDevApp/ViewController.h | 2 +- .../OneSignalDevApp/ViewController.m | 5 ++-- .../Base.lproj/Main.storyboard | 26 +++++++++---------- .../OneSignalDevAppClip/ViewController.h | 2 +- .../OneSignalDevAppClip/ViewController.m | 5 ++-- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard index 721f61058..9b87b6079 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -20,7 +20,7 @@ - + @@ -43,9 +43,9 @@ - + - +