adaptyteam / AdaptySDK-Unity

Unity SDK for growing mobile in-app purchases
https://docs.adapty.io/docs/quickstart
MIT License
50 stars 4 forks source link

Failed to invoke callback System.Action #5

Closed OlegGrizzly closed 1 year ago

OlegGrizzly commented 1 year ago

Hi, when calling the GetPurchaserInfo method, I get the error: "Failed to invoke callback System.Action`1[System.String] with arg {"success":{"access_levels":{},"subscriptions":{},"non_subscriptions":{},"profile_id":"07d28733-8695-4663-ba6a-22e505df02c7"}}: Exception has been thrown by the target of an invocation. --> The given key 'premium' was not present in the dictionary."

Also sometimes there is an error with Make Purchase and RestorePurchases: "Failed to invoke callback System.Action`1[System.String] with arg {"error":{"code":2,"message":"The operation couldn’t be completed. (SKErrorDomain error 2.)","adapty_code":2,"domain":"SKErrorDomain"}}: Exception has been thrown by the target of an invocation. --> Object reference not set to an instance of an object. Stacktrace is not supported on this platform."

Unity 2021.3.3f1, Cocoapods Adapt 1.17.6, Unity Plugin 1.0.1, iOS 15.3.1

x401om commented 1 year ago

Hi, @OlegGrizzly! Looks like something from within your completion blocks throws an exception. For example, as I see, you have an empty AccessLevels dictionary and you trying to get the value by the key 'premium', which leads to the KeyNotFoundException. I think you should try to use the TryGetValue method or check the key existence before.

Adapty.AccessLevelInfo accessLevel;
if (purchaserInfo != null && purchaserInfo.AccessLevels != null && purchaserInfo.AccessLevels.TryGetValue("premium", out accessLevel)) {
    var isActive = accessLevel.IsActive;
    // grant the access if active
}
OlegGrizzly commented 1 year ago

I already tried this method but i always get null.  when there is even a subscription.

Отправлено из мобильной Почты Mail.ru

Monday 18 July 2022 at 17:11 +0900 from @. @.>:

Hi, @OlegGrizzly ! Looks like something from within your completion blocks throws an exception. For example, as I see, you have an empty AccessLevels dictionary and you trying to get the value by the key 'premium', which leads to the KeyNotFoundException. I think you should try to use the TryGetValue method or check the key existence before. Adapty.AccessLevelInfo accessLevel; if (purchaserInfo != null && purchaserInfo.AccessLevels != null && purchaserInfo.AccessLevels.TryGetValue("premium", out accessLevel)) { var isActive = accessLevel.IsActive; // grant the access if active }

— Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you were mentioned. Message ID: <adaptyteam/AdaptySDK-Unity/issues/5/1186898040 @ github . com>

x401om commented 1 year ago

Could you please print all the purchaserInfo object? There should be a non-empty Subscriptions dictionary, in case you did some successful purchases before.