Skip to content

Commit 19b925e

Browse files
authored
[GameKit] Implement Xcode 16.0 beta 1-6 changes. (#20880)
Note: there were no changes in beta 2, beta 3, beta 4, beta 5 or beta 6.
1 parent 6302fe7 commit 19b925e

22 files changed

+188
-140
lines changed
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#if !WATCH
2+
using System;
3+
4+
using Foundation;
5+
using ObjCRuntime;
6+
7+
namespace GameKit {
8+
/// <summary>This enum is used to select how to initialize a new instance of a <see cref="GKGameCenterViewController" />.</summary>
9+
public enum GKGameCenterViewControllerInitializationOption {
10+
/// <summary>The <c>id</c> parameter passed to the constructor is an achievement ID.</summary>
11+
Achievement,
12+
/// <summary>The <c>id</c> parameter passed to the constructor is a leaderboard set ID.</summary>
13+
LeaderboardSet,
14+
}
15+
16+
public partial class GKGameCenterViewController {
17+
/// <summary>Create a new GKGameCenterViewController instance that presents an achievement.</summary>
18+
/// <param name="achievementId">The ID of the achievement to show.</param>
19+
#if NET
20+
[SupportedOSPlatform ("ios14.0")]
21+
[SupportedOSPlatform ("maccatalyst14.0")]
22+
[SupportedOSPlatform ("macos11.0")]
23+
[SupportedOSPlatform ("tvos14.0")]
24+
#else
25+
[TV (14, 0), Mac (11, 0), iOS (14, 0), MacCatalyst (14, 0)]
26+
#endif
27+
public GKGameCenterViewController (string achievementId)
28+
: this (achievementId, GKGameCenterViewControllerInitializationOption.Achievement)
29+
{
30+
}
31+
32+
/// <summary>Create a new GKGameCenterViewController instance that presents an achievement or a leaderboard set.</summary>
33+
/// <param name="id">The ID of the achievement or the leaderboard set to show.</param>
34+
/// <param name="option">Use this option to specify whether the GKGameCenterViewController shows an achievement or a leader board set.</param>
35+
#if NET
36+
[SupportedOSPlatform ("ios18.0")]
37+
[SupportedOSPlatform ("maccatalyst18.0")]
38+
[SupportedOSPlatform ("macos15.0")]
39+
[SupportedOSPlatform ("tvos18.0")]
40+
#else
41+
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
42+
#endif
43+
public GKGameCenterViewController (string id, GKGameCenterViewControllerInitializationOption option)
44+
: base (NSObjectFlag.Empty)
45+
{
46+
switch (option) {
47+
case GKGameCenterViewControllerInitializationOption.Achievement:
48+
InitializeHandle (_InitWithAchievementId (id));
49+
break;
50+
case GKGameCenterViewControllerInitializationOption.LeaderboardSet:
51+
InitializeHandle (_InitWithLeaderboardSetId (id));
52+
break;
53+
default:
54+
throw new ArgumentOutOfRangeException (nameof (option), option, "Invalid enum value.");
55+
}
56+
}
57+
}
58+
}
59+
#endif // !WATCH

src/GameKit/GameKit.cs

+4
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ public enum GKPlayerConnectionState : long {
222222
}
223223

224224
// NSInteger -> GKVoiceChat.h
225+
[Deprecated (PlatformName.iOS, 18, 0, message: "No longer supported.")]
226+
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "No longer supported.")]
227+
[Deprecated (PlatformName.TvOS, 18, 0, message: "No longer supported.")]
228+
[Deprecated (PlatformName.MacOSX, 15, 0, message: "No longer supported.")]
225229
[Native]
226230
public enum GKVoiceChatPlayerState : long {
227231
Connected,

src/frameworks.sources

+1
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ GAMEKIT_API_SOURCES = \
946946
GameKit/GameKit.cs \
947947

948948
GAMEKIT_SOURCES = \
949+
GameKit/GKGameCenterViewController.cs \
949950
GameKit/GKLocalPlayerListener.cs \
950951
GameKit/GameKit2.cs \
951952
GameKit/GKCompat.cs \

src/gamekit.cs

+41-14
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,8 @@ interface GKLeaderboardSet : NSCoding, NSSecureCoding {
535535
[Async]
536536
void LoadLeaderboardsWithCompletionHandler (GKLeaderboardsHandler handler);
537537

538-
[NoMac]
539538
[NoTV]
540539
[NoWatch]
541-
[NoMacCatalyst]
542540
[Export ("loadImageWithCompletionHandler:")]
543541
[Async]
544542
void LoadImage ([NullAllowed] GKImageLoadedHandler completionHandler);
@@ -917,8 +915,7 @@ interface GKLocalPlayer
917915
Action<NSViewController, NSError> AuthenticateHandler { get; set; }
918916
#endif
919917

920-
[NoWatch, NoTV, Mac (12, 0), iOS (15, 0)]
921-
[NoMacCatalyst]
918+
[NoWatch, NoTV, Mac (12, 0), iOS (15, 0), MacCatalyst (15, 0)]
922919
[Export ("isPresentingFriendRequestViewController")]
923920
bool IsPresentingFriendRequestViewController { get; }
924921

@@ -1160,6 +1157,10 @@ interface GKMatch {
11601157
[Export ("disconnect")]
11611158
void Disconnect ();
11621159

1160+
[Deprecated (PlatformName.iOS, 18, 0, message: "No longer supported.")]
1161+
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "No longer supported.")]
1162+
[Deprecated (PlatformName.TvOS, 18, 0, message: "No longer supported.")]
1163+
[Deprecated (PlatformName.MacOSX, 15, 0, message: "No longer supported.")]
11631164
[Export ("voiceChatWithName:")]
11641165
[return: NullAllowed]
11651166
GKVoiceChat VoiceChatWithName (string name);
@@ -1254,6 +1255,10 @@ interface GKMatchDelegate {
12541255
void DataReceivedForRecipient (GKMatch match, NSData data, GKPlayer recipient, GKPlayer player);
12551256
}
12561257

1258+
[Deprecated (PlatformName.iOS, 18, 0, message: "No longer supported.")]
1259+
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "No longer supported.")]
1260+
[Deprecated (PlatformName.TvOS, 18, 0, message: "No longer supported.")]
1261+
[Deprecated (PlatformName.MacOSX, 15, 0, message: "No longer supported.")]
12571262
[NoWatch]
12581263
[MacCatalyst (13, 1)]
12591264
[BaseType (typeof (NSObject))]
@@ -1520,7 +1525,7 @@ interface GKMatchmaker {
15201525
[TV (17, 2), Mac (14, 2), iOS (17, 2), MacCatalyst (17, 2)]
15211526
[Async]
15221527
[Export ("findMatchedPlayers:withCompletionHandler:")]
1523-
void FindMatchedPlayers (GKMatchRequest request, [NullAllowed] Action<GKMatchedPlayers, NSError> completionHandler);
1528+
void FindMatchedPlayers (GKMatchRequest request, Action<GKMatchedPlayers, NSError> completionHandler);
15241529

15251530
// Not truly an [Async] method since the handler can be called multiple times, for each player found
15261531
[MacCatalyst (13, 1)]
@@ -2525,26 +2530,36 @@ interface GKGameCenterViewController
25252530
[Export ("initWithNibName:bundle:")]
25262531
NativeHandle Constructor ([NullAllowed] string nibNameOrNull, [NullAllowed] NSBundle nibBundleOrNull);
25272532

2528-
[TV (14, 0), NoWatch, Mac (11, 0), iOS (14, 0)]
2533+
[TV (14, 0), Mac (11, 0), iOS (14, 0)]
25292534
[MacCatalyst (14, 0)]
25302535
[Export ("initWithLeaderboardID:playerScope:timeScope:")]
25312536
NativeHandle Constructor (string leaderboardId, GKLeaderboardPlayerScope playerScope, GKLeaderboardTimeScope timeScope);
25322537

2533-
[TV (14, 0), NoWatch, Mac (11, 0), iOS (14, 0)]
2538+
[TV (14, 0), Mac (11, 0), iOS (14, 0)]
25342539
[MacCatalyst (14, 0)]
25352540
[Export ("initWithLeaderboard:playerScope:")]
25362541
NativeHandle Constructor (GKLeaderboard leaderboard, GKLeaderboardPlayerScope playerScope);
25372542

2538-
[TV (14, 0), NoWatch, Mac (11, 0), iOS (14, 0)]
2543+
[TV (14, 0), Mac (11, 0), iOS (14, 0)]
25392544
[MacCatalyst (14, 0)]
25402545
[Export ("initWithAchievementID:")]
2541-
NativeHandle Constructor (string achievementId);
2546+
[Internal]
2547+
NativeHandle _InitWithAchievementId (string achievementId);
25422548

2543-
[TV (14, 0), NoWatch, Mac (11, 0), iOS (14, 0)]
2549+
[TV (14, 0), Mac (11, 0), iOS (14, 0)]
25442550
[MacCatalyst (14, 0)]
25452551
[Export ("initWithState:")]
25462552
NativeHandle Constructor (GKGameCenterViewControllerState state);
25472553

2554+
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
2555+
[Export ("initWithLeaderboardSetID:")]
2556+
[Internal]
2557+
NativeHandle _InitWithLeaderboardSetId (string leaderboardSetId);
2558+
2559+
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
2560+
[Export ("initWithPlayer:")]
2561+
NativeHandle Constructor (GKPlayer player);
2562+
25482563
[Export ("gameCenterDelegate", ArgumentSemantic.Weak), NullAllowed]
25492564
NSObject WeakDelegate { get; set; }
25502565

@@ -3110,6 +3125,22 @@ interface GKAccessPoint {
31103125

31113126
[Export ("triggerAccessPointWithState:handler:")]
31123127
void TriggerAccessPoint (GKGameCenterViewControllerState state, Action handler);
3128+
3129+
[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
3130+
[Export ("triggerAccessPointWithAchievementID:handler:")]
3131+
void TriggerAccessPointWithAchievementId (string achievementId, [NullAllowed] Action handler);
3132+
3133+
[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
3134+
[Export ("triggerAccessPointWithLeaderboardSetID:handler:")]
3135+
void TriggerAccessPointWithLeaderboardSetId (string leaderboardSetId, [NullAllowed] Action handler);
3136+
3137+
[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
3138+
[Export ("triggerAccessPointWithLeaderboardID:playerScope:timeScope:handler:")]
3139+
void TriggerAccessPoint (string leaderboardId, GKLeaderboardPlayerScope playerScope, GKLeaderboardTimeScope timeScope, [NullAllowed] Action handler);
3140+
3141+
[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
3142+
[Export ("triggerAccessPointWithPlayer:handler:")]
3143+
void TriggerAccessPoint (GKPlayer player, [NullAllowed] Action handler);
31133144
}
31143145

31153146
[Watch (7, 0), TV (14, 0), Mac (11, 0), iOS (14, 0)]
@@ -3120,9 +3151,6 @@ interface GKLeaderboardEntry {
31203151
[Export ("player", ArgumentSemantic.Strong)]
31213152
GKPlayer Player { get; }
31223153

3123-
#if false
3124-
// Some APIs missing on iOS, tvOS, watchOS as of Xcode 12 beta 3 - https://github.com/xamarin/maccore/issues/2269
3125-
// disabled since the selectors don't respond on macOS 11.0
31263154
[Export ("rank")]
31273155
nint Rank { get; }
31283156

@@ -3137,7 +3165,6 @@ interface GKLeaderboardEntry {
31373165

31383166
[Export ("date", ArgumentSemantic.Strong)]
31393167
NSDate Date { get; }
3140-
#endif
31413168

31423169
[NoWatch] // header lists watch as supported, but UIViewController is not available on Watch!
31433170
[MacCatalyst (13, 1)]

tests/introspection/ApiSelectorTest.cs

+33
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,35 @@ protected virtual bool Skip (Type type, string selectorName)
10311031
return !TestRuntime.CheckXcodeVersion (16, 0);
10321032
}
10331033
break;
1034+
case "GKLeaderboardEntry":
1035+
// It's not possible to create an instance of GKLeaderboardEntry, so I believe that whenever Apple
1036+
// returns an instance they return something that responds to these selectors, thus we have to
1037+
// provide bindings for them.
1038+
switch (selectorName) {
1039+
case "context":
1040+
case "date":
1041+
case "formattedScore":
1042+
case "rank":
1043+
case "score":
1044+
return true;
1045+
}
1046+
break;
1047+
#if __MACCATALYST__
1048+
case "GKLeaderboardSet":
1049+
switch (selectorName) {
1050+
case "loadImageWithCompletionHandler:":
1051+
// This exists in both iOS and macOS, so not existing in Mac Catalyst is weird - so just provide the binding.
1052+
return true;
1053+
}
1054+
break;
1055+
case "GKLocalPlayer":
1056+
switch (selectorName) {
1057+
case "isPresentingFriendRequestViewController":
1058+
// This exists in both iOS and macOS, so not existing in Mac Catalyst is weird - so just provide the binding.
1059+
return true;
1060+
}
1061+
break;
1062+
#endif // __MACCATALYST__
10341063
}
10351064

10361065
// old binding mistake
@@ -1287,6 +1316,10 @@ protected virtual bool SkipInit (string selector, MethodBase m)
12871316
// DDDevicePickerViewController
12881317
case "initWithBrowseDescriptor:parameters:":
12891318
return true;
1319+
// GKGameCenterViewController
1320+
case "initWithAchievementID:":
1321+
case "initWithLeaderboardSetID:":
1322+
return true;
12901323
default:
12911324
return false;
12921325
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Unit tests for GKGameCenterViewControllerTest
3+
//
4+
5+
#if !__WATCHOS__
6+
7+
using System;
8+
using Foundation;
9+
using ObjCRuntime;
10+
#if MONOMAC
11+
using AppKit;
12+
#else
13+
using UIKit;
14+
#endif
15+
using GameKit;
16+
using NUnit.Framework;
17+
using Xamarin.Utils;
18+
19+
namespace MonoTouchFixtures.GameKit {
20+
21+
[TestFixture]
22+
[Preserve (AllMembers = true)]
23+
public class GKGameCenterViewControllerTest {
24+
[Test]
25+
public void StringCtor ()
26+
{
27+
TestRuntime.AssertXcodeVersion (12, 0);
28+
using var controller = new GKGameCenterViewController ("achievementId");
29+
Assert.AreEqual (controller.ViewState, GKGameCenterViewControllerState.Achievements, "ViewState");
30+
}
31+
32+
[Test]
33+
public void StringOptionCtor_AchievementId ()
34+
{
35+
TestRuntime.AssertXcodeVersion (12, 0);
36+
using var controller = new GKGameCenterViewController ("achievementId", GKGameCenterViewControllerInitializationOption.Achievement);
37+
Assert.AreEqual (controller.ViewState, GKGameCenterViewControllerState.Achievements, "ViewState");
38+
}
39+
40+
[Test]
41+
public void StringOptionCtor_LeaderboardSetId ()
42+
{
43+
TestRuntime.AssertXcodeVersion (16, 0);
44+
using var controller = new GKGameCenterViewController ("achievementId", GKGameCenterViewControllerInitializationOption.LeaderboardSet);
45+
Assert.AreEqual (controller.ViewState, GKGameCenterViewControllerState.Leaderboards, "ViewState");
46+
}
47+
}
48+
}
49+
50+
#endif // !__WATCHOS__

tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-GameKit.ignore

-7
This file was deleted.

tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-GameKit.todo

-9
This file was deleted.

tests/xtro-sharpie/api-annotations-dotnet/common-GameKit.ignore

-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,3 @@
33

44
## enum size declared after the enum, e.g. `typedef NSInteger GKInviteeResponse;`, so we miss the metadata
55
!unknown-native-enum! GKInviteeResponse bound
6-
7-
# Xcode 12 beta 3 - these API are missing
8-
# https://github.com/xamarin/maccore/issues/2269
9-
!missing-selector! GKLeaderboardEntry::context not bound
10-
!missing-selector! GKLeaderboardEntry::date not bound
11-
!missing-selector! GKLeaderboardEntry::formattedScore not bound
12-
!missing-selector! GKLeaderboardEntry::rank not bound
13-
!missing-selector! GKLeaderboardEntry::score not bound
14-
15-
## unsorted
16-

tests/xtro-sharpie/api-annotations-dotnet/iOS-GameKit.ignore

-2
This file was deleted.

tests/xtro-sharpie/api-annotations-dotnet/iOS-GameKit.todo

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
# The parent enum GKVoiceChatService is not available in macOS
2-
# so to be honest it does not make much sense to expose this constant on macOS
3-
# nor the below protocols
4-
5-
# This selector does not exist in macOS, confirmed by intro.
6-
71
# Deprecated
82
!missing-protocol-member! GKInviteEventListener::player:didRequestMatchWithPlayers: not found
93
!missing-protocol-member! GKTurnBasedEventListener::player:didRequestMatchWithPlayers: not found
104

115
# We have bound GKVoiceChatServiceError as GKVoiceChatServiceError which has no support for macOS
126
!missing-field! GKVoiceChatServiceErrorDomain not bound
137
# https://developer.apple.com/documentation/gamekit/gkvoicechatserviceerror?language=objc
14-
15-
# This selector does not exist (respond?) in macOS either
16-
!missing-selector! GKLeaderboardSet::loadImageWithCompletionHandler: not bound
17-
18-
# NullAllowed makes sense
19-
!extra-null-allowed! 'System.Void GameKit.GKMatchmaker::FindMatchedPlayers(GameKit.GKMatchRequest,System.Action`2<GameKit.GKMatchedPlayers,Foundation.NSError>)' has a extraneous [NullAllowed] on parameter #1

tests/xtro-sharpie/api-annotations-dotnet/macOS-GameKit.todo

-8
This file was deleted.

tests/xtro-sharpie/api-annotations-dotnet/tvOS-GameKit.ignore

-2
This file was deleted.

tests/xtro-sharpie/api-annotations-dotnet/tvOS-GameKit.todo

-8
This file was deleted.

0 commit comments

Comments
 (0)