0
我不知道我在做什麼錯。我有以下代碼:本地通知不適用於iOS模擬器
//Create date
let calendar = NSCalendar.currentCalendar()
let now = NSDate()
let dateComponents = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Month, NSCalendarUnit.Year, NSCalendarUnit.Hour, NSCalendarUnit.Minute, NSCalendarUnit.Second], fromDate: now)
dateComponents.minute += 2 //add 2 minutes to current time for debug
let date = calendar.dateFromComponents(dateComponents)
//Create notification
let notification = UILocalNotification()
notification.alertBody = "Your task is now available"
notification.alertAction = "open"
notification.fireDate = date
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["id": NSUUID().UUIDString]
notification.category = "Notification"
UIApplication.sharedApplication().scheduleLocalNotification(notification)
當我把在應用程序中的斷點:在應用程序委託didReceiveLocalNotification,它永遠不會被調用。
當本地通知開啓,關閉應用程序,然後檢查。 – iphonic
你如何打開通知?模擬器的設置應用程序中沒有通知設置。 – u84six