- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么按下按钮后不显示通知?
如果 fireDate 是 NSDate(timeIntervalSinceNow: 10)
它会工作正常
如何从数组中获取通知?
@IBAction func buttonPressed(sender: AnyObject) {
var stringDate = dateFormatter.stringFromDate(timePicker.date)
alarmArray.append(stringDate)
let fixedAlarmArray = alarmArray
NSUserDefaults.standardUserDefaults().setObject(fixedAlarmArray, forKey: "alarmArray")
NSUserDefaults.standardUserDefaults().synchronize()
//Local Notification
var localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Go to app"
localNotification.alertBody = "Its Time!"
localNotification.fireDate = timePicker.date
localNotification.timeZone = NSTimeZone.defaultTimeZone()
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
self.view.endEditing(true)
}
最佳答案
The date specified in fireDate is interpreted according to the value of this property. If you specify nil (the default), the fire date is interpreted as an absolute GMT time, which is suitable for cases such as countdown timers. If you assign a valid NSTimeZone object to this property, the fire date is interpreted as a wall-clock time that is automatically adjusted when there are changes in time zones; an example suitable for this case is an an alarm clock.
localNotification.fireDate = timePicker.date
localNotification.timeZone = NSTimeZone.defaultTimeZone()
// the problem is here, you are setting the timezone after inputing your date
你应该使用 localtimeZone 并在设置 fireDate 之前设置它
localNotification.timeZone = NSTimeZone.localTimeZone()
localNotification.fireDate = timePicker.date
注意:
In iOS 8 and later, apps that use either local or remote notifications must register the types of notifications they intend to deliver. The system then gives the user the ability to limit the types of notifications your app displays. The system does not badge icons, display alert messages, or play alert sounds if any of these notification types are not enabled for your app, even if they are specified in the notification payload.
这样做:
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, categories: nil))
创建一个扩展,将选择的时间与 0 秒结合起来,如下所示:
extension NSDate {
var day: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitDay, fromDate: self).day }
var month: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitMonth, fromDate: self).month }
var year: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitYear, fromDate: self).year }
var minute: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitMinute, fromDate: self).minute }
var hour: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitHour, fromDate: self).hour }
var fireDate: NSDate {
return NSCalendar.currentCalendar().dateWithEra(1, year: year, month: month, day: day, hour: hour, minute: minute, second: 0, nanosecond: 0)!
}
}
然后按如下方式使用它:
localNotification.fireDate = timePicker.date.fireDate
关于swift - 未收到来自 LocalNotification.fireDate 的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27407245/
我想使用 UILocalNotifications 作为应用程序的后台计时器。用户可以像远程通知一样禁用此通知吗?如果用户禁用了应用程序的远程通知,本地通知是否也会被禁用? 最佳答案 我最终编写了一个
是否有任何原因导致我的本地通知显示在通知中心但未弹出?有什么设置可以让它弹出吗? 最佳答案 本地通知将与所有其他通知一样显示,作为开发者,您对此无能为力。 通知的默认设置是将其显示为屏幕顶部的横幅,而
我创建了一个应用程序,该应用程序每天通知用户一次。 为此我使用了下面的代码 func application(application: UIApplication, didRegisterUserN
我正在安排计时器并向用户发送有关某些数据的一些本地通知,例如 - 如果附近有商店。 func configureNotification(shop: Shop) { let notificat
这是我的 didEnterRegion 函数代码。问题是通知在进入和退出时触发。如何仅在用户输入位置时触发通知? func locationManager(manager: CLLocationMan
我有一个 iOS 应用程序,它每 4 小时左右触发一次本地通知。这似乎按预期成功运行。不过,我担心的是如果用户重新启动设备该怎么办。任何现有的本地通知是否仍然存在?以下是我如何触发本地通知:
我正在通过单击按钮安排基于位置的 UILocalNotification。但是当我尝试通过再次单击同一个按钮来取消 localNotification 时,它不会取消通知。我正在使用 UIApplic
我已使用 UILocalNotification() 创建了通知,并且我正在尝试清除收到的通知,而不删除计划的其余通知。 这是我尝试使用的代码: UIApplication.sharedApplica
我正在开发一个应用程序,该应用程序应该在 21 天内每天发送本地通知,但随后它应该停止发送一周。我知道我可以设置 fireDate 并且可以设置重复间隔,但是有什么方法可以设置像最后一个 fireDa
我有一个日期数组 NSArray *datesArray=[NSArray arrayWithObjects: @"2014-09-14 00:00:00",@"2014-08-21 07:12:36
我在我的应用程序中设置了一个警报,它会产生一个显示为横幅的本地通知。我怎样才能让它显示为必须单击以关闭它或理想情况下直接打开应用程序的警报? 这就是我目前设置通知的方式 window.plugin.n
我在我的 Ionic 应用程序中使用 ngCordova LocalNotification 插件,我试图让它以随机时间跨度重复。 例如,用户将触发通知在 1 分钟内启动,然后我需要在另外 2 分钟内
如果我从后台强行关闭我的应用程序。然后本地通知来了。如果点击本地通知,当应用程序在前台运行时我的方法不会被调用。我在 iOS 中较新。请帮忙。 -(void)application:(UIApplic
我正在开发一款应用,该应用会向用户发送本地通知,提醒他们某双鞋即将上市。 我认为应该在前一天晚上 8:00 发送通知。 这是我的日期字符串(称为 releaseDate): 2014-04-10 00
我正在使用经 Teleriks 验证的 LocalNotification 插件来将本地通知发送到运行我的应用程序的设备。我允许他们选择自己喜欢的通知间隔(1-2-3 或 4 小时),但我希望这些通知
我有一个场景,我安排了两个单独的 LocalNotifications。一个设置为在午夜十点开火,另一个每小时开火一次。我可以通过在安排通知时设置通知的 UserInfo 来区分它们。 对于每小时通知
我正在学习 PhoneGap,我尝试使用 Notification Local Plugin ,但对我不起作用。 我正在尝试构建我的应用程序,但它在 XML AndroidManifest.xml 中
我有这段代码每天早上 7 点运行通知,它获取当前日期,然后在到达设定时间时运行通知,我的问题是如果时间已经超过设定的运行时间,那么它每天都会在用户当前时间运行,而不是我早上 7 点的时间,这是我的代码
我在我的应用程序中使用 LocalNotification。它工作正常,但一旦设置了 ApplicationIconBadgeNumber,就无法将其从应用程序中删除。如何删除它? 最佳答案 您需要设
基于此教程Simple iOS Alarm Clock Tutorial,我实现了AlarmClock App。 该通知运行良好,但没有声音。 为了解决这个问题,我尝试过: Fix-1,并且未选中/选
我是一名优秀的程序员,十分优秀!