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

Bug GKLocalPlayer.Local.FetchItems() Error on Unity

Discussion in 'Authentication' started by MousePods, Feb 4, 2023.

  1. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    808
    I setup everything correctly for adding Apple GameCenter so I can use Cloud Save. On device, I successfully login and it shows the banner.

    I get this error when the next line of code is called.

    Code (CSharp):
    1. var fetchItemsResponse = await GKLocalPlayer.Local.FetchItems();
    Code (CSharp):
    1. Thread 1: EXC_BAD_ACCESS (code=257, address=0x2)
    Is there a fix coming soon?

    Thanks
     
  2. clementescoffier

    clementescoffier

    Joined:
    Sep 21, 2020
    Posts:
    6
    I'm having the same problem as you, except no Thread 1: EXC_BAD_ACCESS (code=257, address=0x2) error, it just crashes and cuts connection from the device to XCode
     
    AndreaMar likes this.
  3. clementescoffier

    clementescoffier

    Joined:
    Sep 21, 2020
    Posts:
    6
    nvm, I have the error on another device i tested
     
  4. ted05051997

    ted05051997

    Joined:
    May 7, 2020
    Posts:
    4
    I have the same problem,
    fetchItems()
    OnSuccess()
    Thread 1: EXC_BAD_ACCESS (code=257, address=0x2) error, it just crashes when cuts connection from the device to XCode
    if not cut connection, it will keep stay in this error line in Xcode
    using Unity 2021.3.9f, build on iOS,
    manually modified manifest.json to use unity authentication 2.4.0
    using Apple Game Center plugin for unity
     
  5. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    279
    Hi everyone,
    There is currently an issue with Apple Game Center that we are aware of. We are in contact with Apple to get that resolved.

    I will postback here once we have more information.
     
    qball13z, AndreaMar, Qray5000 and 2 others like this.
  6. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    353
    DeathPro and SebT_Unity like this.
  7. unity_DD36632923EDB25EB366

    unity_DD36632923EDB25EB366

    Joined:
    Feb 7, 2023
    Posts:
    2
    He said he fixed the pointer thing in that branch but the callback still not working actually
     
  8. unity_DD36632923EDB25EB366

    unity_DD36632923EDB25EB366

    Joined:
    Feb 7, 2023
    Posts:
    2
    Stuck in this problem for 2 weeks already, thanks for finally someone related try to handle it
     
    SebT_Unity likes this.
  9. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    353
    It works for me
     
    SebT_Unity likes this.
  10. TheEugeneL

    TheEugeneL

    Joined:
    Dec 7, 2017
    Posts:
    43
    I also have the same error and so I could not use the apple plugin.

    I found another path.
    First I used Social.localUser.Authenticate();
    Social.localUser.id - is TeamPlayerID;

    then I used code from this link https://gist.github.com/BastianBlokland/bbc02a407b05beaf3f55ead3dd10f808

    So I got:
    publicKeyUrl, signature, salt and timestamp

    And it works perfectly. Authorization on the Unity side works without any problems.
     
    xxzchozxx and SebT_Unity like this.
  11. ted05051997

    ted05051997

    Joined:
    May 7, 2020
    Posts:
    4
    Is there any update on this issue?
     
  12. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    279
    Hi,
    I've asked the development team to take a look at the suggested workaround proposed above.
    We also have an open ticket with Apple.

    I will postback here when I have more news
     
  13. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    People here are saying that this git branch is working properly. I still have to give it a try as soon as I can.

    I confirm. It's working. It's impossible to select target platforms while building tars though.

    I'm nonetheless waiting for the official release.

    EDIT: I'm having troubles when I switch back to Android. Unity is building the Apple plugins for Android as well and this creates problems. It seems I cannot deselect the Android platform from the plugin inspector: even if I select only iOS and apply changes, as I try to build the .apk selection are resetting to "Any platform". :mad:
     
    Last edited: Mar 16, 2023
  14. GingerNingerish

    GingerNingerish

    Joined:
    Sep 17, 2019
    Posts:
    5
    Tried the fix but it currently has the GetSalt and Get Signature functions disabled which i need to Authorize cloud saving.
     
  15. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    Use this. GetSalt() and GetSignature() functions are not available with this mod. Use .Salt and .Signature properties instead. They work fine in my project.

    An annoying problem though is that every time I switch to Android for building my game these plugins (I'm using Core and GameKit) are included in the build process which I cannot complete because of a few errors. I can't edit the selected devices in the plugin inspector. I always have to remove the packages and re-import them again.

    I also cannot target iOS versions lower than 14.0. If I do, the app will crash on launch because of a GameKitWrapper-something missing. But I haven't checked yet if this is a requirement for the mod only or for the official Apple release as well.

    I hope they'll fix this soon.
     
    squigglebucket likes this.
  16. GingerNingerish

    GingerNingerish

    Joined:
    Sep 17, 2019
    Posts:
    5
    Weird, I tried using the .Salt and .Signature properties and it kept telling me there was no permision/access for it or something I forgot the specifics, even though everything was public. This caused me to switch back to whatever the latest was. I have had wayyyyy too many issues with Apple and XCode from these plugins.

    I'm just going to hold out for a fix. I hope it is actually being worked on.
     
    AndreaMar likes this.
  17. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    Can you upload a screenshot?
     
  18. GingerNingerish

    GingerNingerish

    Joined:
    Sep 17, 2019
    Posts:
    5
    I might be going crazy now. I reimported the fix again reverting from the latest version. Now .GetSignature() and .Signature both don't exist. Think I will wait this out.
     
  19. dennis_unity308

    dennis_unity308

    Joined:
    Sep 14, 2022
    Posts:
    1
    You have to switch branches to `fix-fetch-items`. https://github.com/muZZkat/unityplugins/tree/muzzkat/fix-fetch-items.
    Run the python script to build the unity tar files. Then import.

    Personally, I unpack the entire tar files and copy the uncompressed folder into my project entirely.
     
  20. GingerNingerish

    GingerNingerish

    Joined:
    Sep 17, 2019
    Posts:
    5

    Yeah absolutely, that's exactly what I did, which is funny becuase importing the tar file dirrectly causes it to have no read/write permissions to imported package files which was a whole nother headache I had to figure out.

    But anyways, I had the latest version, reverted to the the fix branch, which was indeed working, since the GetSignature() was removed. Discovered the .Signature reference, which in the editor kept telling me there were no permisions for that reference like it was a private varriable. So I just reverted back to the latest branch.

    As per the advice of the others, AndreaMar asked me to get the screen of that error. So I went through the whole proccess again. Now I do not have GetSignature() or .Signature. So I am certainly on the Fix branch especially after re-doing the plugins like 3 times now.

    So thats where I am at.
     
  21. Razera

    Razera

    Joined:
    Oct 5, 2015
    Posts:
    5
    Hello! We were struggled with this error in the past days and we found a workaround. Open the GKIdentityVerificationResponse.cs script and change the GKIdentityVerificationResponse function from internal to public and the error will be solved!


    Code (CSharp):
    1. public GKIdentityVerificationResponse(ulong timestamp,
    2.             IntPtr publicKeyUrl, int publicKeyUrlLength,
    3.             IntPtr signature, int signatureLength,
    4.             IntPtr salt, int saltLength)
    5.         {
    6.             Timestamp = timestamp;
    7.  
    8.             var publicKeyUrlBytes = new byte[publicKeyUrlLength];
    9.             Marshal.Copy(publicKeyUrl, publicKeyUrlBytes, 0, publicKeyUrlLength);
    10.             PublicKeyUrl = System.Text.Encoding.UTF8.GetString(publicKeyUrlBytes);
    11.            
    12.             Signature = new byte[signatureLength];
    13.             Marshal.Copy(signature, Signature, 0, signatureLength);
    14.  
    15.             Salt = new byte[saltLength];
    16.             Marshal.Copy(salt, Salt, 0, saltLength);
    17.  
    18.         }
     
  22. Razera

    Razera

    Joined:
    Oct 5, 2015
    Posts:
    5
    Hello guys! We were having a lot of problems in the past few days with this error in FetchItems and we finally made a build with success and here go some advices:

    1 - The https://github.com/muZZkat/unityplugins/tree/muzzkat/fix-fetch-items branch fixes the FetchItems Bad Access error in IOS build.
    2 - Make sure you are in muZZkat's branch, you have to enter the git and checkout to fix-fetch-items branch.
    3 - To make sure if you are in muZZkat's branch, the functions GetSignature() and GetSalt() must be missing. You have to change those functions with .Signature and .Salt variables.
    4 - If your Unity Editor logs an error saying that the script doesn't have access/permission to the class, go to GKIdentityVerificationResponse.cs script and change the GKIdentityVerificationResponse() function from internal to public.
     
    Last edited: Apr 17, 2023
  23. Jonathan-FourFats

    Jonathan-FourFats

    Joined:
    Apr 21, 2016
    Posts:
    22
    Last edited: Apr 28, 2023
  24. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    353
    Please sir, is there any news? The fix I was using https://developer.apple.com/forums/thread/722593 doesn't work with macOS builds.
     
  25. Epsilon_Delta

    Epsilon_Delta

    Joined:
    Mar 14, 2018
    Posts:
    257
    Hi, I created a fork on github from official Apple/unityplugins:

    https://github.com/EpsilonD3lta/unityplugins

    and integrated two pull requests:
    1. Fix for correct multiplatform compilation from this fork: https://github.com/dodgy-ltd/apple-unityplugins/tree/cross-platform-fixes
    2. Fix for FetchItems exception from this fork: https://github.com/muZZkat/unityplugins/tree/muzzkat/fix-fetch-items

    Second fix causes to GetSalt and GetSignature methods change to Salt and Signature fields so you have to use those.
    It seems to be working, on client and serverside too, tested on iOS devices, not tested on macOS or anything else.
    I used recomended unity 2020.3.33 to build the plugins with command
    python3 build.py -m iOS
    . My xCode version is 14.2
     
    Last edited: Jul 18, 2023
    lucascurci, Brogan89 and TeorikDeli like this.
  26. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    353
    @SebT_Unity Is there any news on the fixes? It has been over half a year. On the latest version of Unity 2023.2.0b5, both macOS and iOS cannot build while using the apple plugin.
     
  27. GingerNingerish

    GingerNingerish

    Joined:
    Sep 17, 2019
    Posts:
    5
    It is absoluelty pathetic that such a basic function is not fixed.
     
  28. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    808
    Thanks for the info! It seems that is obsolete now... I don't see any path to using Unity's Authentication on iOS at this time... :(

    https://docs.unity3d.com/2023.3/Documentation/Manual/net-SocialAPI.html
     
  29. TheEugeneL

    TheEugeneL

    Joined:
    Dec 7, 2017
    Posts:
    43
    It's just awful to see. My current projects work this way. And I don't know at all what to do so that users don't lose their data. The worst part is that there is no replacement, and there doesn't seem to be one.
     
    MousePods likes this.
  30. lucascurci

    lucascurci

    Joined:
    Feb 7, 2019
    Posts:
    5
    There is a serious issue here, Unity Authentication and cloud saves is unusable if this is not fixed quickly. The normal way of implementing it cannot be by merging a PR of some dude with a commit from another dude.
    Even with this fixes, the plugin does not provide necessary data to sign in with Unity.

    a disaster going on for more than 6 months
     
  31. TheEugeneL

    TheEugeneL

    Joined:
    Dec 7, 2017
    Posts:
    43
    I use authorization mainly to save players data.

    Unfortunately I decided to leave unity services and started working on my own, simpler solution on mysql, as I don't see any way out and can't trust solutions from Unity if such simple things can't be fixed for more than half a year. It's absolutely frustrating
     
  32. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    353
    Any Unity developer! Is there any update? How can a paid service be broken for this long?
     
  33. chengg_unity

    chengg_unity

    Unity Technologies

    Joined:
    May 15, 2022
    Posts:
    68
    Hello everyone,
    Apologies for the delayed response. We are still collaborating with Apple to provide an update on the Apple Unity plugin for a permanent solution. In the meantime, we wanted to share this document with you that offers a workaround.
    Please let us know if you have any feedback on this document, and we’ll make updates as necessary. Thank you!
     
  34. sokolwow

    sokolwow

    Joined:
    Dec 19, 2012
    Posts:
    3
  35. carlosmejia083

    carlosmejia083

    Joined:
    Sep 20, 2020
    Posts:
    2
    HUGE thanks! this worked for me. What a headache the Apple SDK
     
  36. Voodoocado

    Voodoocado

    Joined:
    Aug 19, 2018
    Posts:
    11
    I believe this response is now outdated. There was a refactoring in the build.py script, which moved or renamed the "Build Native Libraries" part.

    Wish there will be a clear path forward for this soon!
     
    Last edited: Jan 3, 2024
  37. DacDoudou

    DacDoudou

    Joined:
    May 24, 2019
    Posts:
    7
    Hi MousePods
    I finally managed to install everything and build on Unity 2021.3.31.f1, thanks to the muzzkat fixes.
    Did you manage to make Cloud save work? Unfortunately I cannot see these Gamekit Cloud save bindings in our Unity wrapper.
    Going to try that solution though but I'm not confident it'll work as it's yet another merge from another unofficial branch.
     
  38. DacDoudou

    DacDoudou

    Joined:
    May 24, 2019
    Posts:
    7
  39. hexdecc

    hexdecc

    Joined:
    Oct 24, 2014
    Posts:
    146
  40. Unarmed1000

    Unarmed1000

    Joined:
    Sep 12, 2014
    Posts:
    22
    Seriously how can the plugin still have such basic issues six to eight months after its been reported.
    Also cross platform games that tries to compile for a different platform on Windows gives a error just for having the apple addon included.
     
    madclouds likes this.
  41. xxzchozxx

    xxzchozxx

    Joined:
    Mar 30, 2021
    Posts:
    1
    Can you give me a more detailed code or explanation? Please help me.
     
  42. njellingson

    njellingson

    Joined:
    Jun 25, 2015
    Posts:
    3
    Hi, I was able to get this code to work: https://gist.github.com/BastianBlokland/bbc02a407b05beaf3f55ead3dd10f808
    I created a file at Assets/Plugins/iOS/GeneratedIdentityVerificationSignature.m in my project and copy+pasted the objective-c code into that. In the unity inspector for the file, I ticked the boxes to include the native plugin for the iOS platform and selected GameKit as a framework dependency. Then in my C# script that was handling my GameCenter login flow (the same script where I had been attempting to call GKLocalPlayer.Local.FetchItems()) I have modified the logic to use the new generateIdentityVerificationSignature with a static callback function where I record the public key url, timestamp, signature, and salt someplace that is accessible in my codebase.

    I can then use this info to authenticate with my backend service (in my case LootLocker). I'm using Social.localuser.id for the PlayerId.

    Good luck!
     
    madclouds likes this.
  43. Maih76mh

    Maih76mh

    Joined:
    Mar 4, 2024
    Posts:
    2
  44. CanerGS

    CanerGS

    Joined:
    Jan 13, 2021
    Posts:
    1
    I have used it but FetchItems() parameters doesn't return anything when I use it on iOS.
    Can you give more details about how you made it ?
    I am searching web in the last 3-4 days and I am going to be crazy.
     
  45. Maih76mh

    Maih76mh

    Joined:
    Mar 4, 2024
    Posts:
    2
    Check your Phone settings and ReLogin to Game center account. if thats didnt work well i share my code compare that.
     

    Attached Files: