AFNetworking: Downloading Files with Progress

I was looking for this the other day, and while there are a ton of solutions out there, I felt that all of them were just a tad more complicated than they needed to be to achieve the desired result. Basically, I’m working on an app that needs to download videos and show what percentage of the files have been downloaded in a UITableView. Standard stuff, but for some reason it’s not already built in to AFNetworking. After tinkering around with a few different solutions online, I ended up coming up with my own (shown below). I ended up creating a class called MFVideoDownloader and adding the the following class method to the .m:

While the snippet contains more detailed comments, I’ll just go through what I did really quickly.

    1. First I created the session manager to handle the actual download task that comes about later in the method.
    2. Then I converted the given NSString into an NSURL so it can be used later (I’m working with a REST API that gives me back the URLs I need as strings so it made more sense to convert it here rather than have to convert every place I call the method in app).

Push Notifications, UIUserNotificationSettings, iOS 7, and UIKit

Earlier today, while trying to set my app up to register for notifications in iOS 7 and iOS 8, I came across this exceptionally annoying bug that took me the better part of my work day to iron out. What should have been a simple process ended up keeping me bogged down pouring over the same 11 lines of code for the better part of 6 hours and so in the interest of helping out anyone else that runs across the issue I figured I’d post my solution here.

First the code snippet:

It’s a super common chunk of code that’s all over the internet from personal blogs to stackoverflow that simple allows an app to register for notifications in both iOS 7 and iOS 8. In an ideal world, the process should have been simple, just insert the code snippet, hit run, and then watch everything fall into place: but for some reason as long as the following line was present my app would crash in iOS 7 repeatedly: [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil];  with the following error: dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings .


Inverting a UIColor

More safekeeping than anything else (and because I didn’t see it online anywhere):

Super simple method that’s surprisingly useful if you have something like different themes in an app.


Triangular Imageviews

Certainly not the most climactic way to break my year long posting drought, but I’ve been working on an in house app for my devshop that requires a bunch of triangular UIImageviews and I thought I’d share a quick snippet:

The code itself is pretty simple but just a couple of quick notes on the values used:

  • The 44 value in step 1 is the height of the original view, while 60 is the width (and 30 is half that). I tried using more dynamic values (setting 44 to imageview.frame.size.height etc.) but for some reason when using dynamic values in UITableViewCells I’d get some sizing issues and so I opted to hard code the values in. (I’m assuming because it’s still doing some layout calls.)
  • This code actually isn’t limited to just triangles. By modifying the path in step 1 you can make the ImageView any shape at all, it’s just a matter of playing around with the coordinates until you get something you like.
Project Update

Building a Better Music App : Progress Report 1


After finally getting myself organized two days ago, I’ve finally managed to put something together that actually feels like a somewhat legitimate player. It was a fair amount of hours to get it to the point it is now, but a couple of awesome Cocoapods (thank you BlurryModalSegue and SWRevealViewController!) really sped things up. Furthermore, using MPMediaController is a godsend compared to AVPlayer and I haven’t hit any of the limitations I was worried about running into yet.

As a whole, everything is simpler. Getting organized helped immensely. My code is shorter, easier to read, and more compartmentalized. I’ve been making an effort to comment up my code as I write it as well as taking advantage of pragma marks to be sure I don’t forget where I should insert code snippets I haven’t gotten around to writing yet:

Screen Shot 2014-06-27 at 10.33.00 AM

I’ll be doing a post sometime over the weekend comparing both code bases side by side, but as I haven’t gotten around to doing that yet, I’ve decided to upload a quick video (45 seconds) of my player in action.

Project Update

Building a Better Music App: Getting Organized

IMG_5910 After a long weekend of lots of ugly refactoring moving from AVPlayer to AVAudioPlayer and then back again (more than once because I couldn’t make up my mind) I decided that it would probably benefit me to get just a little more organized in my pursuit of putting together my music app. On that end, spent a few hours the other night putting my ideas on paper and then fleshing them out in a much more thought out approach. On that end, the first thing I start with as clearly defining all of the functionality I’d like my player to have by the time I graduate from Flatiron:

Overall Desired Functionality

  • Play local music
  • Play music on iTunes Match
  • Play songs from Spotify
  • Play playlists from Pandora
  • Play Soundcloud Streams
  • Scrobble to Last.fm
  • Enable favoriting of songs, playlists, and artists
  • Global search across services
  • Specific search narrowed down by service
  • Location based playlists

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!

Project Update

Building a Better Music App: Part 1


In a recent lab at the Flatiron School, we were asked to make a a basic jukebox app. To be honest, it wasn’t anything super impressive. The app simply played a few built in mp3 files that we imported into our Xcode project. Super basic. But it got me curious as to what I could do almost three weeks in at Flatiron. After quick Google search, I came across this incredible iOS Music app concept by Brye Kobayashi. I love the overall design, and the new functionalities he mentioned look super useful. After emailing Brye to get his permission yesterday, I decided to start on trying to make this prototype a reality.


While I’m still a (far) ways off from my final goal, I’ve already managed to put together two basic prototypes that display and play all of the local music on my iPhone. The first draft (pictured right) I managed to do in a few hours last night. And while it’s definitely not the most visually appealing music app out there (not by a long shot), it was a great introduction to the MediaPlayer and AVFoundation frameworks–both of which I’ve found surprisingly intuitive–as well as extra practice in TableViews. Unfortunately the app always started playing on startup, and scrubbing bar at the top wasn’t working and no matter what example I pulled from I couldn’t get it to work. it seems like because the AVFramework is so massive everyone has a totally different answer.