// Modify payment request with "applicationUsername" for fraud detection
if (_applicationUsername != nil)
{
if ([payment respondsToSelector: @selector(setApplicationUsername:)])
{
UnityPurchasingLog(@"Setting applicationUsername to %@", _applicationUsername);
[payment performSelector: @selector(setApplicationUsername:) withObject: _applicationUsername];
//payment.applicationUsername = _applicationUsername;
}
}
[[SKPaymentQueue defaultQueue] addPayment: payment];
Line is commented out and in 299. line there is a function call to “setApplicationUsername” with parameter but there is no “setApplicationUsername” in project as far as i can see. I do not know what this language and I’m not sure if it is a function call but I call m_AppleExtensions.SetApplicationUsername and it does not return “app_account_token” on verifyReceipt call but it should return as responseBody.Latest_receipt_info | Apple Developer Documentation the documentation says it will return.
So, should we uncomment 300. line? Why is it commented out?
Hello,
You can read more about this in the Key-Value Coding Programming Guide, but in short, prefixing with “set” will use the setter of the property specified. In this case, this sets the ApplicationUsername.
Both the line 299 and 300 does the same thing, so this could be cleaned up, but the result is that it sets your ApplicationUsername.
After your call to SetApplicationUsername, did you make a purchase before verifying the receipt?
Hi, thank you for responding. Yes I have made a purchase and sent that purchase’s receipt (Unity IAP’s Payload data which is base64 encoded) to our server. Then our server makes verifyReceipt API call to Apple servers using that base64 encoded receipt.
I call SetApplicationUsername at initialization of Unity IAP. Then I make my purchases from UI which will be later than initialization. Did you try SetApplicationUsername with verifyReceipt API call? If it works for you then I will investigate further but please try with In App Purchasing 4.5.2.
Update: I try to set 64 characters string with that function, could this be the cause?
Are you using iOS 7 and above?
Do you see following log when making a purchase?
Setting applicationUsername to %@
On our side, we tested this and the call is properly made to Apple. After this, if their verifyReceipt doesn’t return it, this is an issue on Apple’s side.
Yes I’m using iOS 7 and above.
If this log is not a “Warning” type, I do not see this log. I have a console in my game that shows logs that are not Warnings.
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
LogToFile("In-App Purchasing successfully initialized");
m_StoreController = controller;
m_AppleExtensions = extensions.GetExtension<IAppleExtensions>();
if (m_AppleExtensions != null)
{
var obfuscatedAccountName = GetObfuscatedAccountName();
m_AppleExtensions.SetApplicationUsername(obfuscatedAccountName);
Debug.Log($"[BuyingConsumables] OnInitialized, m_AppleExtensions.SetApplicationUsername is called! obfuscatedAccountName: {obfuscatedAccountName}");
}
else Debug.LogError($"[BuyingConsumables] OnInitialized, m_AppleExtensions is null!");
UpdateUI();
}
I see [BuyingConsumables] OnInitialized, m_AppleExtensions.SetApplicationUsername is called! obfuscatedAccountName: {obfuscatedAccountName}
this debug message in my console.
Your code seems good for setting it, but you can confirm by checking your device logs for the line I mentioned.
It will only appear after making a purchase since it has to be set in the SKPayment (the code in your first post).
If that works, then the applicationUsername is correctly being sent to Apple