ios - Displaying alert from app delegate before displaying alert from viewDidload -


i attempting display message contained within push notification through app delegate outlined in parse.com documentation.

the problem having in viewdidload method first view controller, presenting alert user must see before use app.

how can call method app delegate after user sees alert viewdidload method?

edit:

so have, suggested in comments, added global variable set true once have displayed alert viewdidload method, notification alert appdelegate still not appear.

here app delegate.m file:

    - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     // override point customization after application launch.     [parse setapplicationid:@"xxxxxxxxxxxxxxxx"                   clientkey:@"xxxxxxxxxxxx"];      // register push notitications, if running ios 8     if ([application respondstoselector:@selector(registerusernotificationsettings:)]) {         uiusernotificationtype usernotificationtypes = (uiusernotificationtypealert |                                                         uiusernotificationtypebadge |                                                         uiusernotificationtypesound);         uiusernotificationsettings *settings = [uiusernotificationsettings settingsfortypes:usernotificationtypes                                                                                  categories:nil];         [application registerusernotificationsettings:settings];         [application registerforremotenotifications];     } else {         // register push notifications before ios 8         [application registerforremotenotificationtypes:(uiremotenotificationtypebadge |                                                          uiremotenotificationtypealert |                                                          uiremotenotificationtypesound)];     }     return yes;        nsdictionary *notificationpayload = launchoptions[uiapplicationlaunchoptionsremotenotificationkey];       if (notification == true) {         if (![pushtext  isequal: @""]) {             pushtext = [[notificationpayload objectforkey:@"aps"] objectforkey:@"alert"];             uialertview *alert_news = [[uialertview alloc] initwithtitle:nslocalizedstring(@"news", "")                                                                  message:pushtext                                                                 delegate:nil                                                        cancelbuttontitle:@"ok"                                                        otherbuttontitles: nil];             [alert_news show];               }     }   } 

and here viewdidload method:

 roadsafetyappappdelegate *appdelegate;  - (void)viewdidload {         appdelegate = (roadsafetyappappdelegate *)[[uiapplication sharedapplication] delegate];         [super viewdidload];      // additional setup after loading view, typically nib.        backgroundimage.alpha = 0.3;     torecipients = [[nsarray alloc]initwithobjects:@"records@shellharbour.nsw.gov.au", nil];     static int appcounter;     if ( appcounter < 1   ) {         uialertview *alert = [[uialertview alloc] initwithtitle:nslocalizedstring(@"disclaimer", "")                                                         message:nslocalizedstring(@"using mobile phone whilst driving against law. ensure not behind wheel when using app.", "")                                                        delegate:nil                                               cancelbuttontitle:@"i agree not use mobile phone while driving"                                               otherbuttontitles: nil];         [alert show];         appcounter = appcounter+1;         appdelegate.notificationalert = @"1";         appdelegate.notification = true;        }  } 

since want show disclaimer 1 time , sure user saw , taped on agree button before showing notification. can using simple local notification.

in delegate (...didfinishlaunchingwithoptions:)

 -(bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions{          //......you code here         if ([[nsuserdefaults standarduserdefaults] boolforkey:@"disclaimershown"]==nil)              [[nsuserdefaults standarduserdefaults] setbool:no forkey:@"disclaimershown"];             [[nsuserdefaults standarduserdefaults] synchronize];         }            //......you code here          if ([[nsuserdefaults standarduserdefaults] boolforkey:@"disclaimershown"]){ //yes                      if (![pushtext  isequal: @""]) {                     pushtext = [[notificationpayload objectforkey:@"aps"] objectforkey:@"alert"];                     uialertview *alert_news = [[uialertview alloc] initwithtitle:nslocalizedstring(@"news", "")                                                                          message:pushtext                                                                         delegate:nil                                                                cancelbuttontitle:@"ok"                                                                otherbuttontitles: nil];                     [alert_news show];                       }             } }   -(void)application:(uiapplication *)application didreceivelocalnotification:(uilocalnotification *)notification{      nsstring *value=[nsstring stringwithformat:@"%@",[notification.userinfo valueforkey:@"key"]];     if ([value isequaltostring:@"disclaimershown"]) {                 [[nsuserdefaults standarduserdefaults] setbool:yes forkey:@"disclaimershown"];                 [[nsuserdefaults standarduserdefaults] synchronize];      ///continue handle parse.com notification     }  } 

in viewcontroller:

-(void)viewdidload{             //...              if ([[nsuserdefaults standarduserdefaults] boolforkey:@"disclaimershown"]==no){                         uialertview *alert = [[uialertview alloc] initwithtitle:nslocalizedstring(@"disclaimer", "")                                                                     message:nslocalizedstring(@"using mobile phone whilst driving against law. ensure not behind wheel when using app.", "")                                                                    delegate:nil                                                           cancelbuttontitle:@"i agree not use mobile phone while driving"                                                           otherbuttontitles: nil];                     alert.tag = 1;                     [alert show];                }               //... } 

pragma mark - uialertviewdelegate

- (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex {     if (alertview.tag == 1) {//the disclaimer alert         if (buttonindex == 0) {             uilocalnotification *alarm = [[uilocalnotification alloc] init];             alarm.userinfo = @{@"key": @"disclaimershown"};             alarm.firedate = [nsdate date];             alarm.timezone = [nstimezone defaulttimezone];              [[uiapplication sharedapplication] schedulelocalnotification:alarm];         }     }  } 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -