I am trying to display the message contained in the push notification through the application delegate, as indicated in the parse.com documentation.
The problem I am facing is that in my viewdidload method for my first view controller, I present a warning that the user MUST see before using the application.
How can I call a method from my application delegate after the user sees a warning from the viewdidload method?
EDIT:
So, as suggested in the comments, a global variable is added that I set to true after I displayed a warning from my ViewDidload method, but the alert notification from my appDelegate application is still not showing.
here is my delegate.m file application:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [Parse setApplicationId:@"xxxxxxxxxxxxxxxx" clientKey:@"xxxxxxxxxxxx"]; // Register for 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 for 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 is my viewdidload method:
RoadSafetyAppAppDelegate *AppDelegate; - (void)viewDidLoad { AppDelegate = (RoadSafetyAppAppDelegate *)[[UIApplication sharedApplication] delegate]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a 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 a mobile phone whilst driving is against the law. Ensure that you are not behind the wheel when using this app.", "") delegate:nil cancelButtonTitle:@"I agree to not use a mobile phone while driving" otherButtonTitles: nil]; [alert show]; appCounter = appCounter+1; AppDelegate.NotificationAlert = @"1"; AppDelegate.Notification = true; } }
source share