Software for Good Logo
Insights / October 28, 2013

Writing a Mac App

By Joe Pintozzi

Last Thursday, I set a daunting challenge for myself: Write my first app for OS X Mavericks by Monday morning at 12am. I was confident because OS X apps are written in Objective-C, which I’ve been using for years to write iOS apps. The real challenge would be working with OS X’s UI paradigms and getting used to a different application lifecycle.

Update: Orangered Messages has been approved!

I <3 Reddit

Reddit has played a huge part in my career in all sorts of ways. My first iOS app was a Reddit app. I found a job on /r/forhire (Hi Core-Apps!) after my first serious employer ran out of money. I’m even wearing an un-purchasable Reddit shirt today!

It only made sense that my first OS X app fall in line and be a Reddit app as well.

Unsatisfied with the Competition

There’s an existing OS X app called “Reddit Notifier” that checks your Reddit inbox and notifies you when you have new messages. It’s a decent app, but it’s lacking in several areas. My three main problems:

1. It takes your username and password directly into text boxes, and I’m not exactly fond of turning over my credentials to a 3rd party app.

2. It doesn’t show how many messages are unread, only some or none.

3. It doesn’t tell me what my messages are. All I know is that there is one. Somewhere. From someone. Maybe.

Clearly it was time for an update, so I set off to build something better.

More Secure Authentication

Step 1 was to dig into Reddit’s API to figure out if I could use a more secure form of authentication. Turns out I was in luck, and their API supports OAuth! I’m generally a fan of writing a custom API client, so I built one on top of the amazing AFNetworking.

I hadn’t used it since they published 2.0, so I had to go over their migration guide to get an understanding of the breaking changes. After access_tokens are received, user authentication is done via bearer tokens being passed in the Authorization header.

Checking for Messages

Once I obtained an authenticated user, it was easy enough to hit /message/inbox and count the number of items returned with new set to 1. iOS has no UI element like NSMenuItem, though it was pretty straightforward to get a nice menu working with an unread message count.

Killing two birds with one stone, I also decided to present the most recent 20 messages. When clicked on, it will bring you directly to the context on where it was posted.

Digging Deep and Going Beyond

At this point my app was good, but it wasn’t GREAT. After using Mavericks for a few days, I yearned for the ability to quick reply to Reddit messages just like I do with iMessage and Airmail. I checked the OS X documentation for NSUserNotification, but I couldn’t find anything relating to the ability to reply to a notification.

I searched Google and StackOverflow, but I couldn’t find anything! Where was this elusive reply ability?! Finally, I dug into the OS X 10.9 API Diffs and found it near the bottom of the page for Foundation updates.

I went back to check the NSUserNotificationActivationType, and sure enough the reply one is missing.

Oh well. It didn’t matter because I had found it! I quickly coded up my alerts to use the new notification methods and had a working QuickReply!

What I Learned

I learned a lot, cramming the development of this app into one weekend. I learned that you can’t always trust documentation, even when it comes from a giant corporation like Apple. I was reminded that not all OAuth2.0 providers follow authorization methods to the exact spec, that AFNetworking is awesome, and that even when something out there exists, that doesn’t always mean that you can’t make something else that is better. It was a fun and exciting project, and I hope it gets approved sometime within the next few days!