gpt4 book ai didi

ios - 本地通知不起作用(快速)

转载 作者:行者123 更新时间:2023-11-28 07:02:32 26 4
gpt4 key购买 nike

我希望触发本地通知。我尝试创建它并且我成功了,没有错误但是当我在模拟器中运行应用程序时本地通知不执行

app delegate中的代码

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: nil))

// play default sound
return true
}

View Controller

class TechByteSchedulingViewController:UIViewController {
@IBOutlet weak var datePicker: UIDatePicker!

@IBAction func DateChosen(sender: UIButton) {
func sendNotification(sender: UIButton) {
var localNotification = UILocalNotification()
localNotification.fireDate = datePicker.date
localNotification.repeatInterval = .CalendarUnitDay
localNotification.alertBody = "check out your daily byte"
localNotification.alertAction = "Open"
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
localNotification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
application.applicationIconBadgeNumber = 0

}
self.navigationController?.popToRootViewControllerAnimated(true)
}

}
override func viewDidDisappear(animated: Bool) {


}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

最佳答案

根据我所见,您在 ButtonAction 函数内部实现了一些错误的函数...您应该在 ButtonAction 之外实现 sendNotfication 函数,然后在内部调用它ButtonAction

class TechByteSchedulingViewController:UIViewController  {

@IBOutlet weak var datePicker: UIDatePicker!

@IBAction func DateChosen(sender: UIButton) {
self.sendNotification()
}

func sendNotification() {
var localNotification = UILocalNotification()
localNotification.fireDate = datePicker.date
localNotification.repeatInterval = .CalendarUnitDay
localNotification.alertBody = "check out your daily byte"
localNotification.alertAction = "Open"
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
localNotification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
application.applicationIconBadgeNumber = 0
self.navigationController?.popToRootViewControllerAnimated(true)
}

}

关于ios - 本地通知不起作用(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31704099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com