objc2-game-kit 0.3.2

Bindings to the GameKit framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
use objc2_app_kit::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gklocalplayer?language=objc)
    #[unsafe(super(GKPlayer, GKBasePlayer, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
    pub struct GKLocalPlayer;
);

#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
extern_conformance!(
    unsafe impl NSCopying for GKLocalPlayer {}
);

#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
unsafe impl CopyingHelper for GKLocalPlayer {
    type Result = Self;
}

#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
extern_conformance!(
    unsafe impl NSObjectProtocol for GKLocalPlayer {}
);

#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
impl GKLocalPlayer {
    extern_methods!(
        /// Obtain the primary GKLocalPlayer object.
        /// The player is only available for offline play until logged in.
        /// A temporary player is created if no account is set up.
        #[unsafe(method(local))]
        #[unsafe(method_family = none)]
        pub unsafe fn local() -> Retained<GKLocalPlayer>;

        #[unsafe(method(localPlayer))]
        #[unsafe(method_family = none)]
        pub unsafe fn localPlayer() -> Retained<GKLocalPlayer>;

        /// Authentication state
        #[unsafe(method(isAuthenticated))]
        #[unsafe(method_family = none)]
        pub unsafe fn isAuthenticated(&self) -> bool;

        /// Indicates if a player is under age
        #[unsafe(method(isUnderage))]
        #[unsafe(method_family = none)]
        pub unsafe fn isUnderage(&self) -> bool;

        /// A Boolean value that declares whether or not multiplayer gaming is restricted on this device.
        #[unsafe(method(isMultiplayerGamingRestricted))]
        #[unsafe(method_family = none)]
        pub unsafe fn isMultiplayerGamingRestricted(&self) -> bool;

        /// A Boolean value that declares whether personalized communication is restricted on this device. If it is restricted, the player will not be able to read or write personalized messages on game invites, challenges, or enable voice communication in multiplayer games.  Note: this value will always be true when isUnderage is true.
        #[unsafe(method(isPersonalizedCommunicationRestricted))]
        #[unsafe(method_family = none)]
        pub unsafe fn isPersonalizedCommunicationRestricted(&self) -> bool;

        #[cfg(feature = "block2")]
        /// Asynchronously load the recent players list as an array of GKPlayer.  A recent player is someone that you have played a game with or is a legacy game center friend.  Calls completionHandler when finished. Error will be nil on success.
        /// Possible reasons for error:
        /// 1. Communications problem
        /// 2. Unauthenticated player
        #[unsafe(method(loadRecentPlayersWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadRecentPlayersWithCompletionHandler(
            &self,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
            >,
        );

        #[cfg(feature = "block2")]
        /// Asynchronously load the challengable friends list as an array of GKPlayer.  A challengable player is a friend player with friend level FL1 and FL2.  Calls completionHandler when finished. Error will be nil on success.
        /// Possible reasons for error:
        /// 1. Communications problem
        /// 2. Unauthenticated player
        #[unsafe(method(loadChallengableFriendsWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadChallengableFriendsWithCompletionHandler(
            &self,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
            >,
        );

        #[cfg(feature = "block2")]
        /// Set the default leaderboard for the current game
        /// Possible reasons for error:
        /// 1. Communications problem
        /// 2. Unauthenticated player
        /// 3. Leaderboard not present
        #[unsafe(method(setDefaultLeaderboardIdentifier:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDefaultLeaderboardIdentifier_completionHandler(
            &self,
            leaderboard_identifier: &NSString,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Load the default leaderboard identifier for the local player
        /// Possible reasons for error:
        /// 1. Communications problem
        /// 2. Unauthenticated player
        /// 3. Leaderboard not present
        #[unsafe(method(loadDefaultLeaderboardIdentifierWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadDefaultLeaderboardIdentifierWithCompletionHandler(
            &self,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSString, *mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Generates a signature allowing 3rd party server to authenticate the GKLocalPlayer
        /// Possible reasons for error:
        /// 1. Communications problem
        /// 2. Unauthenticated player
        #[unsafe(method(fetchItemsForIdentityVerificationSignature:))]
        #[unsafe(method_family = none)]
        pub unsafe fn fetchItemsForIdentityVerificationSignature(
            &self,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut NSURL, *mut NSData, *mut NSData, u64, *mut NSError)>,
            >,
        );
    );
}

