Skip to content

Instantly share code, notes, and snippets.

View alansvits's full-sized avatar
🧭
seeker

Stas alansvits

🧭
seeker
View GitHub Profile
@alansvits
alansvits / Saving some data from applicationDidEnterBackground method.txt
Last active March 3, 2018 17:25
Saving some data from applicationDidEnterBackground method
Put the code in the class that actually has the data. Have the class register for the UIApplicationDidEnterBackgroundNotification notification.
// Put this in the `init` method
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgrounding) name:UIApplicationDidEnterBackgroundNotification object:nil];
// The method that gets called
- (void)backgrounding {
// save the data
}
import AVFoundation
var audioPlayer: AVAudioPlayer!
let soundURL = Bundle.main.url(forResource: "soundName", withExtension: "soundFormat")
do {
audioPlayer = try AVAudioPlayer(contentsOf: soundURL!)
} catch {
print(error)