objc2_game_kit/generated/
GKLocalPlayer.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9use objc2_foundation::*;
10
11use crate::*;
12
13extern_class!(
14    /// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gklocalplayer?language=objc)
15    #[unsafe(super(GKPlayer, GKBasePlayer, NSObject))]
16    #[derive(Debug, PartialEq, Eq, Hash)]
17    #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
18    pub struct GKLocalPlayer;
19);
20
21#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
22extern_conformance!(
23    unsafe impl NSCopying for GKLocalPlayer {}
24);
25
26#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
27unsafe impl CopyingHelper for GKLocalPlayer {
28    type Result = Self;
29}
30
31#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
32extern_conformance!(
33    unsafe impl NSObjectProtocol for GKLocalPlayer {}
34);
35
36#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
37impl GKLocalPlayer {
38    extern_methods!(
39        /// Obtain the primary GKLocalPlayer object.
40        /// The player is only available for offline play until logged in.
41        /// A temporary player is created if no account is set up.
42        #[unsafe(method(local))]
43        #[unsafe(method_family = none)]
44        pub unsafe fn local() -> Retained<GKLocalPlayer>;
45
46        #[unsafe(method(localPlayer))]
47        #[unsafe(method_family = none)]
48        pub unsafe fn localPlayer() -> Retained<GKLocalPlayer>;
49
50        /// Authentication state
51        #[unsafe(method(isAuthenticated))]
52        #[unsafe(method_family = none)]
53        pub unsafe fn isAuthenticated(&self) -> bool;
54
55        /// Indicates if a player is under age
56        #[unsafe(method(isUnderage))]
57        #[unsafe(method_family = none)]
58        pub unsafe fn isUnderage(&self) -> bool;
59
60        /// A Boolean value that declares whether or not multiplayer gaming is restricted on this device.
61        #[unsafe(method(isMultiplayerGamingRestricted))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn isMultiplayerGamingRestricted(&self) -> bool;
64
65        /// 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.
66        #[unsafe(method(isPersonalizedCommunicationRestricted))]
67        #[unsafe(method_family = none)]
68        pub unsafe fn isPersonalizedCommunicationRestricted(&self) -> bool;
69
70        #[cfg(feature = "block2")]
71        /// 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.
72        /// Possible reasons for error:
73        /// 1. Communications problem
74        /// 2. Unauthenticated player
75        #[unsafe(method(loadRecentPlayersWithCompletionHandler:))]
76        #[unsafe(method_family = none)]
77        pub unsafe fn loadRecentPlayersWithCompletionHandler(
78            &self,
79            completion_handler: Option<
80                &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
81            >,
82        );
83
84        #[cfg(feature = "block2")]
85        /// 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.
86        /// Possible reasons for error:
87        /// 1. Communications problem
88        /// 2. Unauthenticated player
89        #[unsafe(method(loadChallengableFriendsWithCompletionHandler:))]
90        #[unsafe(method_family = none)]
91        pub unsafe fn loadChallengableFriendsWithCompletionHandler(
92            &self,
93            completion_handler: Option<
94                &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
95            >,
96        );
97
98        #[cfg(feature = "block2")]
99        /// Set the default leaderboard for the current game
100        /// Possible reasons for error:
101        /// 1. Communications problem
102        /// 2. Unauthenticated player
103        /// 3. Leaderboard not present
104        #[unsafe(method(setDefaultLeaderboardIdentifier:completionHandler:))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn setDefaultLeaderboardIdentifier_completionHandler(
107            &self,
108            leaderboard_identifier: &NSString,
109            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
110        );
111
112        #[cfg(feature = "block2")]
113        /// Load the default leaderboard identifier for the local player
114        /// Possible reasons for error:
115        /// 1. Communications problem
116        /// 2. Unauthenticated player
117        /// 3. Leaderboard not present
118        #[unsafe(method(loadDefaultLeaderboardIdentifierWithCompletionHandler:))]
119        #[unsafe(method_family = none)]
120        pub unsafe fn loadDefaultLeaderboardIdentifierWithCompletionHandler(
121            &self,
122            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSString, *mut NSError)>>,
123        );
124
125        #[cfg(feature = "block2")]
126        /// Generates a signature allowing 3rd party server to authenticate the GKLocalPlayer
127        /// Possible reasons for error:
128        /// 1. Communications problem
129        /// 2. Unauthenticated player
130        #[unsafe(method(fetchItemsForIdentityVerificationSignature:))]
131        #[unsafe(method_family = none)]
132        pub unsafe fn fetchItemsForIdentityVerificationSignature(
133            &self,
134            completion_handler: Option<
135                &block2::DynBlock<dyn Fn(*mut NSURL, *mut NSData, *mut NSData, u64, *mut NSError)>,
136            >,
137        );
138    );
139}
140
141/// Methods declared on superclass `GKPlayer`.
142#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
143impl GKLocalPlayer {
144    extern_methods!(
145        #[unsafe(method(anonymousGuestPlayerWithIdentifier:))]
146        #[unsafe(method_family = none)]
147        pub unsafe fn anonymousGuestPlayerWithIdentifier(
148            guest_identifier: &NSString,
149        ) -> Retained<Self>;
150    );
151}
152
153/// Methods declared on superclass `NSObject`.
154#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
155impl GKLocalPlayer {
156    extern_methods!(
157        #[unsafe(method(init))]
158        #[unsafe(method_family = init)]
159        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
160
161        #[unsafe(method(new))]
162        #[unsafe(method_family = new)]
163        pub unsafe fn new() -> Retained<Self>;
164    );
165}
166
167extern_protocol!(
168    /// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gklocalplayerlistener?language=objc)
169    #[cfg(all(
170        feature = "GKEventListener",
171        feature = "GKGameActivityListener",
172        feature = "GKMatchmaker",
173        feature = "GKSavedGameListener",
174        feature = "GKTurnBasedMatch"
175    ))]
176    pub unsafe trait GKLocalPlayerListener:
177        GKChallengeListener
178        + GKGameActivityListener
179        + GKInviteEventListener
180        + GKTurnBasedEventListener
181        + GKSavedGameListener
182    {
183    }
184);
185
186/// GKLocalPlayerEvents.
187#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
188impl GKLocalPlayer {
189    extern_methods!(
190        #[cfg(all(
191            feature = "GKEventListener",
192            feature = "GKGameActivityListener",
193            feature = "GKMatchmaker",
194            feature = "GKSavedGameListener",
195            feature = "GKTurnBasedMatch"
196        ))]
197        /// 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.
198        #[unsafe(method(registerListener:))]
199        #[unsafe(method_family = none)]
200        pub unsafe fn registerListener(&self, listener: &ProtocolObject<dyn GKLocalPlayerListener>);
201
202        #[cfg(all(
203            feature = "GKEventListener",
204            feature = "GKGameActivityListener",
205            feature = "GKMatchmaker",
206            feature = "GKSavedGameListener",
207            feature = "GKTurnBasedMatch"
208        ))]
209        #[unsafe(method(unregisterListener:))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn unregisterListener(
212            &self,
213            listener: &ProtocolObject<dyn GKLocalPlayerListener>,
214        );
215
216        #[unsafe(method(unregisterAllListeners))]
217        #[unsafe(method_family = none)]
218        pub unsafe fn unregisterAllListeners(&self);
219    );
220}
221
222extern "C" {
223    /// Notification will be posted whenever authentication status changes.
224    ///
225    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkplayerauthenticationdidchangenotificationname?language=objc)
226    pub static GKPlayerAuthenticationDidChangeNotificationName: &'static NSNotificationName;
227}
228
229/// Deprecated.
230#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
231impl GKLocalPlayer {
232    extern_methods!(
233        #[cfg(feature = "block2")]
234        #[deprecated]
235        #[unsafe(method(setDefaultLeaderboardCategoryID:completionHandler:))]
236        #[unsafe(method_family = none)]
237        pub unsafe fn setDefaultLeaderboardCategoryID_completionHandler(
238            &self,
239            category_id: Option<&NSString>,
240            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
241        );
242
243        #[cfg(feature = "block2")]
244        #[deprecated]
245        #[unsafe(method(loadDefaultLeaderboardCategoryIDWithCompletionHandler:))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn loadDefaultLeaderboardCategoryIDWithCompletionHandler(
248            &self,
249            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSString, *mut NSError)>>,
250        );
251
252        #[cfg(feature = "block2")]
253        #[deprecated]
254        #[unsafe(method(authenticateWithCompletionHandler:))]
255        #[unsafe(method_family = none)]
256        pub unsafe fn authenticateWithCompletionHandler(
257            &self,
258            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
259        );
260
261        #[cfg(feature = "block2")]
262        #[deprecated]
263        #[unsafe(method(loadFriendPlayersWithCompletionHandler:))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn loadFriendPlayersWithCompletionHandler(
266            &self,
267            completion_handler: Option<
268                &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
269            >,
270        );
271
272        #[cfg(feature = "block2")]
273        /// Generates a signature allowing 3rd party server to authenticate the GKLocalPlayer
274        /// Possible reasons for error:
275        /// 1. Communications problem
276        /// 2. Unauthenticated player
277        #[deprecated]
278        #[unsafe(method(generateIdentityVerificationSignatureWithCompletionHandler:))]
279        #[unsafe(method_family = none)]
280        pub unsafe fn generateIdentityVerificationSignatureWithCompletionHandler(
281            &self,
282            completion_handler: Option<
283                &block2::DynBlock<dyn Fn(*mut NSURL, *mut NSData, *mut NSData, u64, *mut NSError)>,
284            >,
285        );
286    );
287}
288
289/// Obsoleted.
290#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
291impl GKLocalPlayer {
292    extern_methods!(
293        #[cfg(feature = "block2")]
294        /// This method is obsolete. It will never be invoked and its implementation does nothing**
295        #[deprecated]
296        #[unsafe(method(loadFriendsWithCompletionHandler:))]
297        #[unsafe(method_family = none)]
298        pub unsafe fn loadFriendsWithCompletionHandler(
299            &self,
300            completion_handler: Option<
301                &block2::DynBlock<dyn Fn(*mut NSArray<NSString>, *mut NSError)>,
302            >,
303        );
304
305        /// This property is obsolete. **
306        #[deprecated]
307        #[unsafe(method(friends))]
308        #[unsafe(method_family = none)]
309        pub unsafe fn friends(&self) -> Option<Retained<NSArray<NSString>>>;
310    );
311}
312
313/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkfriendsauthorizationstatus?language=objc)
314// NS_ENUM
315#[repr(transparent)]
316#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
317pub struct GKFriendsAuthorizationStatus(pub NSInteger);
318impl GKFriendsAuthorizationStatus {
319    #[doc(alias = "GKFriendsAuthorizationStatusNotDetermined")]
320    pub const NotDetermined: Self = Self(0);
321    #[doc(alias = "GKFriendsAuthorizationStatusRestricted")]
322    pub const Restricted: Self = Self(1);
323    #[doc(alias = "GKFriendsAuthorizationStatusDenied")]
324    pub const Denied: Self = Self(2);
325    #[doc(alias = "GKFriendsAuthorizationStatusAuthorized")]
326    pub const Authorized: Self = Self(3);
327}
328
329unsafe impl Encode for GKFriendsAuthorizationStatus {
330    const ENCODING: Encoding = NSInteger::ENCODING;
331}
332
333unsafe impl RefEncode for GKFriendsAuthorizationStatus {
334    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
335}
336
337/// FriendsList.
338#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
339impl GKLocalPlayer {
340    extern_methods!(
341        #[cfg(feature = "block2")]
342        #[unsafe(method(loadFriendsAuthorizationStatus:))]
343        #[unsafe(method_family = none)]
344        pub unsafe fn loadFriendsAuthorizationStatus(
345            &self,
346            completion_handler: &block2::DynBlock<
347                dyn Fn(GKFriendsAuthorizationStatus, *mut NSError),
348            >,
349        );
350
351        #[cfg(feature = "block2")]
352        #[unsafe(method(loadFriends:))]
353        #[unsafe(method_family = none)]
354        pub unsafe fn loadFriends(
355            &self,
356            completion_handler: &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
357        );
358
359        #[cfg(feature = "block2")]
360        #[unsafe(method(loadFriendsWithIdentifiers:completionHandler:))]
361        #[unsafe(method_family = none)]
362        pub unsafe fn loadFriendsWithIdentifiers_completionHandler(
363            &self,
364            identifiers: &NSArray<NSString>,
365            completion_handler: &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
366        );
367    );
368}
369
370/// UI.
371#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
372impl GKLocalPlayer {
373    extern_methods!(
374        #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
375        #[cfg(target_os = "macos")]
376        /// # Safety
377        ///
378        /// - The returned block's argument 1 must be a valid pointer or null.
379        /// - The returned block's argument 2 must be a valid pointer or null.
380        #[unsafe(method(authenticateHandler))]
381        #[unsafe(method_family = none)]
382        pub unsafe fn authenticateHandler(
383            &self,
384            mtm: MainThreadMarker,
385        ) -> *mut block2::DynBlock<dyn Fn(*mut NSViewController, *mut NSError)>;
386
387        #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
388        #[cfg(target_os = "macos")]
389        /// Setter for [`authenticateHandler`][Self::authenticateHandler].
390        ///
391        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
392        #[unsafe(method(setAuthenticateHandler:))]
393        #[unsafe(method_family = none)]
394        pub unsafe fn setAuthenticateHandler(
395            &self,
396            authenticate_handler: Option<
397                &block2::DynBlock<dyn Fn(*mut NSViewController, *mut NSError)>,
398            >,
399        );
400
401        /// observable property that becomes true when the friend request view controller is displayed.  It becomes false when it is dismissed
402        #[unsafe(method(isPresentingFriendRequestViewController))]
403        #[unsafe(method_family = none)]
404        pub unsafe fn isPresentingFriendRequestViewController(&self) -> bool;
405
406        #[cfg(feature = "objc2-app-kit")]
407        #[cfg(target_os = "macos")]
408        /// presentFriendRequestCreatorFromViewController:
409        ///
410        /// Discussion:
411        /// 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.
412        /// If an error is returned, control are returned directly to the application, without presentation.
413        ///
414        /// Possible reasons for error:
415        /// - The local player user account is not allowed to add friends
416        /// - The device is not allowing outgoing traffic at the time of the operation
417        #[unsafe(method(presentFriendRequestCreatorFromViewController:error:_))]
418        #[unsafe(method_family = none)]
419        pub unsafe fn presentFriendRequestCreatorFromViewController_error(
420            &self,
421            view_controller: &NSViewController,
422        ) -> Result<(), Retained<NSError>>;
423
424        #[cfg(feature = "objc2-app-kit")]
425        #[cfg(target_os = "macos")]
426        /// presentFriendRequestCreatorFromWindow:
427        ///
428        /// Discussion:
429        /// 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.
430        /// If an error occurs, controls are returned to the caller application, with an error describing the error.
431        ///
432        /// Possible reasons for error:
433        /// - The local player user account is not allowed to add friends
434        /// - The device is not allowing outgoing traffic at the time of the operation
435        #[unsafe(method(presentFriendRequestCreatorFromWindow:error:_))]
436        #[unsafe(method_family = none)]
437        pub unsafe fn presentFriendRequestCreatorFromWindow_error(
438            &self,
439            window: Option<&NSWindow>,
440        ) -> Result<(), Retained<NSError>>;
441    );
442}