Create an array of minutes and declare your interval variable right under minutes array like so
let pickerData = ["Every minute", "Every 2 minutes", "Every 3 minutes", "Every 4 minutes", "Every 5 minutes", "Every 6 minutes", "Every 7 minutes", "Every 8 minutes", "Every 9 minutes", "Every 10 minutes"]
let minutes[Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var interval: Inte = 0
Change your pickerView didSelectRow function to this
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int) {
interval = minutes[row]
}
now you have your interval as int which is from 1 to 10 depending on which row has been selected.
@IBAction func triggerNotification(){
print("notification will be triggered in five seconds..Hold on tight")
let content = UNMutableNotificationContent()
content.title = "Placeholder"
content.subtitle = "Placeholder"
content.body = "Placeholder"
content.sound = UNNotificationSound.default()
let minute = TimeInterval(interval * 60)
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval:(minute), repeats: true)
let request = UNNotificationRequest(identifier:requestIdentifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request){(error) in
if (error != nil){
print(error?.localizedDescription ?? "User instance is nil")
}
}
}
I created a new minute variable which is a TimeInterval also multiply interval*60. If interval is 2 then it will be 2*60 = 120 and so on.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…