Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] How do I test iOS Leaderboards?

Discussion in 'Getting Started' started by jshrek, Mar 28, 2015.

  1. jshrek

    jshrek

    Joined:
    Mar 30, 2013
    Posts:
    220
    I have Game Center authentication set up in my game, and I have a leaderboard added in iTunes Connect and have also enabled it on the main page of the app in iTunes Connect.

    I can test my game in Xcode simulator or on attached device and everything checks out except I cannot figure out how to test the leaderboards.

    On the device I tried logging in to Game Center with both a real Apple ID and a Test User Apple ID, but I still get failed authentication.

    Here is code I call from Start() (assumes you have using UnityEngine.SocialPlatforms; )

    Code (CSharp):
    1. Social.localUser.Authenticate ( success => { if (success) { Debug.Log("==iOS GC authenticate ok"); } else { Debug.Log("==iOS GC authenticate Failed"); } } );
    It comes back OK in the Unity Editor which I assume is supposed to happen so you can test it, but of course you cannot submit anything because you are not really authenticated.

    In Xcode simulator and real device it always comes back FAILED, even when I log in to Game Center on the device or simulator before I start the game.

    Thanks
     
  2. jshrek

    jshrek

    Joined:
    Mar 30, 2013
    Posts:
    220
    Okay well I finally got it to work in the Xcode Simulator only (not on a device), but that is okay for testing to make sure it is working. Here is what I did...

    iTunes Connect
    (1) In iTunes Connect setup a Test User by going to Users and Roles > Sandbox Testers tab > Add (little round + sign).

    (2) In iTunes Connect create your app and setup/add Leaderboard under the apps Game Center tab.

    (3) In iTunes Connect on your apps main page, make sure you slide the Game Center slider to ON and then click the little round blue plus sign and add the Leaderboard you just created and then click SAVE.

    UNITY
    (4) In Unity at the top of your main script add:
    Code (CSharp):
    1. using UnityEngine.SocialPlatforms;
    (5) In this same script in void Start() add:
    Code (CSharp):
    1.     Social.localUser.Authenticate ( success => { if (success) { Debug.Log("==iOS GC authenticate OK"); } else { Debug.Log("==iOS GC authenticate Failed"); } } );
    2.  
    (6) In this same script you can report the score from your game over method (or from wherever you want) with something like this:
    Code (CSharp):
    1. int score = 50; //This is just a test value. You would probably pass score into this method.
    2.  
    3. string iOS_LeaderboardID = "com.me.myself.Leaderboard"; //Same as Leaderboard ID you setup in iTunes Connect.
    4.  
    5. bool isGCAuthenticated = Social.localUser.authenticated;
    6.  
    7. if (isGCAuthenticated) {
    8.     Social.ReportScore(score, iOS_LeaderboardID, success => { if (success) { Debug.Log("==iOS GC report score ok: "+score+"\n"); } else { Debug.Log("==iOS GC report score Failed: "+iOS_LeaderboardID+"\n"); } } );
    9.  
    10. } else {
    11.     Debug.Log("==iOS GC can't report score, not authenticated\n");
    12.  
    13. }
    (7) In the Player Settings make sure you have iOS platform selected and then in the
    Player Settings > Other Settings > Optimization > SDK Version > set it to Simulator SDK.

    (8) Not sure if the following step is required, but in Player Settings I also have the following set:
    Other Settings > Identification > Bundle Identifier > set to match the Bundle ID used in iTunes Connect.
    Other Settings > Configuration > Scripting Backend > set it to IL2CPP

    (9) BUILD to create Xcode project.

    XCODE
    (10) Open your project in Xcode and select the Build Settings tab and go to Code Signing > Code Signing Identity and choose the iPhone Distribution that corresponds to the same user/company of your iTunes Connect account where you created the app.

    (11) Select the simulator test device you want to use and press Play button.

    (12) App should start playing and the Game Center login should pop up. Login using the Test User you created in the Sandbox Testers in iTunes Connect.

    (13) Play your game until the game over portion where it will report the score.

    (14) From the Simulator drop down menus choose the Hardware > Home.

    (15) Find the Game Center app icon, click it and you should be able to see the score you reported from your app.
     
    correia55 likes this.
  3. pokeking

    pokeking

    Joined:
    May 13, 2015
    Posts:
    42
    I followed your tutorial, and built in real device. I logged in successfull in Game Center in game with test acc reg in Sandbox, but it show "No Leaderboard". Do i need some steps to show it?
    Beside that, the status of leaderboard in Game Center (iTune) is "Not Live". I don't know how to change it, please help me.
    And do i need submit game to store, or i can test it when "Prepare for submission" ?
     
  4. Emmanuel_Charon

    Emmanuel_Charon

    Joined:
    Jul 22, 2015
    Posts:
    4
    Same problem for me; has anyone solved it?
     
  5. unicoea

    unicoea

    Joined:
    Feb 18, 2013
    Posts:
    60