我使用兩個動作按鈕創建一個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