Search Unity

Text not working on Unity 5.2.1f1 and iOS

Discussion in 'UGUI & TextMesh Pro' started by fred_gds, Oct 11, 2015.

  1. fred_gds

    fred_gds

    Joined:
    Sep 20, 2012
    Posts:
    184
    Hi there,

    I have a problem using UI text on iOS devices which run a firmware lower then iOS 9.0.2. As in my script I change the text of a few UI objects after I have initialized the StoreKit (using iOS Native).

    So on my iPhone 6 with iOS 9.0.2 this works really well. But on my iPad 2 (iOS 9.0.1) and iPhone 4S which still runs iOS 8 the Text objects are messed up. The text appears to be all over the screen just not where it is supposed to be. I tried to debug with this code:

    void Update()
    { Debug.Log(myText.text);}


    But this will return the correct text. Also I double checked the position and everything seems fine.

    The Error seems to be causes by the price I receive from the StoreKit. As on the iPhone 6 I receive "€0,99" and on the other devices I receive "0,99 €". But it does not make any sense to me why this would cause trouble. I can debug the string without any problem. And if I set the text on my own to "0,99 €" it will also work fine. But it does not work when i get it directly by this:

    IOSInAppPurchaseManager.Instance.Products[0].localizedPrice

    or this

    IOSInAppPurchaseManager.Instance.Products[0].localizedPrice.ToString()

    What could be inside the string I receive that brakes the UI text?

    So I was wondering whether anybody experienced anything similar or has an idea what causes the problem.

    Best regards,

    Fred


    EDIT: just tried unity 5.2.1p3 and it did not solve the problem

    EDIT2: I found out that the error seems to be due to the Font I am using ("BPreplay") as it works perfectly when using Arial. So I Converted the string to UTF8 format and no it returns "0,99??". So at least the text works now, but all my Euro symbols are gone. Also I noticed that on the iPhone 6 the Euro symbol gets replaced by only one questionmark while on the other devices it gets replaced with 2. Is there a way to reformat the string while preserving the currency symbol?
     
    Last edited: Oct 12, 2015
  2. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    I am 90% sure that your problem connected with the font.

    By the way if you just creating string like "0,99 €" and then assign this string to your text field, will it work fine in the editor?
    I just want to understand is you experiencing same issues on editor or on the device only?

    Cheers!
     
  3. fred_gds

    fred_gds

    Joined:
    Sep 20, 2012
    Posts:
    184
    Well if I enter 0,99 € my self it will work on any device. The problem seems to be caused by the string encoding of the string I get from the StoreKit in combination with the font I use. At least I think that it is the string encoding as with this code it will work fine (except that the euro symbols are gone):

    string n = IOSInAppPurchaseManager.Instance.GetProductById(removeAdsProductID).localizedPrice;
    byte[] bytes = Encoding.Default.GetBytes(n);
    n = Encoding.UTF8.GetString(bytes);
    But I am not able to tell what encoding the StoreKit returns. So Encoding.Default.GetBytes is unable to recognize the Euro symbols as such ...

    I can not say whether this will cause trouble in the editor as I do not use the StoreKit in the editor (not quite sure if can initiated it there).

    Yes the problem seems so be connected to the font as using the default Arial will not cause the problem, but the font I used just matched the game style very well I do not really want to redesign everything.
     
  4. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Can you try to use Price + CurrencySymbol instead of LocalizedPrice?
     
  5. fred_gds

    fred_gds

    Joined:
    Sep 20, 2012
    Posts:
    184
    Ok that solved the problem. Will the price always adapt to the region like the localized price?
     
  6. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    yep, it will.
     
  7. fred_gds

    fred_gds

    Joined:
    Sep 20, 2012
    Posts:
    184
    Perfect. Thank you :)