iOs 8, start playing sound when in the background, alarm clock app <p>I know there are many questions on SOF, but this is the "newest" one. The thing is, I'm trying to create and alarm app, and I know for a fact that there are alarm apps out there that works perfectly ( somehow ), even if the app is not running and is in the background.</p> <p>My question is: how do you start playing sound <strong>after</strong> your app is already in the background ?? </p> <p>UILocalNotification is great, but you'll only get <code>application:(_:didReceiveLocalNotification:)</code> after the user has already clicked on your notification, so playing sound using AVAudioPlayer didn't work, i want to play sound regardless weather the user clicks on it or doesn't. Of course with <code>Required background modes: App plays audio or streams audio/video using AirPlay</code> in <code>info.plist</code> already set. Once the music starts playing, it keeps playing even if i go to the background.</p> <p>I don't want to use UILocalNotificaation sound coz it's limited to 30 secs and only the able to play the sounds that are bundled with the application.</p> <p>Any insights ? thoughts ?? </p> <p>Sample code:</p> <pre><code> var notif = UILocalNotification() notif.fireDate = self.datePicker.date notif.alertBody = "test" UIApplication.sharedApplication().scheduleLocalNotification(notif) </code></pre> <p>the above code gets called when the user selects and alarm and clicks save.</p> <p>and here's what's happening in AppDelegate:</p> <pre><code>func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -&gt; Bool { NSLog("launched") application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil )) AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil) AVAudioSession.sharedInstance().setActive(true, error: nil) self.sound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("sound", ofType: "caf")) self.audioPlayer = AVAudioPlayer(contentsOfURL: sound, error: nil) return true } func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!){ audioPlayer.play() NSLog("received local notif") } </code></pre> <p>You need to hold a strong reference to the <code>AVAudioPlayer</code> btw, so it won't get released, and the <code>audioplayer.play()</code> won't do anything...</p>