Search Unity

GameCenter authentication returns false + Crash when using error string callback

Discussion in 'iOS and tvOS' started by CaptainKiyaku, Jan 5, 2017.

  1. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Unity Version: 5.5.0f3
    XCode Version: 8.2.1
    iOS: 10

    We recently updated to Unity 5.5, mainly for some bug fixes and the new GC Authentication Callback returning error strings.

    However i seem to have problems authenticating now, it worked just fine before the update.

    To make things simpler, i created a test scene with following code:

    Code (CSharp):
    1. void Start () {
    2.         Social.localUser.Authenticate ((success, error) => {
    3.             Debug.Log ("GC Success: " + success);
    4.  
    5.             if (!string.IsNullOrEmpty (error)) {
    6.                 Debug.Log ("GC Error: " + error);
    7.             }
    8.         });
    9.     }
    When i run this, there are 2 results (in both cases, the GC popup says "Welcome back, [Username]!":
    • If i'm already logged into GC before launching the app, GC Success returns False and GC Error returns an empty string
    • If i logout of GC before launching the app and then login at the prompt, GC Success returns false and then the game crashes to this:


    Any idea why the error bit would crash and why the GC authentication returns false, even though i see myself logged in?
    Running out of ideas here so any tip would help!

    Thanks,
    Sven
     
    Last edited: Jan 6, 2017
  2. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Couple of new information:

    I created a new project with Unity 5.5 that only contains an empty scene with the above mentioned GameCenter test script.

    Two different results depending on the app ID:
    • if i use an app id that doesn't exist on itunesconnect AND i'm already logged in, GC Success always prints "true"
      • If i log out prior to launching the app and then enter my credentials on the popup, it tells me that there is no game associated with this app and im forced to cancel the GC login prompt (which then prints out GC Success: false, with the error message that the user cancelled, all good so far)
    • if i use an app id that does exist, it gets really weird. GC Success seems to cycle betwen true and false everytime i stop and run it through xcode. It's not exactly in a pattern, sometimes it says false a few times in a row, then true a few times, then false, etc. But never consistent.
    I also tried this with the 5.6 beta, same results.

    I then downgraded that same project back to 5.4.2, and using my proper app id it logs in 100% of the time.

    To me this seems like Unity 5.5 and up seems to have some issues with gamecenter. Those versions also use the new Authenticate method that can contain a string for error messages.

    Anyone else had any similar issues with this? Some config options i'm missing in Xcode or Unity?

    Thanks,
    Sven
     
  3. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    And some more discoveries!

    Like i mentioned above, the first GS Success can be either true or false, it seems really random.
    However i just set Authenticate on a loop. The first one is still random but every other call afterwards always returns true.

    Is it possible that there is a race condition bug going on with the Social Authenticate method?
     
    mahdie likes this.
  4. allergicracoon

    allergicracoon

    Joined:
    Nov 9, 2014
    Posts:
    2
    We're running into the same problem, also on Unity 5.5.0f3. It does seem like Social.localUser.authenticated does show the correct value, when checked from within the callback. That's how we solved it for now.
     
    _Adriaan likes this.
  5. spiller2002

    spiller2002

    Joined:
    Nov 2, 2016
    Posts:
    2
    Hi guys! Any news on this issue? We are experiencing the same problem with unity 5.5 and game center login process.
     
  6. OleSviper

    OleSviper

    Joined:
    Aug 26, 2016
    Posts:
    5
    We have the same problem, @CaptainKiyaku did you file a bug report for this?
     
  7. i9mobile

    i9mobile

    Joined:
    Aug 8, 2013
    Posts:
    54
    same problem here, it crashes when try to authenticate... tomorrow I'll try to remove the error string from the callback and try again.
     
  8. iamthejames

    iamthejames

    Joined:
    Mar 23, 2015
    Posts:
    7
    Same here. No crashes but Authenticate method returns true or false randomly.
     
  9. MigrantP

    MigrantP

    Joined:
    Jun 24, 2013
    Posts:
    119
  10. MigrantP

    MigrantP

    Joined:
    Jun 24, 2013
    Posts:
    119
    This was supposedly fixed in 5.6.0p1 but our beta testers are still getting game center related crashes.
     
  11. mansonet

    mansonet

    Joined:
    Jan 11, 2014
    Posts:
    8
    Same error here in 2017.1.0p5, did anyone find a workaround?
     
  12. i9mobile

    i9mobile

    Joined:
    Aug 8, 2013
    Posts:
    54
    I just removed the ErroString from the callback... It's not useful since the error messages are too generic.


    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class ExampleScript : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.         Social.localUser.Authenticate(success => {
    8.                 if (success)
    9.                 {
    10.                     Debug.Log("Authentication successful");
    11.                     string userInfo = "Username: " + Social.localUser.userName +
    12.                         "\nUser ID: " + Social.localUser.id +
    13.                         "\nIsUnderage: " + Social.localUser.underage;
    14.                     Debug.Log(userInfo);
    15.                 }
    16.                 else
    17.                     Debug.Log("Authentication failed");
    18.             });
    19.     }
    20. }
    21.  
     
  13. mansonet

    mansonet

    Joined:
    Jan 11, 2014
    Posts:
    8