Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 本地警报未被称为Swift_Ios_Swift_Uilocalnotification - Fatal编程技术网

Ios 本地警报未被称为Swift

Ios 本地警报未被称为Swift,ios,swift,uilocalnotification,Ios,Swift,Uilocalnotification,我正在尝试创建一个闹钟,当预定义的时间到来时发送推送通知。我创建了一个从UILocalNotification继承的自定义警报类,但警报不会显示。 代码: 应用程序不会崩溃或打印任何错误,但通知不会在应该的时候弹出。println()打印正确的日期和时间 您没有请求发送通知的权限。很抱歉没有澄清这一点。我在应用程序委托(let notificationType=UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUser

我正在尝试创建一个闹钟,当预定义的时间到来时发送推送通知。我创建了一个从UILocalNotification继承的自定义警报类,但警报不会显示。 代码:


应用程序不会崩溃或打印任何错误,但通知不会在应该的时候弹出。println()打印正确的日期和时间

您没有请求发送通知的权限。很抱歉没有澄清这一点。我在应用程序委托(let notificationType=UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound let settings=UIUserNotificationSettings(类型:notificationType,类别:nil)应用程序中请求权限。registerUserNotificationSettings(设置)
class shabbosClockViewController: UIViewController
{
    //variables****************************************************
    var localNotification: UILocalNotification = UILocalNotification()
    var alarmArray: [alarmObject] = defaults.arrayForKey("alarmArray") as [alarmObject]


    override func viewDidLoad()
    {
        super.viewDidLoad()

        var testAlarm = alarmObject(title: "test title", hour: 15, minutes: 36, day: 3)
        UIApplication.sharedApplication().scheduleLocalNotification(testAlarm)
    }


}

class alarmObject: UILocalNotification
{
    var dateComponents: NSDateComponents = NSDateComponents()

    init(title: String, hour: Int, minutes: Int, day: Int)
    {
        super.init()
        var calander: NSCalendar = NSCalendar.currentCalendar()
        calander.locale = NSLocale.currentLocale()
        var dateFormatter = NSDateFormatter()
        dateFormatter.timeStyle = .ShortStyle
        dateFormatter.timeZone = NSTimeZone.localTimeZone()

        dateComponents.hour = hour
        dateComponents.minute = minutes
        dateComponents.weekday = day
        dateComponents.weekOfMonth = calander.weekOfMonthInDate(NSDate())
        dateComponents.month = calander.monthsInDate(NSDate())
        dateComponents.year = calander.yearsInDate(NSDate())
        dateComponents.timeZone = NSTimeZone.localTimeZone()


        self.fireDate = calander.dateFromComponents(dateComponents)!
        self.alertBody = title

        println("\(self.fireDate) \n\(dateFormatter.stringFromDate(self.fireDate!))\n\(dateComponents.weekday) \n\(dateComponents.weekOfMonth)")
    }

    required init(coder aDecoder: NSCoder)
    {
        fatalError("init(coder:) has not been implemented")
    }

}