objective c - UIAlertView first deprecated IOS 9 -


i have tried several ways use uialertcontroller,instead of uialertview. tried several ways cannot make alert action work. here code works fine in ios 8 , ios 9 showing deprecated flags. tried elegant suggestion below can't make function in context. need submit app , last thing address. thank further suggestions. newbie.

#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 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, 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];          }  } 

from ios8 apple provide new uialertcontroller class can use instead of uialertview deprecated, stated in depreciation message

uialertview deprecated. use uialertcontroller preferredstyle of uialertcontrollerstylealert instead

so should use this

uialertcontroller * alert = [uialertcontroller                 alertcontrollerwithtitle:@"title"                                  message:@"message"                           preferredstyle:uialertcontrollerstylealert];    uialertaction* yesbutton = [uialertaction                     actionwithtitle:@"yes, please"                               style:uialertactionstyledefault                             handler:^(uialertaction * action) {                                 //handle yes please button action here                             }];  uialertaction* nobutton = [uialertaction                         actionwithtitle:@"no, thanks"                                   style:uialertactionstyledefault                                 handler:^(uialertaction * action) {                                    //handle no, button                                                 }];  [alert addaction:yesbutton]; [alert addaction:nobutton];  [self presentviewcontroller:alert animated:yes completion:nil]; 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -