Dans mon application, je dois déclencher une fausse notification à une date particulière avec l'heure 12h et 18h. J'ai créé et planifié une notification locale dans le fichier de catégorie "UILocalNotification".Comment définir une notification locale pour une date particulière avec l'heure 12h et 18h
UILocalNotification + fichier TZT.h:
#import <UIKit/UIKit.h>
@interface UILocalNotification (TZT)
//Create LocalNotification
+ (void)createLocalNotificaitonForDateForDate:(NSDate *)date
withBody:(NSString *)body
withUserInfo:(NSDictionary *)userInfo
withTimeInterValInfo:(NSArray *)timeInterValInfo
withBtnTitle:(NSString *)btnTitle;
//Cancel All Local notificaitons
+ (void)cancelAllLocalNotifications;
@end
UILocalNotification + fichier TZT.m:
#import "UILocalNotification+TZT.h"
@implementation UILocalNotification (TZT)
+ (void)createLocalNotificaitonForDateForDate:(NSDate *)date
withBody:(NSString *)body
withUserInfo:(NSDictionary *)userInfo
withTimeInterValInfo:(NSArray *)timeInterValInfo
withBtnTitle:(NSString *)btnTitle
{
UILocalNotification * localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = body;
localNotification.alertAction = btnTitle;
localNotification.userInfo = userInfo;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = 0;
localNotification.soundName = UILocalNotificationDefaultSoundName;
for (int i = 0; i < [timeInterValInfo count]; i++) {
NSLog(@"timeInterValInfo = %ld",(long)[[timeInterValInfo objectAtIndex:i] integerValue]);
date = [date dateByAddingTimeInterval:(long)[[timeInterValInfo objectAtIndex:i] integerValue]];
localNotification.fireDate = date;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
//localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
}
+ (void)cancelAllLocalNotifications
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
En classe Appdelegate de didFinishLaunchingWithOptions méthode, je dois créer et prévu notification locale en appelant la catégorie de catégorie.
#pragma mark - UILocalNotification
- (void)setUpLocalNotification
{
NSDate * firedDate = [TZTNSDateHandlings getDateMonthYearHyPhenFormat:@"31-07-2017 00:00:00" withHourMinSec:YES];
NSArray * timeInterValArray = @[@"43200",@"64800"];
NSDictionary * userInfoDic = @{@"receiverType":@"localNotification"
};
[UILocalNotification createLocalNotificaitonForDateForDate:firedDate
withBody:@"Sample local notification"
withUserInfo:userInfoDic
withTimeInterValInfo:timeInterValArray
withBtnTitle:NSLocalizedString(@"localPush.btnTitle", nil)];
}
Par exemple, le 31 Juillet 24:00 et je veux montrer 18 heures la notification locale, donc je mets la date statique comme une chaîne puis convertir en NSDate, après avoir créé NSArray contient des valeurs NSTimeInterVal.
12PM en 43200 secondes et également 6PM en 64800 secondes programmées avec ces valeurs d'intervalle de temps.
Mais je ne peux pas voir le simulateur de notification local ainsi que le périphérique aussi.
cible de déploiement d'application commence à partir de iOS 9.0
donc je dois gérer une notification locale pour iOS 9.0 et iOS ci-dessous et 10. et au-dessus des cas?
Je dois suivre également les instructions iOS-10?
Veuillez me le suggérer.
Merci pour votre réponse et d'accord laissez-moi suivre votre chemin. est le UILocalNotification peut déclencher tous les appareils même mon déploiement à partir de iOS 9.0? Sinon, j'ai besoin d'intégrer la notification locale pour iOS 10.0 de manière séparée? – Ram
La notification locale a été planifiée comme ceci, {date du tir = samedi 29 juillet 2017 à 18:00:00 heure normale de l'Inde, fuseau horaire = Asie/Kolkata (GMT + 5: 30) offset 19800 , intervalle de répétition = 0, nombre de répétition = UILocalNotificationInfiniteRepeatCount, date de déclenchement suivante = samedi, 29 juillet 2017 à 18:00 heure normale de l'Inde, informations utilisateur = (null)} Mais je ne peux pas voir l'alerte de notification locale. J'ai testé sur simulateur. nous pouvons afficher une notification locale uniquement sur l'appareil? –
Ram
La notification locale fonctionne dans le simulateur et le périphérique.Vous devriez le vérifier dans la méthode didReceiveLocalNotification de AppDelegate. –