Codessional LLC
Codessional LLC

Reputation: 21

OSPermissionSubscriptionState : Cannot resolve symbol

I'm trying to add push notification to my mobile native chat app. I'm trying to use OneSignal.

I can send manual push notification, so I think gradle part is okay

idsAvaiable method is deprecated, I started to looking for how can I get userId.

OSPermissionSubscriptionState status = OneSignal.getPermissionSubscriptionState();
    String userId = status.getSubscriptionStatus().getUserId();

In here, I'm trying to get userId with status, but it's saying:

Cannot resolve symbol 'OSPermissionSubscriptionState'

How can I get userId?

Upvotes: 2

Views: 1840

Answers (1)

Son Truong
Son Truong

Reputation: 14173

Root cause

From OneSignal API 4.0.0, there are many APIs that have been removed including OSPermissionSubscriptionState.

Solution 1

Use OneSignal.getDeviceState()

OSDeviceState device = OneSignal.getDeviceState();
String userId = device.getUserId();

Solution 2

Use OneSignal.addSubscriptionObserver()

OneSignal.addSubscriptionObserver(new OSSubscriptionObserver() {

    @Override
    public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) {
        if (!stateChanges.getFrom().isSubscribed() && stateChanges.getTo().isSubscribed()) {
            // Get user id
            String userId = stateChanges.getTo().getUserId();
        }
    }
});

For more information, see the change log here.

Upvotes: 1

Related Questions