SHGameCenter 0.8.0

SHGameCenter 0.8.0

测试测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2014 年 12 月

Seivan Heidari 维护。



  • Seivan Heidari

在 GameKit 框架上添加带前缀的分类便利选择器,同时也添加块(Blocks)代替代理(Delegate)调用。

SHGameCenter 为 GKTurnBasedMatch 添加类或实例观察者以处理比赛,还添加了验证状态观察者。处理缓存图像以及显示名称。接收一切!

此 Pod 是许多组件的一部分,旨在填补 Foundation、UIKit、CoreLocation、GameKit、MapKit 以及 iOS 应用程序架构其他方面的空白。

依赖状态

测试 版本 平台
SHFastEnumerationProtocols

设置

安装

pod 'SHGameCenter'

使用

#import "SHGameCenter.h"

GKLocalPlayer

API

#pragma mark - Authentication
//handles on foreground notifications
+(void)SH_authenticateWithLoginViewControllerBlock:(SHGameViewControllerBlock)theLoginViewControllerBlock
                                     didLoginBlock:(SHGameCompletionBlock)theLoginBlock
                                    didLogoutBlock:(SHGameCompletionBlock)theLogoutBlock
                                    withErrorBlock:(SHGameErrorBlock)theErrorBlock;

#pragma mark - Properties
#pragma mark - Player Getters
+(GKLocalPlayer *)SH_me;
+(void)SH_requestFriendsWithBlock:(SHGameListsBlock)theBlock;

用法

  __weak SHSessionViewController * blockSelf = self;
  [GKLocalPlayer SH_authenticateWithLoginViewControllerBlock:^(UIViewController *viewController) {
    [blockSelf presentViewController:viewController animated:YES completion:nil];
  } didLoginBlock:^{
    [blockSelf performSegueWithIdentifier:@"SHLoggedIn" sender:self];
  } didLogoutBlock:^{
    [blockSelf dismissViewControllerAnimated:NO completion:nil];
  } withErrorBlock:^(NSError *error) {
    [blockSelf showAlertWithError:error];
  }];

GKPlayer

API

#pragma mark - Getter
@property(nonatomic,readonly) UIImage * SH_photo;

GKTurnBasedMatch

API

#pragma mark - Participant Getters
@property(nonatomic,readonly) GKTurnBasedParticipant  * SH_meAsParticipant;
@property(nonatomic,readonly) NSArray                 * SH_participantsWithoutMe;
@property(nonatomic,readonly) NSArray                 * SH_participantsWithoutCurrent;
@property(nonatomic,readonly) NSArray                 * SH_participantsNextOrder;
@property(nonatomic,readonly) NSArray                 * SH_playerIdentifiers;


#pragma mark - Conditions
@property(nonatomic,readonly) BOOL SH_isMyTurn;
//Participants who are neither active nor invited - e.g done, declined and etc
@property(nonatomic,readonly) BOOL SH_hasIncompleteParticipants;

@property(nonatomic,readonly) BOOL SH_isMatchStatusOpen;
@property(nonatomic,readonly) BOOL SH_isMatchStatusMatching;
@property(nonatomic,readonly) BOOL SH_isMatchStatusEnded;
@property(nonatomic,readonly) BOOL SH_isMatchStatusUnknown;



#pragma mark - Observer
-(void)SH_setObserver:(id)theObserver
  matchEventTurnBlock:(SHGameMatchEventTurnBlock)theMatchEventTurnBlock
 matchEventEndedBlock:(SHGameMatchEventEndedBlock)theMatchEventEndedBlock;

+(void)SH_setObserver:(id)theObserver
matchEventTurnBlock:(SHGameMatchEventTurnBlock)theMatchEventTurnBlock
matchEventEndedBlock:(SHGameMatchEventEndedBlock)theMatchEventEndedBlock
matchEventInvitesBlock:(SHGameMatchEventInvitesBlock)theMatchEventInvitesBlock;



#pragma mark - Preloaders

+(void)SH_requestMatchesWithBlock:(SHGameListsBlock)theMatchesBlock
              andFriendsWithBlock:(SHGameListsBlock)theFriendsBlock
              withCompletionBlock:(SHGameCompletionBlock)theCompletionBlock;


#pragma mark - Player
-(void)SH_requestPlayersWithBlock:(SHGameListsBlock)theBlock;


#pragma mark - Equal
-(BOOL)SH_isEqualToMatch:(id)object;


#pragma mark - Match Getters
+(void)SH_requestMatchesWithBlock:(SHGameListsBlock)theBlock;




#pragma mark - Match Setters
-(void)SH_resignWithBlock:(SHGameMatchBlock)theBlock;

