Search code examples
c#uwpwin-universal-appxbox-onexbox-live

How can a UWP/C# app sign in an XBox user and display gamertag?


I am trying to resubmit a UWP app (written in C#/XAML) into the Microsoft store so that it supports "Windows 10 Xbox" in addition to the previously supported Windows Desktop and Windows Phone. I can deploy (using Visual Studio 2017) and run the app on my Xbox One console in Developer Mode with no problems. When I submit to the store, I get the following error:

Because your game uses Xbox Live, it must:
· Create at least one active user and sign the user into Xbox.
· Display the user’s Xbox gamertag as the primary display and profile name.

Please add this behavior and resubmit your game.

I am looking for a minimal C#/XAML example that shows me how to solve this submission problem.

The post on "Accessing Raw Gamer Profile Picture" seems to indicate that I can take care of the login by doing something like this:

if (App is running on Xbox)
{
    XboxLiveUser user = new XboxLiveUser();
    SignInResult result = await user.SignInAsync(); 
}

but I'm not sure if this is correct, or how I would determine that the app is running on Xbox.

Also, I would like to know how and where I am supposed to display the user's gamertag. Can I just display it anywhere in the XAML? Alternatively, is there some special Xbox api I need to call to display this?

In short, I need a very simple C#/XAML example that shows how to do the minimal requirements of checking to see if the app is running on Xbox, logging in the user, and then displaying the user's gamertag in the appropriate place, so that I satisfy the Microsoft Store requirements.

Update: I did the following:

Using Nuget Package Manager, I installed Microsoft.Xbox.Live.SDK.WinRT.UWP\

In the project, I created an xboxservices.config file following Section 6 of these instructions

I created a TextBlock control at upper left side of my screen, and passed it in to the following function to display the gamertag:

public static async void InitializeXboxGamer(TextBlock gamerTagTextBlock)
{
    if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily.Contains("Xbox"))
    {
        XboxLiveUser user = new XboxLiveUser();
        SignInResult result = await user.SignInSilentlyAsync(Window.Current.Dispatcher);
        if (result.Status == SignInStatus.UserInteractionRequired)
        {
            result = await user.SignInAsync(Window.Current.Dispatcher);
        }
        gamerTagTextBlock.Text = user.Gamertag;
        gamerTagTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
    }
    else
    {
        gamerTagTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
    }
}

However, this still failed to pass submission tests with the following error:

App Policies: 10.13.5 Xbox Live Active User and Gamertag

Notes To Developer

Because your game uses Xbox Live, it must: · Create at least one active user and sign the user into Xbox. · Display the user’s Xbox gamertag as the primary display and profile name. Please add this behavior and resubmit your game. You can view the Xbox Live documentation for more information. Your game may not appear in the Creators Collection until this has been resolved.

Tested Devices: Windows 10 Desktop, Windows 10 Xbox

Any ideas on what I'm doing wrong here?


Solution

  • After much research, and reviewing the helpful answers above, I found out the following two ways to get a Windows Universal app to be approved by the Microsoft Store to work on Xbox One. The second method (see below) shows how to do this by displaying the gamertag in the application.

    To get the app approved for Xbox without using "Xbox Live" (and displaying the gamertag), you will need to go through the "Concept Approval" process. You can get started by filling out the ID@XBOX application

    Alternatively, you can get the app approved by integrating "Xbox Live" into your UWP application by doing the following to display the gamertag in your app:

    Make sure your project (right click on your project->Application) is set to a min version of "Windows 10 Creators Update (10.0; Build 15063)" and a Target version of "Windows 10 Fall Creators Update (10.0; Build 16299)" -- otherwise, the reference to "Microsoft.Xbox.Services.winmd" won't appear when you add the NuGet package below.

    Inside Visual Studio, use Nuget Package Manager, to add Microsoft.Xbox.Live.SDK.WinRT.UWP

    In your project, created an xboxservices.config file following Section 6 of these instructions.

    Create a TextBlock control to display the gamertag. In my case, I put it at upper left side of the app's screen, and passed it in to the following function to display the gamertag:

    public static async void InitializeXboxGamer(TextBlock gamerTagTextBlock)
    {
        try
        {
            XboxLiveUser user = new XboxLiveUser();
            SignInResult result = await user.SignInSilentlyAsync(Window.Current.Dispatcher);
            if (result.Status == SignInStatus.UserInteractionRequired)
            {
                result = await user.SignInAsync(Window.Current.Dispatcher);
            }
            gamerTagTextBlock.Text = user.Gamertag;
            gamerTagTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
        catch (Exception ex)
        {
            // TODO: log an error here
        }
    }
    

    I called this function at the end of my MainPage() constructor.

    You must call this function on all supported platforms (including Windows 10) to get store approval.

    Then, go to developer.windows.com, login, select your game, select "Services", select "Xbox Live", and click on the "Authorize Xbox Live Accounts for your Test Environment" so that you can test locally.

    Also, be sure to click on the "Test" button in the "Xbox Live" section.