Repository navigation
GameKit UnsupportedOperationForOSVersion Exception thrown on iOS 18 #67
Description
On iOS 18 (and probably since iOS 15 that is the minimum indicated in the documentation), the plugin is throwing the following exception:
GameKitException: Code=-7 Domain=GKErrorDomain Description=No se pudo completar la operación.
(Error de GKErrorDomain -7) (UnsupportedOperationForOSVersion) at
Apple.GameKit.DefaultNSErrorHandler.ThrowNSError (System.IntPtr nsErrorPtr) [0x00000] in
<00000000000000000000000000000000>:0 Rethrow as TypeInitializationException:
The type initializer for 'Apple.GameKit.GKGameActivity' threw an exception.
I found that is happening because the current implementation of GKGameActivity has a static constructor calling a native function that registers a delegate that needs iOS 26 as minimum:
Lines 32 to 35 in e0d22a2
| static GKGameActivity() | |
| { | |
| Interop.GKGameActivity_SetWantsToPlayCallback(OnWantsToPlay); | |
| } |
On C# static constructors are called at least once independently from the user, it should be used to initialize static data or actions that need to be performed only once, however static GKGameActivity() is calling a native function in Swift that is not available on iOS 18:
unityplugins/plug-ins/Apple.GameKit/Native/GameKitWrapper/GKGameActivityDelegate.swift
Lines 41 to 46 in e0d22a2
| @_cdecl("GKGameActivity_SetWantsToPlayCallback") | |
| public func GKGameActivity_SetWantsToPlayCallback(callback : @escaping WantsToPlayActivityCallback) { | |
| if #available(iOS 26.0, macOS 26.0, tvOS 26.0, visionOS 26.0, *) { | |
| _localPlayerListener.WantsToPlayActivity = callback; | |
| } else { | |
| DefaultNSErrorHandler.throwApiUnavailableError(); |
I think the delegate registration must be Developer's responsibility if he needs to use this class and it should be his responsibility to handle the exception, I don't think it is good to have an exception on initialization.
As a suggestion, perhaps it will be better to have a non-static public constructor that the developer can call explicitly.
Activity
michaelclockstone commentedon Dec 17, 2025
This bug completely prevents user authentication on older devices. As a workaround for development you can make Unity Development builds. For some reason authentication then works.
ryzngard commentedon Dec 25, 2025
This should be fixed by #74