/// Methods declared on superclass `GKPlayer`.
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
impl GKLocalPlayer {
    extern_methods!(
        #[unsafe(method(anonymousGuestPlayerWithIdentifier:))]
        #[unsafe(method_family = none)]
        pub unsafe fn anonymousGuestPlayerWithIdentifier(
            guest_identifier: &NSString,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
impl GKLocalPlayer {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gklocalplayerlistener?language=objc)
    #[cfg(all(
        feature = "GKEventListener",
        feature = "GKGameActivityListener",
        feature = "GKMatchmaker",
        feature = "GKSavedGameListener",
        feature = "GKTurnBasedMatch"
    ))]
    pub unsafe trait GKLocalPlayerListener:
        GKChallengeListener
        + GKGameActivityListener
        + GKInviteEventListener
        + GKTurnBasedEventListener
        + GKSavedGameListener
    {
    }
);

/// GKLocalPlayerEvents.
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
impl GKLocalPlayer {
    extern_methods!(
        #[cfg(all(
            feature = "GKEventListener",
            feature = "GKGameActivityListener",
            feature = "GKMatchmaker",
            feature = "GKSavedGameListener",
            feature = "GKTurnBasedMatch"
        ))]
        /// A single listener may be registered once. Registering multiple times results in undefined behavior. The registered listener will receive callbacks for any selector it responds to.
        #[unsafe(method(registerListener:))]
        #[unsafe(method_family = none)]
        pub unsafe fn registerListener(&self, listener: &ProtocolObject<dyn GKLocalPlayerListener>);

        #[cfg(all(
            feature = "GKEventListener",
            feature = "GKGameActivityListener",
            feature = "GKMatchmaker",
            feature = "GKSavedGameListener",
            feature = "GKTurnBasedMatch"
        ))]
        #[unsafe(method(unregisterListener:))]
        #[unsafe(method_family = none)]
        pub unsafe fn unregisterListener(
            &self,
            listener: &ProtocolObject<dyn GKLocalPlayerListener>,
        );

        #[unsafe(method(unregisterAllListeners))]
        #[unsafe(method_family = none)]
        pub unsafe fn unregisterAllListeners(&self);
    );
}

extern "C" {
    /// Notification will be posted whenever authentication status changes.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkplayerauthenticationdidchangenotificationname?language=objc)
    pub static GKPlayerAuthenticationDidChangeNotificationName: &'static NSNotificationName;
}

/// Deprecated.
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
impl GKLocalPlayer {
    extern_methods!(
        #[cfg(feature = "block2")]
        #[deprecated]
        #[unsafe(method(setDefaultLeaderboardCategoryID:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDefaultLeaderboardCategoryID_completionHandler(
            &self,
            category_id: Option<&NSString>,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        #[deprecated]
        #[unsafe(method(loadDefaultLeaderboardCategoryIDWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadDefaultLeaderboardCategoryIDWithCompletionHandler(
            &self,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSString, *mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        #[deprecated]
        #[unsafe(method(authenticateWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn authenticateWithCompletionHandler(
            &self,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        #[deprecated]
        #[unsafe(method(loadFriendPlayersWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadFriendPlayersWithCompletionHandler(
            &self,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
            >,
        );

        #[cfg(feature = "block2")]
        /// Generates a signature allowing 3rd party server to authenticate the GKLocalPlayer
        /// Possible reasons for error:
        /// 1. Communications problem
        /// 2. Unauthenticated player
        #[deprecated]
        #[unsafe(method(generateIdentityVerificationSignatureWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn generateIdentityVerificationSignatureWithCompletionHandler(
            &self,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut NSURL, *mut NSData, *mut NSData, u64, *mut NSError)>,
            >,
        );
    );
}

/// Obsoleted.
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
impl GKLocalPlayer {
    extern_methods!(
        #[cfg(feature = "block2")]
        /// This method is obsolete. It will never be invoked and its implementation does nothing**
        #[deprecated]
        #[unsafe(method(loadFriendsWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadFriendsWithCompletionHandler(
            &self,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut NSArray<NSString>, *mut NSError)>,
            >,
        );

        /// This property is obsolete. **
        #[deprecated]
        #[unsafe(method(friends))]
        #[unsafe(method_family = none)]
        pub unsafe fn friends(&self) -> Option<Retained<NSArray<NSString>>>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkfriendsauthorizationstatus?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKFriendsAuthorizationStatus(pub NSInteger);
