我的问题是这样的:
我已经在iOS应用程序上安排了一些UILocalNotifications,问题是如果我删除应用程序而不删除与通知关联的对象(并因此从scheduledNotifications数组中删除通知),通知仍然会触发.
虽然我没有经历过它们实际射击(它们被设置为在一周的间隔内重复)但我有证据证明这是因为我在应用程序启动时NSLog the scheduledNotifications数组,即使在删除应用程序并重新安装它之后(与数据的实体一起)模型消失了),仍然显示一些预定的通知.
我在Apple的参考库中搜索了UIApplication和UIApplicationDelegate参考,但我发现没有方法可以知道应用程序是否被删除,如果有的话我会写的
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Run Code Online (Sandbox Code Playgroud)
在所述方法中.
那么,有没有办法知道这一点?
提前感谢您,非常感谢您的帮助.
我现在已经实现UILocalNotifications了两个不同的应用程序.一个使用位置服务,这意味着如果它被杀死,它(通常)会重新启动(所以它不是一个大问题).但是,在另一个应用程序中,我UILocalNotification根据时间安排.在这种情况下,我遇到了一个重大问题.
如果我安排通知,那么应用程序会被杀死,推出内存,电话关闭然后再打开,我无法在打开应用程序时"自动"查看旧通知.
这是有效的工作流程(app在后台运行):
下面是它工作流程无法正常工作(应用程序不再在后台运行):
didReceiveLocalNotification调用该方法.用户认为该应用程序不起作用.有什么方法可以知道当应用程序没有在后台运行时它们触及了哪个通知(因此没有运行didReceiveLocalNotification method)?
我有一个UILocalNotification应该每周一次,周一到周五开火,但不是在周末.我认为将通知的repeatInterval属性设置为NSWeekdayCalendarUnit可以实现此目的.可悲的是,我的通知仍在周末开火.谁有人建议为什么?这是我的代码:
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertAction = @"View";
localNotification.alertBody = NSLocalizedString(@"ALERT_MESSAGE", nil);
localNotification.soundName = UILocalNotificationDefaultSoundName;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy HH:mm"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"America/Toronto"]];
// Notification fire times are set by creating a notification whose fire date
// is an arbitrary weekday at the correct time, and having it repeat every weekday
NSDate *fireDate = [dateFormatter dateFromString:@"01-04-2012 11:00"];
localNotification.fireDate = fireDate;
localNotification.repeatInterval = NSWeekdayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
break;
[localNotification release];
Run Code Online (Sandbox Code Playgroud) 我想知道如何处理使用我的应用程序创建的UILocalNotifications,但该应用程序随后被删除.比方说,创建几个通知后,用户决定删除应用程序,但我注意到,即使该应用程序被删除通知住,他们仍然火在正确的时间,但是这并没有任何意义,我因为应用程序不再存在于手机中.
我理解这是可能的,但我想知道当用户决定摆脱我的应用程序时是否有办法删除此类通知?
如果应用程序正在更新,这是否会发生?
谢谢.
任何人都可以告诉我如何让UILocalNotification我的应用程序在后台一段时间.
我在这里发布我的代码.提前致谢.
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate =[startDate addTimeInterval:60];
NSLog(@"%@",localNotif.fireDate);
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
NSString *notifStr=[NSString stringWithFormat:@"Hey looks like you're meeting up with %@, why don't you let your other friends know what fun they're missing out on? Share a photo :)",[itemDict objectForKey:@"fname"]];
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:notifStr ,@"notifKey",nil];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
Run Code Online (Sandbox Code Playgroud) 问题:
- (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
Run Code Online (Sandbox Code Playgroud)
有时用iOS7不会调用.它不会影响我们如何安排通知:
alarm.fireDate = [[NSDate date] dateByAddingTimeInterval:0.1];
[app scheduleLocalNotification:alarm];
Run Code Online (Sandbox Code Playgroud)
要么:
[app presentLocalNotificationNow:alarm];
Run Code Online (Sandbox Code Playgroud)
我的想法:当用户在通知警报动画完成之前滑动时会发生这种情况.如果他在滑动之前等待半秒钟 - 通知被解雇,应用程序按预期进行.问题可能是应用程序在收到通知之前进入前台.
有没有人见过这个?这是一个错误吗?有解决方案吗 谢谢!
我想在UILocalNotification每个星期天晚上8点触发,但是,我每天晚上8点都有一个火灾日期.
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now = [NSDate date];
NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate: now];
[componentsForFireDate setWeekday: 1] ; //for fixing Sunday
[componentsForFireDate setHour: 20] ; //for fixing 8PM hour
[componentsForFireDate setMinute:0] ;
[componentsForFireDate setSecond:0] ;
NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];
UILocalNotification *notification = [[UILocalNotification alloc] init] ;
notification.fireDate = fireDateOfNotification ;
notification.timeZone = [NSTimeZone localTimeZone] ;
notification.alertBody = [NSString stringWithFormat: @"New updates!"] ;
notification.userInfo= [NSDictionary …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何在swift中设置UILocalNotification,但我没有很多运气.我在尝试这个:
var notification = UILocalNotification()
notification.timeZone = NSTimeZone.defaultTimeZone()
var dateTime = NSDate.date()
notification.fireDate(dateTime)
notification.alertBody("Test")
UIApplication.sharedApplication().scheduleLocalNotification(notification)
Run Code Online (Sandbox Code Playgroud)
首先,我不确定这是否是获取当前日期时间的正确方法.在.Net中,我只会做DateTime.Now().
其次,当我尝试这个时,我得到一个错误,上面写着:
'(@lvalue NSDate!) - > $ T3'与'NSDate'不同
不幸的是,我不知道这意味着什么或如何继续.
从iOS9开始,本地通知无法正常工作.有时用户会收到通知,有时他们却没有收到通知.我的通知每天重复.知道可能导致问题的原因吗?我看到一些帖子,iOS9中有一个错误,但我不确定是什么原因.
这是一段代码:
NSDate *alarmDate = [date dateByAddingTimeInterval:DEFAULT_SNOOZE_DURATION * i];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = alarmDate;
localNotif.timeZone = nil;
localNotif.alertBody = alertBody;
localNotif.hasAction = YES;
localNotif.applicationIconBadgeNumber = 1;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.repeatInterval = NSCalendarUnitDay;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif]
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
iOS 11有一项新功能:持久横幅通知.您可以通过设置菜单 - >特定应用设置 - >通知选择此选项.
有没有办法默认为我开发的特定应用程序使用这些持久性横幅?plist文件中的一些配置?
我见过谷歌日历已经取得了类似的成就.
我没有找到任何关于此事的文件.