0

Is there an accepted way to tell if a user is logged into a Windows Universal App with a Microsoft Account as opposed to a Local Account?

I'm trying to implement in-app-purchases and I've hit a snag if CurrentApp::GetUnfulfilledConsumables() is called from a Local Account. An exception gets thrown with the message "The specific account does not exist."

A few people on the web are using the Live SDK to try to initialize the user's credentials, which would fail for non-Microsoft accounts. And in this way they have a roundabout way of figuring out if the user is logged in. (https://social.msdn.microsoft.com/Forums/en-US/f6946851-b495-45f6-95a4-eb3c2a004c0e/live-sdk-v53-how-to-tell-the-difference-between-a-user-logged-in-with-a-microsoft-account-and?forum=messengerconnect)

But I was wondering if there was a nicer, cleaner way to detect if a user is logged into a Microsoft Account or a Local account without having to integrate an entire SDK just for one function call.

Thanks for your help.

Kylaaa
  • 6,349
  • 2
  • 16
  • 27

1 Answers1

1

Unfortunately, the answer is that you need to put the call inside a try ... catch to catch the exception and then look at the exception->HResult to confirm that it's the "The specific account doesn't exist" exception. (And rethrow anything else.)

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • I would like to be able to have a safety check in place before making any calls to purchasing APIs. If I find something closer to what I'm looking for, I'll be sure to come back. Thank you for your suggestion though. – Kylaaa Feb 17 '16 at 00:00
  • How about making a silent call to `CurrentApp::GetUnfulfilledConsumables()` inside a `try..catch` and see if it raises an exception. If not, then you're good to enable your in-app-purchase UI. If it raises an exception, then in-app-purchases won't work and you can disable the UI. – Raymond Chen Feb 17 '16 at 01:56
  • Ultimately, the purchasing flow of my app has only two entry points: CurrentApp::PurchaseProduct() and CurrentApp::GetUnfulfilledConsumables(). Microsoft handles the case that a user is not logged into an account for PurchaseProduct(). So ultimately, your solution solved my problem, even if not in the way I would have hoped. If the call throws the an exception with an HResult with a string value equal to "-2147023579" we know it is because of "The specific account does not exist". Thank you Raymond. – Kylaaa Feb 17 '16 at 23:54