我使用两个动作按钮创建一个UILocationNotification,一个呼叫睡眠并立即醒来。因此,一旦用户看到通知,如果他们按下现在唤醒应用程序将启动并执行一些代码由于某种原因,应用程序启动,然后拒绝执行代码。带动作按钮的UILocalNotification按钮
FYI : The code for the UILocalNotification were implement and they are working, the only problem is when I pressed the wake up now button.
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler:() -> Void) {
if notification.category == "options" {
if identifier == "Sleep"{
println("sleep more lazy bumm")
}
else if identifier == "wakeup"{
var object = ViewController()
object.wakeupnow()
}
}
第二种方法我拿了,但它仍然没有工作
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler:() -> Void) {
if notification.category == "options" {
if identifier == "Sleep"{
println("sleep more lazy bumm")
}
else if identifier == "wakeup"{
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("wake"), name: UIApplicationWillEnterForegroundNotification, object: nil)
}
}
fun wake(){
var alertview = UIAlertView()
alert.message = "Good job you are up now, so lets get to work"
alert.addButtonWithTitle("ok")
alert.cancelButtonIndex = 0
alert.show()
}
实际的错误是什么? – ozgur
由于某些原因没有错误代码没有被调用 – Lamar