I’m having a bit of a nightmare trying to implement the ability to have two players playing against each other on my iPhone app through Game Center.
I am simply trying to access a function within GameCenterManager.m from a different .m file that I have. In my racetohundredViewController.h file I have:
#import <UIKit/UIKit.h>
#import "startPage.h"
#import "GameCenterManager.h"
#import <GameKit/GameKit.h>
@interface racetohundredViewController : UIViewController <UIActionSheetDelegate, GKLeaderboardViewControllerDelegate, GameCenterManagerDelegate>
{
GameCenterManager *gcManager;
BOOL gameIsMultiplayer;
double randomHostNumber;
}
@property (retain, nonatomic) GameCenterManager *gcManager;
in my corresponding .m file I have:
@interface racetohundredViewController ()
@end
@implementation racetohundredViewController
@synthesize gcManager;
- (void)generateAndSendHostNumber;
{
NSLog(@"Generate and send host number");
randomHostNumber = arc4random();
NSString *randomNumberString = [NSString stringWithFormat: @"$Host:%f", randomHostNumber];
NSLog(@"the random number string is: %@", randomNumberString);
[self.gcManager testString];
[self.gcManager sendStringToAllPeers:randomNumberString reliable: YES];
}
- (void)viewDidLoad
{
[self generateAndSendHostNumber];
}
It’s the [self.gcManager testString]; and [self.gcManager sendStringToAllPeers:randomNumberString reliable: YES]; that are not being called. They were before, I have clearly messed it up somehow. I can see the NSLog for the random number string.
In my GameCenterManager.h file I have (including some bits unrelated to this problem):
#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>
@class GKLeaderboard, GKAchievement, GKPlayer;
@protocol GameCenterManagerDelegate <NSObject>
@optional
- (void) processGameCenterAuthentication: (NSError*) error;
- (void) scoreReported: (NSError*) error;
- (void) reloadScoresComplete: (GKLeaderboard*) leaderBoard error: (NSError*) error;
- (void) achievementSubmitted: (GKAchievement*) ach error:(NSError*) error;
- (void) achievementResetResult: (NSError*) error;
- (void) mappedPlayerIDToPlayer: (GKPlayer*) player error: (NSError*) error;
- (void) receivedData:(NSDictionary *)dataDictionary;
@end
@interface GameCenterManager : NSObject <GameCenterManagerDelegate>
{
id <GameCenterManagerDelegate, NSObject> delegate;
NSMutableDictionary* earnedAchievementCache;
id matchOrSession;
}
//This property must be atomic to ensure that the cache is always in a viable state...
@property (retain) NSMutableDictionary* earnedAchievementCache;
@property (nonatomic, strong) id <GameCenterManagerDelegate, NSObject> delegate;
@property(nonatomic, strong) id matchOrSession;
+ (BOOL) isGameCenterAvailable;
- (void) authenticateLocalUser;
- (void)sendStringToAllPeers:(NSString *)dataString reliable:(BOOL)reliable;
- (void)sendString:(NSString *)dataString toPeers:(id)peers reliable: (BOOL)reliable;
-(void)testString;
and finally a cut down version of the .m file for GameCenterManager:
#import "GameCenterManager.h"
#import <GameKit/GameKit.h>
@implementation GameCenterManager
@synthesize earnedAchievementCache;
@synthesize delegate;
@synthesize matchOrSession;
-(void)testString
{
NSLog(@"THIS IS A TEST");
}
I could post code about sendString too but the principle is that even with the basic testString function it is not calling it.
Am I missing something very obvious here? It seems when I step through the code it will highlight the function in the .h file of GameCenterManager, but it won’t then display the NSLog as I request.
My best guess would be that
self.gcManagerisnil. Where do you instantiate yourGameCenterManager?