-(IBAction)submitScore{
NSString *connectionString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"]];
//Do this if your not connected ot internet/offline.
if([connectionString length] == 0){
//Leave spaces in failureAlert message! These allow the texfield to line up correctly and not overlap.
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle:@"Offline - Submit Local Score" message:@"While offline you can only submit your score locally. This will not be seen by the player. " delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Submit Score Locally", nil];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(12, 110, 260, 25)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[failureAlert addSubview:nameField];
nameField.placeholder = @"Enter Name Here...";
nameField.borderStyle = UITextBorderStyleLine;
nameField.delegate = self;
[failureAlert show];
[failureAlert release];
}
//Do this if the player is connected to the internet.
else{
UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"Submit Score"
message:@"Choose below to submit your score to global leaderboards, locally, or both."
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Global", @"Local", @"Both", nil];
[successAlert show];
[successAlert release];
[connectionString release];
}
}
-(void)successAlert:(UIAlertView *)successAlert clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 1){
[OFHighScoreService setHighScore: score forLeaderboard:@"371803" onSuccess:OFDelegate () onFailure:OFDelegate ()];
UIAlertView *onlineSuccessAlert = [[UIAlertView alloc] initWithTitle:@"Successfully Submitted!"
message:@"You have successfully submitted your score to the online leaderboards!"
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[onlineSuccessAlert show];
[onlineSuccessAlert release];
}
if(buttonIndex == 2){
[highScoresArray addObject:[NSString stringWithFormat:@"%@ - %i", nameField.text, score]];
UIAlertView *offlineAlert = [[UIAlertView alloc] initWithTitle:@"Submit Local Score" message:@"Enter your name below to submit a local score." delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Submit Score Locally", nil];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(12, 110, 260, 25)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[offlineAlert addSubview:nameField];
nameField.placeholder = @"Enter Name Here...";
nameField.borderStyle = UITextBorderStyleLine;
nameField.delegate = self;
[offlineAlert show];
[offlineAlert release];
}
if(buttonIndex == 3){
[OFHighScoreService setHighScore: score forLeaderboard:@"371803" onSuccess:OFDelegate () onFailure:OFDelegate ()];
[highScoresArray addObject:[NSString stringWithFormat:@"%@ - %i", nameField.text, score]];
UIAlertView *offlineAlert = [[UIAlertView alloc] initWithTitle:@"Submit Local Score" message:@"Enter your name below to submit a local score." delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Submit Score Locally", nil];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(12, 110, 260, 25)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[offlineAlert addSubview:nameField];
nameField.placeholder = @"Enter Name Here...";
nameField.borderStyle = UITextBorderStyleLine;
nameField.delegate = self;
[offlineAlert show];
[offlineAlert release];
}
}