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

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift