import UIKit
class MyView: UIViewController {
@IBOutlet var mySwitch: UISwitch!
@IBOutlet var myDatePicker: UIDatePicker!
func datePicker() { myDatePicker.datePickerMode = UIDatePickerMode.Date }
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
datePicker()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func switchPressed(sender: AnyObject) {
if mySwitch.on{
var localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Open App"
localNotification.alertBody = "Here is your notification at 7:00 AM"
localNotification.fireDate = myDatePicker.date
localNotification.repeatInterval = NSCalendarUnit.CalendarUnitDay
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
} else {
var localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Open App"
localNotification.alertBody = "This notification should not appear"
localNotification.fireDate = NSDate(timeIntervalSinceNow: 999999999999)
IApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
}
}
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
create a new Swift Source file at your project to put your extensions
If you already have the
UIDatePicker
, all you need to do is grab thedate
property from it and use it to set thefireDate
.