Introducing Urban Push

Urban Push is a WordPress plugin that utilizes the Urban Airship API to send a push directly from the WordPress “new post” page. You MUST have an account with Urban Airship to use this plugin. You can send a single push to up to 4 Urban Airship applications.

Installation

1. Grab it from the official WordPress plugin directory.
2. Unzip and upload to your plugins directory
3. Configure via the settings page
3a. Set your Urban Airship application key and master secret as well as a safety password to avoid accidental pushes.
4. Push away.

Notes

After a push attempt, you will see one new custom field entry for each configured Urban Airship application. It will say push sent for followed by the name you chose for your Urban Airship application. The value of the custom field will contain the response returned from Urban Airship. For a successful push, the response is usually “(null).”

More features are coming like:

  • The ability to set your aps options (badge, sound, etc..)
  • The ability to choose which app to send a push to (or all).




Parsing JSON with iOS 5

iOS 5 has a great built in class for parsing JSON called NSJSONSerialization, and with minimum coding you can parse an entire JSON script. Here is a very basic method with no error handling.

As you can see, the bare bones implementation is very small and easy to use. The first line grabs your JSON url and converts it to NSData, the second line converts your JSON to Foundation objects. After you have objects, you can simply iterate through them. But you would never want to implement this without some error checking, so your actual implementation would be something more like this.

Hope this helps someone, have fun.

My Thoughts about the Trayvon Martin Killing

It may seem like a weird departure from my normal writing (if you can call anything I do here normal). I’ve had a long and drawn out debate with friends on Facebook who want to insist that the whole world is wrong when it comes to the details about Trayvon’s death. Specifically, they point to this absolutely ridiculous piece of shit posing as a factually based article by Kyle Rogers.

I would like to discuss this article and explain why its content is stunningly absurd. Let’s start with this:

Literally thousands of articles contain at least one false statement in the first couple of lines. They usually read “George Zimmerman, a white man,” or “shot by a white man.” Zimmerman is described by family as a multiracial Hispanic. His appearance is clearly that of a Latino/Mestizo individual. However, the media wants him to be white because that better fits the political narrative they are trying to artificially create.

Okay so when I saw this line, a red flag went up. This guy sounds like HE is the one trying to politicize the issue by claiming that the media is trying to start a race war in America. Sure enough, I looked up the author and he is a “Conservative activist in South Carolina. He co-organized the 2006 Greenville, SC rally against the Lindsey Graham/Ted Kennedy sponsored amnesty bill. The event helped launch the SC Tea Party movement.”

So right off the bat, we have a tea-party conservative writing about the left-wing media in this country trying to “artificially create a narrative.” At this point, the writer lost all credibility with me because he is obviously a conservative with an axe to grind with the evil liberal media. Sounds all too familiar.

While I would normally just dismiss everything he has to say, I feel that he made an extremely poor argument, which warrants a response. So let’s continue.

By the way, Zimmerman is half white. Source. So why did the evil liberal media say he was white? Maybe because that’s what the police report said. So much for false narratives. (Thanks to commenter Marsha Miller for that info).

The author (and I use that word generously) makes these other points:

1. The witness reports that George Zimmerman was on the ground and Trayvon is on top of him punching him.
2. A witness says that George Zimmerman was screaming and yelling for help.
3. Police arrive and find Zimmerman bleeding on his face and the back of his head. He also has had grass stains on his back.
4. All this confirms the story told by Zimmerman and the witness.
5. Police play the 911 tape for Trayvon Martin’s father, who tells police that the voice screaming is not the voice of his son.

I’m going to save point #1 for last, because that’s my favorite and I actually hope it’s true because that would mean that Trayvon got to tune up Zimmerman before he was killed. So let’s just get #2 and #5 right out of the way. Trayvon’s father is POSITIVE that the voice crying for help is his son’s. You can hear it right from the horse’s mouth.

