Luiz Luiz - 1 year ago 70
iOS Question

Play a sound before opening an URL


I'm having a problem when calling an action before opening App Store to rate my game. The sound won't be played. I've seen a game in which it worked. Am I doing anything wrong?


func rateGame(){

let appIDString = "375380948"
let reviewsURLString = "itms-apps://\(appIDString)"
let reviewsURL = NSURL(string: reviewsURLString)


func clickSoundFX(){
self.runAction(SKAction.playSoundFileNamed("buttonClick.mp3", waitForCompletion: false))

Thanks in advance,


Answer Source

When you launch clickSoundFX() and after you call:


your game start to make an action to play a simple sound but right after all the app going in applicationDidEnterBackground due to open an external url: in this exact moment all your game going in paused mode so you can't do any action.

A safe way to do your code is to make a pause sequence after your sound and check the completion like this:

let wait = SKAction.SKAction.waitForDuration(1.0)
let sound = SKAction.playSoundFileNamed("buttonClick.mp3")
let seq = SKAction.sequence([sound,wait])
self.runAction(seq,completion: {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download