I followed this post: SKAction playSoundFileNamed stops background music and it worked in that background music was no longer paused when SK sound actions were run.
Unfortunately thought music is still stopped when the app is launched initially. I also tried code from another post (background device music gets stopped as app starts ios) but that either didn't work.
How do I stop my app from pausing music upon the initial launch? Maybe I am not placing my code in the right location?
Code:
import UIKit
import AVFoundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
} catch _ {
}
return true
}
}
Thanks!
EDIT 1 (for use from comments)
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
} catch _ {
}
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch _ {
}
}