Tip

Removing Articles from an NSString

Not much to say about this one. I put this together while trying to ignore the basic articles in front of a song name in my music app. Takes a given NSString and returns a new one sans the article:

You can call it as follows:

Tip

How to Push a New UIViewController on Device Orientation Change

IMG_8918

At this point I’m sure everyone has seen the iOS Music app’s album view—where you tilt your phone horizontally and the screen suddenly displays all of the album art on your phone.

While viewing a collage of cover art always felt a little useless to me, I always thought the effect was pretty cool and wanted to do something similar in the music app I’m currently working on. As such, I took to google and spent longer than I’d care to admit trying to figure this one out. In the process I got an astonishing variety of errors, but once I finally figured it out the process was actually really simple and not a lot of code at all.

Basically, the code is broken into two methods. The first goes in the vertical ViewController:

and the second in the horizontal:

Here, the first method (the one in the vertical ViewController) is performing a manual segue based on the device’s orientation state. The second method is basically doing the reverse. It dismisses said ViewController, but does so after the UI has had a moment to reset itself to vertical (you get some pretty gnarly errors if you try and segue back before allowing the UI to finish changing orientation). The end result is an effect very similar to the one in the iOS music app. There are a couple of more things to note however:

Tip

How to Stop a UISlider from Stuttering in an AVPlayer

After hours of Googling and trying absurdly complex solutions from old documentation to stop the scrubbing bar on my music player from jumping when I dragged it I finally found the solution and it’s annoyingly simple. Just add a call to not update the slider when it’s being touched inside of your update method like so:

Hopefully this tip will save someone else from having to go through the multiple refactoring attempts I did!

Tip

Setting up Spotify to Work with the Built-in Apple Headphones Remote

spotify-generic I’ve always found it extremely annoying that the remote on the Apple headphones not only didn’t work with Spotify but also opened up iTunes every time I accidentally tried to use it to pause whatever song I was listening to. After Googling around for a couple of days with no luck, I managed to piece together a few separate posts on message boards that combined let me stop iTunes from opening anytime I tried to play/pause on the headphone remote as well as control Spotify. I’ve included all of the steps below, as well as download links to all of the files you’ll need to set it all up.

Step I – Stopping iTunes from Opening on Play/Pause
This was the easiest part to figure out and was on pretty much every site I came across. It boiled down to three main steps:

  1. Disable SIP:
    1. Restart your Mac.
    2. Hold down Command+R before OS X starts up. Release the keys once you see an Apple icon and progress bar.
    3. From the Utilities menu, select Terminal.
    4. In the command prompt, type: csrutil disable
  2. Download and run this DMG file.
  3. Re-Enable SIP:
    1. Restart your Mac.