Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-02-2010, 06:58 AM   #1 (permalink)
Follow Me! Developer
 
Join Date: Nov 2010
Posts: 3
iFlo is on a distinguished road
Default Handling network errors while reporting GKScore?

Hello,

Using Game Center in my app, I have to report scores, and to handle network errors.
I wrote some code but it doesn't work. And I have no info from the debugger.
I have a "HighScore.plist" file in my Resources panel, which is basically a NSDictionary with one key : "highScore", of Data type.

Here is my code :
Code:
-(void)reportScore:(int)score forCategory:(NSString *)category {
	GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
	scoreReporter.value = score;
	
	[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
		if (error != nil) {
			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error"
														message:@"You are not connected to the Game Center, or you are not currently connected to the internet. Your score will be posted later."
														delegate:self
														cancelButtonTitle:@"OK"
														otherButtonTitles:nil];
			[alert show];
			[alert release];
			
			
			
			NSMutableDictionary *highScores = [[NSMutableDictionary alloc] initWithContentsOfFile:[self dataFilePath]];
			
			if (scoreReporter.value > [[highScores objectForKey:@"highScore"] intValue]) {
				[highScores setObject:scoreReporter forKey:@"highScore"];
			}
			
			
			
			
		}
	}];
}
The dataFilePath method :

Code:
-(NSString*)dataFilePath {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	return [documentsDirectory stringByAppendingPathComponent:@"HighScore.plist"];
}
And, finally, in the app delegate, in the didFinishLaunchingWithOptions: method :
Code:
NSMutableDictionary *highScores = [[NSMutableDictionary alloc] initWithContentsOfFile:[self dataFilePath]];
	
	GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"001"] autorelease];
	scoreReporter.value = [[highScores objectForKey:@"highScore"]intValue];
	
	[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
		if (error != nil) {
			
			[highScores setObject:scoreReporter forKey:@"highScore"];

		}
	}];
(With the same dataFilePath method)

Do you have any ideas?

Thanks for your answers.
iFlo is offline   Reply With Quote
Old 11-02-2010, 09:33 AM   #2 (permalink)
Follow Me! Developer
 
Join Date: Nov 2010
Posts: 3
iFlo is on a distinguished road
Default

Anyone?

EDIT : Woops, never mind, my code is really lame here. I figured it out.

Last edited by iFlo; 11-03-2010 at 08:56 AM.
iFlo is offline   Reply With Quote
Old 12-01-2010, 09:39 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 1
shuwee is on a distinguished road
Default Same Issue

Hey I am trying to implement the Game Center for the first time and have completed most of the things however I was struck with this network failure issue..

It would be great if you can guide me or let me know how to save the score and update later when network is available.

Thanks a lot!!
shuwee is offline   Reply With Quote
Reply

Bookmarks

Tags
errors, gkscore, plist

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 337
12 members and 325 guests
7twenty7, chiataytuday, condor304, Creativ, Domele, dreamdash3, laureix68, LEARN2MAKE, mistergreen2011, mottdog, palme2elie, Paul Slocum
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,660
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, laureix68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:24 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0