Próbuję wyświetlić komunikat zawarty w powiadomieniu push przez delegata aplikacji, zgodnie z opisem w dokumentacji parse.com.Wyświetlanie alertu od delegata aplikacji przed wyświetleniem alertu z viewDidload
Problem polega na tym, że w mojej metodzie viewdidload dla mojego pierwszego kontrolera widoku, przedstawiam alert, który użytkownik MUSI zobaczyć przed użyciem aplikacji.
Jak mogę wywołać tę metodę z delegata aplikacji, gdy użytkownik zobaczy alert z metody viewdidload?
EDIT:
więc mam, jak zasugerowano w komentarzach, dodał zmienna globalna, która ustawić na true raz mam wyświetlony alert z mojego sposobu viewDidLoad, jednak uderzył nieczysto zawiadomienie od mojego appDelegate nieruchomego nie pojawia się.
tutaj jest mój plik app delegate.m:
- (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];
}
}
}
I tu jest moja metoda viewDidLoad:
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:@"[email protected]", 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;
}
}
Od delegata aplikacji można ustawić zmienną bool showPushMessage w kontrolerze widoku, a następnie wyświetlać alert wiadomości Push po zwolnieniu pierwszego alertu w przypadku showPushMessage == YES. –
czy mógłbyś podać trochę kodu, żeby to opisać? Jestem trochę nowy w korzystaniu z funkcji delegowania aplikacji w celu dodatkowej manipulacji. – scb998
Aplikacja powinna natychmiast wyświetlać powiadomienie powiadomienia push, jeśli aplikacja jest już otwarta, a użytkownik zaakceptował już ostrzeżenie o naruszeniu zasad, prawda? –