Page 765 - I believe I must have missed something here as I have added the sound resource folder/file needed and I see the “FRIST TIME!” print statement come out on the debug, but no sound. I have tried on simulators as well as a spare iphone 6 I have been using out in the wild to test locations operability.
Attached in is the project file…any help would be appreciated.
How did you add the sound resource folder to the project?
I could not see the sound file at all at first but finally found it under the Asset catalog. Any file you add to the asset catalog would generally be treated as an image. So, I don’t believe that Xcode “sees” the file in the same way.
Plus, if you check the code to load the sound effect file, you’ll notice that the code goes through the main bundle to get the URL for the sound file. Putting the sound file inside the Asset Catalog would change the URL for the sound file and so it would not be where we expect it to be as per the code for loading the sound file
You can check for this quite easily by setting a breakpoint within the loadSoundEffect method and checking to see what happens when the code tries to load the sound file - it will generally just do the first if condition and exit since it can’t find a valid URL for that file.
Of course, it might be a good idea to add an else part to that if condition to notify the user of this situation … Will add that to the next version of the book
Yes, I think I am confused about where to add the sound file. I first added it to the project without success, Then added to the assets without success.
It says Add the Sound folder from the app’s Resources to the project. I figured it belonged in the overall project…I will look at the suggested debugging you provided in your post. Thank you.
You can simply add the files to the top-level of the project structure in Xcode In fact, adding it anywhere in the project, as long as it is not under the Asset Catalog should generally work.
The debugging steps were just to identify what was going wrong. So, simply delete the sounds folder you have added to the Asset Catalog, re-add to the project at the top level (or under the MyLocations folder) and then try running the app again.
You did everything right … except for one thing When you added the Sound folder, you probably had the Create folder references radiobox enabled under the Added folders setting. You need to have Create groups enabled instead.
This is a subtle change but it does make a difference here. If you have Create folder references enabled, your folders will appear in blue in Xcode and they actually appear as a sub-folder under the iOS file structure. That is why your code does not work - since the sound file is not in the main bundle but in a sub-folder under the main bundle. So if you remove the sound folder yet again and add it back with the right setting, it should work.