Search Unity

[Solved] UnauthorizedAccessException thrown during UnityPurchasing.Initialize() call on tvOS

Discussion in 'Unity IAP' started by MariaAngelovaPD, Dec 4, 2017.

Thread Status:
Not open for further replies.
  1. MariaAngelovaPD

    MariaAngelovaPD

    Joined:
    Jun 15, 2017
    Posts:
    25
    Using latest UnityPurchasing version 1.14.1. tvOS 11.2. Development build is run using XCode 9.2. Exception is present in the logs every time the app starts.
    We are able to read the local receipt and make purchases regardless of the exception but I would like to know what effect it has and if there's a know cause/fix for it?
    The source code is pretty straight forward following the examples for integrating UnityPurchasing.
    Here's the log section describing the exception:
    Unable to cache IAP catalog: System.UnauthorizedAccessException: Access to the path "/Unity" is denied.
    at System.IO.DirectoryInfo..ctor (System.String path, Boolean simpleOriginalPath) [0x00000] in <filename unknown>:0
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0
    at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00000] in <filename unknown>:0
    at UnityEngine.Purchasing.UnityPurchasing.InstantiateCatalog (System.String storeName) [0x00000] in <filename unknown>:0
    at UnityEngine.Purchasing.UnityPurchasing.Initialize (IStoreListener listener, UnityEngine.Purchasing.ConfigurationBuilder builder) [0x00000] in <filename unknown>:0
    at UserIOS..ctor () [0x00000] in <filename unknown>:0
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I will research this tvOS issue and will reply when I have additional information.
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Does this happen on TestFlight for you also?
     
  4. MariaAngelovaPD

    MariaAngelovaPD

    Joined:
    Jun 15, 2017
    Posts:
    25
    No, it's not present in the device log when starting a TestFlight build.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  6. MariaAngelovaPD

    MariaAngelovaPD

    Joined:
    Jun 15, 2017
    Posts:
    25
    No, we haven't released just yet (but in a few day we will). We only get it when starting a build via XCode - on a tv device connected directly to the Mac or over the local network. If we see the exception after release I'll let you know.
    The exception is printed before returning from the UnityPurchasing.Initialize(this, builder) call regardless of if there's a receipt or not and if the game has ever run on this device and if the fullgame product has been purchased or not - it's always there. I've attached a log file generated with a development build with logging but the exception is there if running a master build as well.
    Here's also our startup code: an instance of this class is created as part of launching the app after the UnityEarlyTransactionObserver has been created, registered and added to the payment queue as you can see from the log:

    public class IAPSystemIOS : IStoreListener
    {
    private const string FullGameProductId = "fullgame";
    private const string FullGameProductId_iOS = "fullgame_iOS";
    private bool IsFullGameProductId(string productId)
    {
    return String.Equals(productId, FullGameProductId, StringComparison.Ordinal) ||
    String.Equals(productId, FullGameProductId_iOS, StringComparison.Ordinal);
    }

    private bool isTrial = true;
    private bool asyncOpInProgress = false;

    public IAPSystemIOS()
    {
    var module = StandardPurchasingModule.Instance();
    var builder = ConfigurationBuilder.Instance(module);

    InitIsTrial(builder);

    builder.AddProduct(FullGameProductId, ProductType.NonConsumable, new IDs() {
    {FullGameProductId_iOS, AppleAppStore.Name}
    });
    UnityPurchasing.Initialize(this, builder);
    D.Log("***** IAP: Initialize done.");
    }

    private void InitIsTrial(ConfigurationBuilder builder)
    {
    // Parse and validate app receipt and find out if full game is purchased:
    isTrial = true;
    IAppleConfiguration appleStoreConfig = builder.Configure<IAppleConfiguration>();
    D.Log("***** IAP: validating local receipt.");

    if (appleStoreConfig.appReceipt == null)
    return;

    try
    {
    var receiptData = System.Convert.FromBase64String(appleStoreConfig.appReceipt);
    if (receiptData == null)
    return;

    AppleReceipt receipt = new AppleValidator(AppleTangle.Data()).Validate(receiptData);
    if (receipt == null)
    return;

    foreach (AppleInAppPurchaseReceipt productReceipt in receipt.inAppPurchaseReceipts)
    {
    if (IsFullGameProductId(productReceipt.productID))
    isTrial = false;
    }
    }
    catch (IAPSecurityException ex)
    {
    }
    catch (ArgumentException ex)
    {
    }
    catch (FormatException ex)
    {
    }
    }
    ...
    }
     

    Attached Files:

  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Do you plan to test via TestFlight before release? Also what version of Unity are you using?
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I believe Application.persistentDataPath is not usable on tvOS, which is where cloud catalog tries to cache. Also, keep in mind that cloud catalog is not available on tvOS.
     
  9. MariaAngelovaPD

    MariaAngelovaPD

    Joined:
    Jun 15, 2017
    Posts:
    25
    We are testing using TestFlight and the exception is not there in TestFlight builds.
    What is cloud catalog and how does it relate to UnityPurchasing initialization? Are we using that intrinsically somehow?
    Our code is straight forward, very close to the unity docs and manuals, we have one non-consumable in-app-purchase. I don't know of Application.persistentDataPath, we aren't using that in any way in our code. Is it used inside UnityPurchasing code?
     
  10. MariaAngelovaPD

    MariaAngelovaPD

    Joined:
    Jun 15, 2017
    Posts:
    25
    We are using a in-house modified version of Unity 5.6.4p3
     
  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    In that case, you can safely ignore the error. Are you able to test with a newer version of Unity? I will check with the team here to see why you might be triggering Cloud Catalog.
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I checked with the team here and confirmed that you can safely ignore the error. Apparently the tvOS platform behaves a bit differently in this regard, and we should be addressing this in an upcoming release.
     
  13. MariaAngelovaPD

    MariaAngelovaPD

    Joined:
    Jun 15, 2017
    Posts:
    25
    Ok. thanks.
     
Thread Status:
Not open for further replies.