impl GKFriendsAuthorizationStatus {
    #[doc(alias = "GKFriendsAuthorizationStatusNotDetermined")]
    pub const NotDetermined: Self = Self(0);
    #[doc(alias = "GKFriendsAuthorizationStatusRestricted")]
    pub const Restricted: Self = Self(1);
    #[doc(alias = "GKFriendsAuthorizationStatusDenied")]
    pub const Denied: Self = Self(2);
    #[doc(alias = "GKFriendsAuthorizationStatusAuthorized")]
    pub const Authorized: Self = Self(3);
}

unsafe impl Encode for GKFriendsAuthorizationStatus {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for GKFriendsAuthorizationStatus {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// FriendsList.
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
impl GKLocalPlayer {
    extern_methods!(
        #[cfg(feature = "block2")]
        #[unsafe(method(loadFriendsAuthorizationStatus:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadFriendsAuthorizationStatus(
            &self,
            completion_handler: &block2::DynBlock<
                dyn Fn(GKFriendsAuthorizationStatus, *mut NSError),
            >,
        );

        #[cfg(feature = "block2")]
        #[unsafe(method(loadFriends:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadFriends(
            &self,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
        );

        #[cfg(feature = "block2")]
        #[unsafe(method(loadFriendsWithIdentifiers:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadFriendsWithIdentifiers_completionHandler(
            &self,
            identifiers: &NSArray<NSString>,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
        );
    );
}

/// UI.
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
impl GKLocalPlayer {
    extern_methods!(
        #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
        #[cfg(target_os = "macos")]
        /// # Safety
        ///
        /// - The returned block's argument 1 must be a valid pointer or null.
        /// - The returned block's argument 2 must be a valid pointer or null.
        #[unsafe(method(authenticateHandler))]
        #[unsafe(method_family = none)]
        pub unsafe fn authenticateHandler(
            &self,
            mtm: MainThreadMarker,
        ) -> *mut block2::DynBlock<dyn Fn(*mut NSViewController, *mut NSError)>;

        #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
        #[cfg(target_os = "macos")]
        /// Setter for [`authenticateHandler`][Self::authenticateHandler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setAuthenticateHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAuthenticateHandler(
            &self,
            authenticate_handler: Option<
                &block2::DynBlock<dyn Fn(*mut NSViewController, *mut NSError)>,
            >,
        );

        /// observable property that becomes true when the friend request view controller is displayed.  It becomes false when it is dismissed
        #[unsafe(method(isPresentingFriendRequestViewController))]
        #[unsafe(method_family = none)]
        pub unsafe fn isPresentingFriendRequestViewController(&self) -> bool;

        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        /// presentFriendRequestCreatorFromViewController:
        ///
        /// Discussion:
        /// iOS only. When invoked, a Messages sheet will be presented on the viewController passed in, using the existing flow of presentation on behalf of an application.
        /// If an error is returned, control are returned directly to the application, without presentation.
        ///
        /// Possible reasons for error:
        /// - The local player user account is not allowed to add friends
        /// - The device is not allowing outgoing traffic at the time of the operation
        #[unsafe(method(presentFriendRequestCreatorFromViewController:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn presentFriendRequestCreatorFromViewController_error(
            &self,
            view_controller: &NSViewController,
        ) -> Result<(), Retained<NSError>>;

        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        /// presentFriendRequestCreatorFromWindow:
        ///
        /// Discussion:
        /// MacOS only. When invoked, if no error is encountered, the caller application is backgrounded and the 'Messages' application is launched/foregrounded, with a formatted friend request message.
        /// If an error occurs, controls are returned to the caller application, with an error describing the error.
        ///
        /// Possible reasons for error:
        /// - The local player user account is not allowed to add friends
        /// - The device is not allowing outgoing traffic at the time of the operation
        #[unsafe(method(presentFriendRequestCreatorFromWindow:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn presentFriendRequestCreatorFromWindow_error(
            &self,
            window: Option<&NSWindow>,
        ) -> Result<(), Retained<NSError>>;
    );
}