Mein Problem ist, wenn App im Hintergrund ist und Benachrichtigung ankommt und ich öffnete die App von Symbol; App stellt es wieder her, aber ich möchte die Bildschirmdaten in diesem Fall aktualisieren. Gibt es eine Möglichkeit, die Daten im Hintergrund zu aktualisieren, wenn die Benachrichtigung eintrifft? HieriOS: Wenn App im Hintergrund ist und lokale Benachrichtigung angekommen ist; Welche Methode wird automatisch aufgerufen?
ist der Code, den ich für die Bekämpfung der diesen Fall bin mit:
ViewController.m
Datei Code:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appIsComingFromBackground:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
// Do any additional setup after loading the view, typically from a nib.
}
- (void) appIsComingFromBackground:(NSNotification *) note {
// code
NSString *hasMessage = [[NSUserDefaults standardUserDefaults] objectForKey:@"alertmsg"];
if([hasMessage length]!=0)
{
_labelText.text = hasMessage;
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"alertmsg"];
}
else{
_labelText.text = @"";
}
}
AppDelegate.m
Datei Code:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
if (application.applicationState == UIApplicationStateActive) {
}
else if(application.applicationState == UIApplicationStateBackground || application.applicationState == UIApplicationStateInactive)
{
[[NSUserDefaults standardUserDefaults] setObject:notification.alertTitle forKey:@"alertmsg"];
}
NSLog(@"Alert Message: %@", notification.alertTitle);
NSLog(@"Alert Body: %@", notification.alertBody);
}
Wenn die App dann wird keine AppDelegate suspendiert Methode aufgerufen, wenn eine lokale Benachrichtigung angezeigt wird. – Paulw11
@ Paulw11 also gibt es keine Lösung für dieses Problem? –
Gibt es eine Möglichkeit, Daten zu aktualisieren, wenn der Benutzer die App nicht von der Benachrichtigung aus geöffnet hat, sondern vom Symbol? –