Let’s go to #3 “Police arrive and find Zimmerman bleeding on his face and the back of his head. He also has had grass stains on his back.” Okay, there was a scuffle/fight. That doesn’t surprise me but it also doesn’t prove Zimmerman’s story. So let’s move on to #4 “All this confirms the story told by Zimmerman and the witness.”

Wow, that’s some real bang up journalism there. It sounds to me like the only one trying to build a narrative so far is Kyle Rogers with his totally biased vomit-filled article.

So what about #1? Okay, if you’ve bothered to listen to the 911 call, there’s a part where you can actually hear George Zimmerman pursuing Martin due to his loud mouth breathing, which is probably what made the 911 operator ask if Zimmerman was following Martin. But then there are two important words that Zimmerman says on the tape that I haven’t heard anyone talk about. Zimmerman says “he ran,” obviously referring to Martin’s attempt to flee. Sound like Martin is the aggressor to you? Hmm, me neither. But let’s continue.

So let’s say that after chasing Martin (yes chasing–Martin ran, remember?) that he caught up with him or found him hiding or whatever the case may be, they got into a scuffle. Now let’s say for argument’s sake that Zimmerman started to get his silly ass kicked by Martin. I still have my doubts about this, but let’s say it’s true.

What kind of pussy pulls a gun when he’s catching a beat down?. If you start a confrontation with someone that leads to a fight and the fight doesn’t go your way, guess what? You take your beating like a man, you don’t reach down and pull a gun out of your vagina when you start getting beaten up by the 17-year-old kid that YOU went after. So even if it’s true, I have no sympathy for Zimmerman whatsoever. Taking a gun to a fist fight is not, as they say, “fair.” The fault in this incident lies solely with one man and one man alone: George Zimmerman.

Demand justice.

Required iPhone & iPod touch Screenshot Upgrade for Retina Display

Just got this email from Apple:

Required iPhone & iPod touch Screenshot Upgrade for Retina Display

When you create or update your apps in iTunes Connect, you must upload screenshots that are high-resolution. We require your screenshots as high-resolution images so that your app is optimized for the Retina display.

The requirements for high-resolution images are 960 x 640, 960 x 600, 640 x 960, or 640 x 920 pixels. Images must be at least 72 dpi, in the RGB color space, and the file must be .jpeg, .jpg, .tif, .tiff, or .png. You can update your screenshot files at any time in iTunes Connect.

I’m posting this here more for myself than anything else, so I don’t forget.

So much has happened since the start of the year

Or “Why I’m a bad blogger.” I’ve been immersed deep in iOS development. Ever since getting my first app approved in the app store I’ve been working on the iPad version, which is significantly nicer than it’s iPhone counter part. First, there’s only a couple of web views, most of it is UITables geting populated from the wggb.com rss feeds for different categories.

But most of the work went into designing the user interface, which has three columns, a left menu bar, a master view with the ability to search stories, an expandable detail view (which uses gesture recognizers so users can swipe to expand and retract) and a comments popover with the ability to add comments to stories. The app uses delegates to communicate between the different view controllers.

Some of the new things I learned writing this app include:

  • The use of viewDidLayoutSubviews.
  • More about using delegates and properties.
  • Gesture Recognizers
  • Setting up a UISearchBar.
  • Learned how to properly parse XML using NSXMLParser (that was tricky).
  • Learned more about UIViews, including animations and positioning.
  • Learned more about how to use the Xcode debugger.
  • And I learned that Stack Overflow is the absolute best resource for iOS development.

A note on the last bullet point. I seriously wouldn’t have come as far as I have without the use of that website. It is rife with information, answers to common questions and tons of brilliant developers who give up their time to answer questions from noobs like me.

Once I’m done with this app, I’ll try to put together a tutorial or two explaining some of the more challenging things that noobs like me will do when creating an iOS app like grabbing and parsing an RSS feed and populating a UITable with the data, searching a wordpress based site from an iOS app or how to grab and display comments and submitting your own. Or maybe just how to set up multiple view controllers and communicate between them using delegates.

