Search Unity

Mac GameCenter never calls back from Authenticate

Discussion in 'macOS' started by hazel_koop, Nov 20, 2019.

  1. hazel_koop

    hazel_koop

    Joined:
    Apr 9, 2019
    Posts:
    29
    I'm trying out Unity's native GameCenter support (i.e. Social.localUser.Authenticate), and it's working fine on iOS, but when I try it on Mac, the callback that I pass to Authenticate just never gets called, and the GameCenter login prompt reappears every time the app gets focus.

    Specifically, these are the scenarios I'm encountering:

    On iOS, I press my debug "authenticate gamecenter" button, and a few seconds later, the callback that I passed to Social.localUser.Authenticate gets called, with its success argument set to TRUE, and I'm able to read the correct values from things like Social.localUser.id. All good.

    On Mac, if I follow the UNSH "Unity Apple Distribution Workflow" to sign a development build with an entitlements file containing a "com.apple.developer.game-center" key, it launches fine, but as soon as I click the "authenticate gamecenter" button, a GameCenter login prompt appears (even though I'm already logged in in System Preferences > Internet Accounts), and when I enter my username and password, the prompt goes away successfully (which it wouldn't if the password was wrong for example), but then the callback that I provided to Authenticate never gets called... and as soon as I click any other window, then click back into the game window, the login prompt appears *again* (even though I absolutely haven't called Authenticate a second time; I have Debug.Log calls in place to make sure).

    And just for context, if I sign the mac build WITHOUT the "com.apple.developer.game-center" key, the Authenticate callback actually DOES get called, with its success argument set to FALSE (presumably due to the missing entitlement). So it's interesting that it isn't even "Authenticate never calls back on Mac"; it's that it never calls back SUCCESSFULLY, but it WILL call back if something goes wrong.

    Has anyone else encountered this? Why is it firing off the login panel every time it gains focus? Are there any extra requirements besides the "com.apple.developer.game-center" entitlement in order to successfully access GameCenter in a Mac OS dev build?
     
  2. hazel_koop

    hazel_koop

    Joined:
    Apr 9, 2019
    Posts:
    29
    OK wow, I've just found an even weirder scenario: I'm able to make it somewhat work, but only after cancelling a previous attempt, and even so it STILL prompts me to log in again whenever I change programs.

    To be explicit:
    - I build according to the UNSH process, with the com.apple.developer.game-center key in my entitlements
    - I launch the build, and click my "authenticate gamecenter" button (to call Social.localUser.Authenticate)
    - The login prompt appears
    - Instead of logging in, I click CANCEL
    - The login prompt goes away, but the callback that I passed to Authenticate is NOT CALLED (not even with success==false)
    - I click my "authenticate gamecenter" button AGAIN
    - INSTANTLY, without displaying a new login prompt, without even the few-seconds delay that occurs on iOS: the callback is immediately called with success==true, and the gamecenter login information that I stored in System Preferences > Internet Accounts is accessible in Social.localUser.id etc!
    - HOWEVER, if I click to another application and then return to my game build, the game center login prompt appears AGAIN, despite the fact that I'm already authenticated by now!
    - I can keep clicking my 'authenticate' button to keep immediately getting its callback called with success==true, and there's nothing I can do to stop the login prompt from reappearing every time I change applications.

    Why is it only seeing my information when I *cancel* the login? And how can I stop the login from reappearing every time the application gains focus?
     
  3. hazel_koop

    hazel_koop

    Joined:
    Apr 9, 2019
    Posts:
    29
    To confirm a few more details:

    - I made a new button that just prints the value of Social.localUser.id
    - If I press the button before calling Social.localUser.Authenticate, the value of .id is nothing
    - If I press it AFTER the .Authenticate call, the value of .id is whatever I'm logged into in System Preferences — even if Authenticate hasn't called its callback yet!
    - Pressing the button to get the value of .id works even if I log in (even though it won't call the callback if I do that) — but also, the login credentials that I give have no effect; it will always show the ID of whatever account I'm logged into in System Preferences (and if I'm not logged in, it won't return anything).

    Also, for context, I'm on Catalina; maybe it's different on earlier OSes?
     
  4. hazel_koop

    hazel_koop

    Joined:
    Apr 9, 2019
    Posts:
    29
    Even weirder: I made a new test project to demonstrate the bug for a bug report, but the bug doesn't happen in builds of the new test project; in the test project, I just get a little "welcome back" message, no login prompt, and the callback is called like it should. So it isn't even anything about my machine, or anything universal to Unity; there's something in my (real) project that's causing this, but I absolutely can't narrow it down. All the (relevant) 'Player' project settings are the same, it happens in both debug and release mode, I've taken out the (homemade) iCloud plugin that was requiring it to be re-signed with new entitlements and now it behaves pre-signing just like it did post-signing with the plugin.

    So:
    - it's not my OS
    - it's not my Unity version
    - it's not my signing process
    - it's not development vs release build
    - it's not scripting backend or API compatibility level
    - it's not app store validation
    - it's not fullscreen or run-in-background choice
    - if it's a plugin, it's one I haven't found (this is a project that has had a lot of hands on it, but searching hasn't turned up anything obvious; is there any way to get a list of all plugins included in a build?)

    What could explain the difference in behaviour between the test project and the real project?