Alarm in iOS Swift



In iOS, we don't have Alarm manager.But we will use local notification as an alarm manager.
We will play the sound as like alarm.
Code:
        let notification = UILocalNotification()
        notification.soundName = "alarm.mp3" // add soundfile to your project and put the name here
        notification.timeZone = NSTimeZone.local
        notification.userInfo = data as? [String: AnyObject] //set the notification data here and get and process in the receiving end
        notification.fireDate = NsDate()  // set the alarm time
        UIApplication.shared.scheduleLocalNotification(notification)   // fire the notification

Comments

Popular posts from this blog

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift

Parse the value from string value iOS swift