UIAlertViewの代わりに、UIAlertControllerを使用するいくつかの方法を試しました。いくつかの方法を試しましたが、アラートアクションを機能させることができません。これは、IOS 8とIOS 9で正常に動作する私のコードですが、非推奨のフラグで表示されています。以下のエレガントな提案を試してみましたが、このコンテキストでは機能しません。私は自分のアプリを提出する必要があり、これは対処する最後のことです。さらなる提案をありがとう。私は初心者です。
#pragma mark - BUTTONS ================================
- (IBAction)showModesAction:(id)sender {
NSLog(@"iapMade: %d", iapMade3);
// IAP MADE ! ===========================================
if (!iapMade3) {
//start game here
gamePlaysCount++;
[[NSUserDefaults standardUserDefaults]setInteger:gamePlaysCount forKey:@"gamePlaysCount"];
NSLog(@"playsCount: %ld", (long)gamePlaysCount);
if (gamePlaysCount >= 4) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Basic"
message: THREE_PLAYS_LIMIT_MESSAGE
delegate:self
cancelButtonTitle:@"Yes, please"
otherButtonTitles:@"No, thanks", nil];
[alert show];
NSString *path = [[NSBundle mainBundle] pathForResource:@"cow" ofType:@"wav"];
_pop =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[_pop play];
[self dismissViewControllerAnimated:true completion:nil];
} else {
if (gamePlaysCount == 1) {
// Create & store the next 5 mins when player gets 3 more lives
nextDateToPlay = [[NSDate date] dateByAddingTimeInterval:60*60*0.1];
NSLog(@"CURRENT DATE: %@", [NSDate date]);
NSLog(@"NEXT DAY: %@", nextDateToPlay);
[[NSUserDefaults standardUserDefaults]setObject: nextDateToPlay forKey:@"nextDateToPlay"];
NSLog(@"nextDateToPlay: %@", nextDateToPlay);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Basic"
message: THREE_PLAYS_LIMIT_MESSAGE2
delegate:self
cancelButtonTitle:@"Got it!"
otherButtonTitles:@"Start", nil];
[alert show];
} else {
if (gamePlaysCount == 3) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Basic"
message: THREE_PLAYS_LIMIT_MESSAGE3
delegate:self
cancelButtonTitle:@"Yep, I Know!"
otherButtonTitles:@"Start", nil];
[alert show];
}
}
}
}
}
// IAP NOT MADE =============================
#pragma mark - ALERTVIEW DELEGATE ============================
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"Yes, please"]) {
UIStoryboard *storyboard = self.storyboard;
MenuViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"Store"];
svc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:svc animated:YES completion:nil];
}
}