pusher / push-notifications-android

Android SDK for Pusher Beams
https://www.pusher.com/beams
MIT License
21 stars 22 forks source link

setSubscriptions not working as expected #57

Closed hottmanmichael closed 5 years ago

hottmanmichael commented 5 years ago

This works as expected and the event is seen in the Pusher debug console.

...
import com.pusher.pushnotifications.PushNotifications;
...

 @Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PushNotifications.start(getApplicationContext(), "omitted-instance-id");
        PushNotifications.subscribe("debug-test");
        // Pusher debug-console event is logged     
       Log.i("Interests", PushNotifications.getInterests().toString()); // prints: Interests ["debug-test"]  
}

This does not have the same effect and doesn't seem to subscribe to the interests passed in

...
import com.pusher.pushnotifications.PushNotifications;
...

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PushNotifications.start(getApplicationContext(), "omitted-instance-id");
        Set interests = new HashSet();
        String interest = "debug-test";
        set.add(interest);
        PushNotifications.setSubscriptions(interests);
        // Pusher debug-console event is NOT logged 
       Log.i("Interests", PushNotifications.getInterests().toString()); // // prints: Interests []  
}

Both of these are using

compile 'com.google.firebase:firebase-core:16.0.1'
compile 'com.google.firebase:firebase-messaging:17.1.0'
compile 'com.pusher:push-notifications-android:1.0.1'

My intention is to use this with a React Native project, and my experience of Java is limited so I could very well be doing this wrong, however I first noticed this with the following.

@ReactMethod
public void setSubscriptions(ReadableArray interests, 
                Callback errorCallback, 
                Callback successCallback) {
        Set interestsAsSet = new HashSet(interests.toArrayList());
        Log.i("interestsAsSet", interestsAsSet.toString());
        try {
            PushNotifications.setSubscriptions(interestsAsSet);
            successCallback.invoke();
        } catch (IllegalViewOperationException e) {
            errorCallback.invoke(e.getMessage());
        }
        return;
}
rmartin48 commented 5 years ago

Also having this issue with a React Native project. Resorting to subscribe() as a workaround.

julioromano commented 5 years ago

I can confirm PushNotifications.setSubscriptions() is not working on v1.0.1.

60 fixes it.

luismfonseca commented 5 years ago

I've released version 1.0.2, please update to this one. We are working on refactoring the SDK and have included a test for this case.

I'm going to close issue this but feel free to reopen if there are still issues. Thanks everyone.