Question

Avec iOS 5 et scénarisation, quelle est la meilleure façon de présenter une vue lorsque l'utilisateur entre l'application après avoir reçu un localnotification?

Je l'ai lu en utilisant la NSNotificationCenter est la façon de le faire, mais est-ce aussi ainsi avec scénarisation et enchaînements?

Était-ce utile?

La solution

Ceci est exactement ce que j'implémenté. Dans les didFinishLaunchingWithOptions du AppDelegate: méthode, je l'ai fait ce qui suit:

   UILocalNotification *notification = 
   [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
   [self application:application didReceiveLocalNotification:notification];

Je l'ai fait pour que je puisse garder la logique en un seul endroit. Dans le didreceiveLocalNotification: méthode, je puis utilisé le NSNotificationCenter:

    // Let another view handle the display        
    NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
    [nc postNotificationName:@"SHOW_VERSE" 
                      object:self 
                    userInfo:notification.userInfo];

Le point de vue qui gère l'affichage est la première UIViewController pour la table de montage. Dans cette classe, dans la méthode viewDidLoad:

    [[NSNotificationCenter defaultCenter] addObserver:self  
                  selector:@selector(receivedLocalNotification:) 
                      name:@"SHOW_VERSE" 
                    object:nil];

Cela fonctionne très bien pour moi. Espérons que cela aide.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top