-(void)SH_deleteWithBlock:(SHGameMatchBlock)theBlock;

用法

实例

  __weak TELMatchShowViewController *blockSelf = self;
  [self.match SH_setObserver:self matchEventTurnBlock:^(GKTurnBasedMatch *match, BOOL didBecomeActive) {
    [blockSelf handleTurnEventForMatch:match didBecomeActive:didBecomeActive];

  } matchEventEndedBlock:^(GKTurnBasedMatch *match) {
    blockSelf.txtView.text = @"ENDED";
  }];

  [GKTurnBasedMatch SH_setObserver:self matchEventTurnBlock:^(GKTurnBasedMatch *match, BOOL didBecomeActive) {


    BOOL isInList = [self.orderedSetsOfMatches containsObject:match];

    if(isInList)
      [self.orderedSetsOfMatches replaceObjectAtIndex:[self.orderedSetsOfMatches
                                                       indexOfObject:match]
                                           withObject:match];
    else
      [self.orderedSetsOfMatches addObject:match];


    NSArray * indexPaths = @[[NSIndexPath
                              indexPathForRow:[self.orderedSetsOfMatches indexOfObject:match]
                              inSection:0]];

    if(self.currentSelectedOrderedSet == self.orderedSetsOfMatches)
      [self.viewCollection performBatchUpdates:^{
        if(isInList)
          [self.viewCollection reloadItemsAtIndexPaths:indexPaths];
        else
          [self.viewCollection insertItemsAtIndexPaths:indexPaths];
      } completion:nil];

  } matchEventEndedBlock:^(GKTurnBasedMatch *match) {

  } matchEventInvitesBlock:^(NSArray *playersToInvite) {

  }];

GKTurnBasedParticipant

API

enum {
  SHTurnBasedMatchOutcomeNone         = 0,        // Participants who are not done with a match have this state
  SHTurnBasedMatchOutcomeQuit         = 1,        // Participant quit
  SHTurnBasedMatchOutcomeWon          = 2,        // Participant won
  SHTurnBasedMatchOutcomeLost         = 3,        // Participant lost
  SHTurnBasedMatchOutcomeTied         = 4,        // Participant tied
  SHTurnBasedMatchOutcomeTimeExpired  = 5,        // Game ended due to time running out
  SHTurnBasedMatchOutcomeFirst        = 6,
  SHTurnBasedMatchOutcomeSecond       = 7,
  SHTurnBasedMatchOutcomeThird        = 8,
  SHTurnBasedMatchOutcomeFourth       = 9,
  SHTurnBasedMatchOutcomeFifth        = 10,
  SHTurnBasedMatchOutcomeSixth        = 11,
  SHTurnBasedMatchOutcomeSeventh      = 12,
  SHTurnBasedMatchOutcomeEighth       = 13,
  SHTurnBasedMatchOutcomeNinth        = 14,
  SHTurnBasedMatchOutcomeTenth        = 16,
  SHTurnBasedMatchOutcomeEleventh     = 17,
  SHTurnBasedMatchOutcomeTwelvth      = 18,


  SHTurnBasedMatchOutcomeCustomRange = 0x00FF0000 // game result range available for custom app use

};
typedef NSInteger SHTurnBasedMatchOutcome;


#pragma mark -
#pragma mark Getter
@property(nonatomic,readonly) NSString * SH_alias;
@property(nonatomic,readonly) UIImage  * SH_photo;

#pragma mark -
#pragma mark Conditions
@property(nonatomic,readonly) BOOL SH_isMe;

#pragma mark -
#pragma mark GKTurnBasedParticipantStatus
@property(nonatomic,readonly) BOOL SH_isActiveOrInvited;
@property(nonatomic,readonly) BOOL SH_isInvited;
@property(nonatomic,readonly) BOOL SH_isActive;
@property(nonatomic,readonly) BOOL SH_isMatching;
@property(nonatomic,readonly) BOOL SH_isDone;

#pragma mark -
#pragma mark GKTurnBasedMatchOutcome
@property(nonatomic,readonly) BOOL SH_hasMatchOutcomeNone;
@property(nonatomic,readonly) BOOL SH_hasMatchOutcomeQuit;
@property(nonatomic,readonly) BOOL SH_hasMatchOutcomeWon;
@property(nonatomic,readonly) BOOL SH_hasMatchOutcomeWithPosition;

联系

如果您在一个项目中使用了 SHFoundationAdditions,我希望听到您的消息。

电子邮件:[email protected]
Twitter:@seivanheidari

许可

SHGameCenter版权所有©2013 Seivan,并且可以在MIT许可协议下自由分发。请参阅LICENSE.md文件。