2016-12-25 1 views
0

Voici mon code de notification locale, je reçois notification tous les jours en utilisant [localNotification setRepeatInterval:NSCalendarUnitDay]; maintenant je veux arrêter ou annuler les notifications après la date et l'heure expire en utilisant la date et l'heure de fin. et où dois-je mettre en œuvre sur ceux-ci, N'importe qui s'il vous plaît expliquer.Advance en remerciements.Définir un rappel en utilisant la notification locale dans iOS Objectif C

NSString *startdate = @"10-12-2016 07:00 am"; 
NSString *enddate = @"14-12-2016 07:00 am"; 
UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
localNotification.fireDate = startdate; 
localNotification.alertBody = [NSString stringWithFormat:@"%@ ",self.nameTextField.text]; 
      localNotification.soundName = @"bell_tree.mp3"; 
      localNotification.alertAction = @"Show me the item"; 
      localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
      localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; 
    [localNotification setRepeatInterval:NSCalendarUnitDay]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

et ceci est mon délégué app codages didReceiveLocalNotification,

- (void)application:(UIApplication *)application didReceiveLocalNotification:(nonnull UILocalNotification *)notification { 
    UIApplicationState state = [application applicationState]; 
    if (state == UIApplicationStateActive) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder" 
                 message:notification.alertBody 
                 delegate:self cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alert show]; 
    } 

    // Request to reload table view data 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self]; 

    // Set icon badge number to zero 
    application.applicationIconBadgeNumber = 0; 

} 

Répondre

0

Vous pouvez annuler cette notification en utilisant le code suivant:

Annuler une notification locale avec cette ligne de code: [[UIApplication sharedApplication] cancelLocalNotification:theNotification]

Vous pouvez le faire dans didReceiveLocalNotification après avoir affiché la notification à l'utilisateur .. ou passer le "notification" o bject à cette classe/méthode si l'utilisateur l'annule.

ou vous pouvez implémenter le bouton "annuler" cliquez sur le bouton d'alerte, et sur ce clic, vous pouvez annuler ce rappel (notification locale).

+0

Comment puis-je vérifier la réception de la date et l'heure de notification est égale à la chaîne de date et heure de fin. alors seulement son droit possible ?, pouvez-vous expliquer s'il vous plaît. – Jaikannan