Z
Z
Zimaell2021-02-21 21:42:14
Unity
Zimaell, 2021-02-21 21:42:14

What to do if PlayerPrefs are reset on the phone?

Data is created, saved and taken from me like this

public int AdsOff = 0;
/* --- вначале задаются --- */
if(!PlayerPrefs.HasKey("AdsOff")){
  PlayerPrefs.SetInt("AdsOff", AdsOff);
  PlayerPrefs.Save();
  }else AdsOff = PlayerPrefs.GetInt("AdsOff");
/* --- так при покупке они сохраняются ---*/
public void ProcessPurchase(string TypePurchase){
  switch(TypePurchase){
    case "EnAdsOff": PlayerPrefs.SetInt("AdsOff", 1); PlayerPrefs.Save(); break;
    .............................
    }
  }

When testing in the unit, everything works fine, I bought it, the data is saved, I opened a new test and the variable is already equal to 1 because I already bought it, everything is logical, everything is fine ....

But now I uploaded it to the working version on the Google market, downloaded ( there on another phone), installed, played all the rules, and now I made a purchase, for example, as in this example, I turned off ads, money was withdrawn, ads were turned off, everything seems to be ok .... but when I closed the application and went back into it, this the function is already disabled, as if it was not bought, that is, it turns out that PlayerPrefs are reset to zero or something, this is a problem, and I would say a big one ....
How to solve it and because of what this can be ???
(of course, I have suspended purchases in the game)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bogdan Erolskiy, 2021-02-22
@B-Erolskiy

I do not advise using ONLY PlayerPrefs as a way to save a purchase.
If the player buys with real money in the store, then UnityIAP has a great property of the Product (product) class - . hasReceiptwhich works with Subscription and Non Costumable products.
In my code, it is implemented like this: when buying, I save it in PlayerPrefs, and I check it like this: if there is an Internet connection, I request the receipt using . hasReceipt, otherwise I look in PlayerPrefs.
PlayerPrefs can be cleared by the user, also when updating or deleting the application, and the player paid for the purchase - here you have a dissatisfied buyer and a bad review

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question