Search Unity

Handle iOS user not authenticated

Discussion in 'Unity IAP' started by ncortesp, Sep 19, 2018.

  1. ncortesp

    ncortesp

    Joined:
    Oct 28, 2016
    Posts:
    42
    When I try to purchase a "consumable" item (haven't tested others types since we just sell consumables) in iOS and I'm not authenticated a popup like this is comes up.



    If I do press cancel, OnPurchaseFailed is called with Unknown fail reason. That's a problem because I'm expecting an on UserCancel in this case.

    When It comes to Android the Purchaser never Initialises If I'm not authenticated with any Google Account, because it can't retrieve the products from the store, instead, I do retrieve them on iOS. ¿How can it be?

    ¿How can I handle this situation (iOS one)? Because If i'm logged with an iOS account, and I do cancel de purchase process (see the image below) I'm getting a UserCancel OnPurchaseFailed, which is correct.



    Greetings,
    Nacho.
     
  2. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    @ncortesp

    I'm sorry to hear you are experiencing this issue. The Errors that we display in OnPurchaseFailed comes directly from Apple. We have been working to ensure that all errors that are returned describe as much about what is going on as possible.

    I will put this to our IAP developers to see if there is a possibility of making the error communicate what is actually happening in this case.
     
    ncortesp likes this.
  3. ncortesp

    ncortesp

    Joined:
    Oct 28, 2016
    Posts:
    42
    Thank you Benvictus I do appreciate your help!
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please describe how you are using an Android device without an associated user account on the device.
     
  5. ncortesp

    ncortesp

    Joined:
    Oct 28, 2016
    Posts:
    42
    It's pretty simple. Log in with your Google account, go to the PlayStore and download whatever app you would like to. After that, log out from your account and launch the downloaded app, get into the shop and then try to purchase something.

    Some apps just block the access to the shop in this case, but in our case, we are giving free coins every X time in the shop, so we can't block the access.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please provide the steps you are using to "log into your Google account" on the Android device.
     
  7. ncortesp

    ncortesp

    Joined:
    Oct 28, 2016
    Posts:
    42
    Mobile -> Settings -> Accounts -> Add Account (Google).
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    That allows you to Add or Remove an account. How do you log off and still have access to the device? My Android devices require you to be logged in as a known user. Same for my iPhone. I don't have Mobile -> Settings on my Android devices, just the gear icon at the top of the screen, then Settings.
     
  9. ncortesp

    ncortesp

    Joined:
    Oct 28, 2016
    Posts:
    42
    I'm using a Samsung Galaxy A3 and I can remove all my Google Accounts from my device. If so, when I do open de GooglePlay I see this.



    If I get into my app this way I see this on PurchaseInit; OnInitializeFailed: PurchasingUnavailable

    So I can not retrieve the products.

    This is not happening when I do the same on iOS.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    It's my experience that an iOS device does not allow you to use the device without being logged on. All Android devices require the user to have an account on the device to use Google Play. Is your expectation that IAP will create the account on the device? With no account on a device, IAP is indeed unavailable. If you get this response, you could put up a dialog to inform the user that they need to be logged onto the device with a valid account. I should add that the next release available in a few weeks will have better error handling in addition to the default UserCancelled response. So you should be able to detect this specific condition, rather than just a user cancelling out of the purchase process.
     
    Last edited: Sep 25, 2018
  11. ncortesp

    ncortesp

    Joined:
    Oct 28, 2016
    Posts:
    42
    I don't expect IAP to create an account on the device. I'm just telling you that I can access to my shop (my app one) without an account logged in either Google or Apple.

    Btw, I'm currently showing a popup (in Android) asking the user to log with his google account, otherwise he won't be able to purchase in-app products. That's because of this OnInitializeFailed: PurchasingUnavailable, which is not happening in iOS, that's why I'm just handling this case in Android.

    I wish that I could see the same behaviour on iOS. But If I do get a UserCancelled when the user cancels instead of login with his account when they press an in-app product, it's enough.

    I will be really gratefull if this comes with the new version, this way I'll be able to give a better user experience.

    Thanks
     
  12. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Hi,

    Google Play and App Store have different behaviors on IAP initialization. Unity IAP tries to offer uniform APIs for both IAP systems, but couldn't change them.
    Since they're totally different IAP systems, we couldn't expect that they have the same logic.

    Regarding the PurchaseFailureReason in OnPurchaseFailed, Unknown is what the App Store returns. Unity IAP has no control over this.
    The error code returned from App Store is SKErrorUnknown. You can get it via ITransactionHistoryExtensions.GetLastStoreSpecificPurchaseErrorCode() and ITransactionHistoryExtensions.GetLastPurchaseFailureDescription() in C# code. Code example can be found in 'Assets\Plugins\UnityPurchasing\script\IAPDemo.cs'.

    The Objective-C source code of Unity IAP is 'Assets\Plugins\UnityPurchasing\iOS\UnityPurchasing.m'. The code of processing failed purchases is at line 410.
    You can set up some breakpoints and debug it in your Xcode.
    https://developer.apple.com/documentation/storekit/skerrorcode?language=objc
     
    ncortesp likes this.
  13. ncortesp

    ncortesp

    Joined:
    Oct 28, 2016
    Posts:
    42
    I wish they could change it, but I do have 0 expectations.

    Thanks anyway.