One other thing that I’m working on is using core location services to grab your location so folks can submit traffic delays to ABC40. But more on that later as I haven’t really scratched the surface yet.

PullToRefresh iOS 5 and ARC Tutorial

When I first wrote this post I had been working on my first “official” iPhone app for my company. It’s a basic news app that pulls information from a WordPress powered news site. One of the first features I wanted to add was Pull to refresh. The problem I encountered was that because iOS 5 had only been out for a short time, the standard PullToRefresh libraries (most notably EGOTableViewPullRefresh) hadn’t been updated for iOS 5 or ARC. Converting the code to ARC is easy enough with Xcode’s Refactor tool but I was also looking to use the code on a UIWebView and there was no documentation for how to set that up.

Luckily, I came across a fork of the EgoPullToRefresh code at GitHub called PullToRefreshView, which had a very good README file with directions on how to implement for both a UITableView and a UIWebView. Also, there was a lot less code that needed to go into your controller as compared to the original EGOTableViewPullRefresh code. I built upon this code base.

Let’s get started

I created my own fork of PullToRefreshView, which is available here. So, if you haven’t already gotten it, go get it. After you add PullToRefreshView.h, PullToRefreshView.m arrow.png and [email protected] to your project, go to Edit->Refactor->Convert To Objective-C ARC and refactor to make the files ARC compliant. Once you’ve done that, you can start adding code to your project.

For a UITableView, it’s really simple. First, #import “PullToRefreshView.h”, then add an iVar:

Then add the following to your UITableViewController in ViewDidLoad:

Next, you simply add the delegate method for when the user pulls to refresh:

Finally, in your reloadTableData method, call finish

Your done.

A couple of Tricks

One of the first things I noticed was that my app would freeze while it was loading data. This really annoyed me, probably because I’ve gotten so used to other apps like Facebook or Twitter that still allow you to scroll up and down while the app is reloading it’s data after pulling to refresh. To fix that we change our delegate to look like so.

Pretty self explanatory, this basically runs the task in the background.

The second thing I noticed was that there wasn’t a way for me to trigger the Pull to Refresh code without, well, pulling to refresh… I wanted to be able to trigger it when bringing the app back to the foreground. Here’s how we do that.

Add the following code to ViewDidLoad

Then add this to your UITableView:

The first line scrolls the view so you can see the loading “screen”, the second line sets the state of your pull scrollView to loading and the third is your call to reload your table data. Now your PullToRefreshView will fire when you bring the app back into the foreground.

PullToRefresh a UIWebView

Working with a UIWebView is slightly more complicated because there’s a few more steps involved. In the controller that contains your UIWebView, create an iVar for your scrollView:

Next, in ViewDidLoad make the UIWebView a delegate to itself and give it a tag:

Now add the following to your ViewDidLoad:

Now you can set up your PullToRefreshView scrollView and add it to the webView:

You’ll probably get a warning on line 3 ([pull setDelegate:self]), if so, go into the .h file of your controller and #import PullToRefreshView.h then add <PullToRefreshViewDelegate> to your @interface declaration like so:

That should squash the warning. Or you could skip all that and typedef the setDelegate method like so: ([pull setDelegate:(id)self]), the choice is yours. Moving right along, add the following to your controller:

Then in your webViewDidFinishLoad method, add the following:

That’s it. Now you have Pull To Refresh working in your UIWebView. Thanks to iStopped for his work on this.

WordPress: Display first image in each post

In a recent WordPress project I was working on, I was looking for a quick way to get the first image from each post to show up in the list of posts. I couldn’t find anything that worked the way I wanted it to, so I came up with this idea using Simple HTML Dom Parser. Download simple_html_dom.php to your computer, then upload it to your theme’s directory.

Then, edit your functions.php file (if it doesn’t exist, go ahead and create it) and add the following code:

Then, in your template, do something like this:

You can configure it to return nothing for specific categories that you want to exclude and don’t forget to style the img_class css class in your stylesheet.