OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

[question]: deleteTag and sendTags not working (After OneSignal sdk update from 4.8.6 -> 5.1.13 version)

Open simranthakkar1996 opened this issue 1 year ago • 2 comments

How can we help?

We decided to update oneSignal from 4.. version to 5.. version Facing some issue around OneSignal Tag In 5.. version sendTag and deleteTag doesn't seem to work.

Its giving "Cannot resolve method 'sendTags' in 'OneSignal'" error Downgrading to 4.. version resolves the issue though.

Also I checked the decompiled stub file, it seems that the methods provided in the OneSignal object do not explicitly show a deleteTag/sendTags method.

Thank you for al the help

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

simranthakkar1996 avatar May 21 '24 16:05 simranthakkar1996

@simranthakkar1996 These tag methods as well as most of the OneSignal methods have been renamed in the 5.0.0 major release. For example OneSignal.sendTag is now OneSignal.User.addTag.

Please see the full migration guide for all the methods and behavior that has changed: https://github.com/OneSignal/OneSignal-Android-SDK/blob/user-model/main/MIGRATION_GUIDE.md

jkasten2 avatar May 21 '24 20:05 jkasten2

I have one question @jkasten2 So we want to iterate through all the tags we retrieve Iterator<String> keys = tags.keys() that retrieves the keys of a JSON object (tags variable) and creates an iterator to iterate over those keys. Inside the while loop, each key is retrieved using keys.next(), and then OneSignal.getUser().removeTag(key) is called to remove the corresponding tag. So to get the keys of the tags variable there is not alternative in this update to handle that scenario.

OneSignal.getUser().getTags(tags -> {
            if (tags != null) {
                Iterator<String> keys = tags.keys(); ---------> This is not possible in this version 
                while (keys.hasNext()) {
                    String key = keys.next();
                    OneSignal.getUser().removeTag(key);
                }
            }
        });

simranthakkar1996 avatar May 22 '24 14:05 simranthakkar1996

getTags() no longer takes a callback, it just returns the tags now. So you can simply do this now if you want to delete all tags for the User.

OneSignal.getUser().removeTags(
   OneSignal.getUser().getTags().keySet()
);

jkasten2 avatar May 24 '24 05:05 jkasten2