Magic Wizards is Now in the App Store

The latest game created by my team and me is called Magic Wizards¬†and it’s both free and awesome. Based on a joke song written with a friend, Magic Wizards is a space-shooter role playing game (RPG if you’re nerdy) starring a wizard with fire, ice, and lightning spells. Check it out and post a review in the App Store or let me know what you think in the comments. I’m thinking of selling the source code and/or doing a tutorial series if there’s enough interest as well.

Adding iOS Push Notifications to Your Apps and Games

After a few days trying to figure out how to add push notifications to my newest game (coming in a week or two!), I finally figured out how the whole system works. I’m not going to do a full tutorial here, just elaborate on some existing tutorials I found and fill in some extra details that I had to figure out for myself.

Step 0: Some ISPs, including BlueHost, do not automatically open ports 2195 and 2196, which are used by APNS to handle push notifications. If you use one of these ISPs, you can contact customer support to open the ports. If it is BlueHost, you will likely have to pay extra (about $30/year currently) to have the privilege of opening them.

Step 1: use EasyAPNs. There’s an excellent video tutorial on their site to get you 95% of the way there yourself. Download the source, and follow the video to install Easy APNs on your web server.

Step 2: Make sure that any devices that are running a development provisioning profile version of your app are set to sandbox mode in your database, and that any devices running the ad-hoc version are set to production.

Step 3: You probably want to send messages to ALL users, rather than just one. To do that, you’ll just need an array including the pids of the devices you want from the devices stored in your apns_devices database. I ended up adding some code to my apns.php file to handle it. My code (which I mostly copied from a helpful poster at the Easy APNS Google code group) looks like this:

$sql = "SELECT `pid` FROM `apns_devices` WHERE `status` = 'active'"; 
$result = $db->query($sql);
$pids = array();
$i = 0;
while($row = $result->fetch_array(MYSQLI_ASSOC)){ 
 $pids[$i] = intval($row['pid']); 

When you create the new message, just make sure to pass in the $pids variable instead of a single number for the device you want to send to. This will create one message in the database for each device that is running your app.

Step 4: Make sure you tell the $apns object to run processQueue() at the end of your code.

Step 5: You need a way to easily add new messages, but make sure no repeat messages are sent to the same user. To handle this, I created a text file in the same directory as my APNS code. This is how I handled it in apns.php:

$message = file_get_contents("example.txt");
if($message != "")
file_put_contents("example.txt", "");

So the data gets read from the text file, provided there’s any text inside of it, and the contents of the file are cleared once the message is added. Boom. No repeat messages. And all you have to do to add a new one is add the message content to your text file.

Step 6: You want your cron job to run apns.php with the flush value passed in, which is explained back at Easy APNs. This will go through all the messages that have not yet been sent, and attempt to send them.

That’s it. Enjoy having your own custom-built push notification system for your apps.

What’s new with Todd Perkins?

This morning I went to upgrade WordPress, and like and idiot did not make a backup of my site. Of course everything was deleted, and I now have to create a new site from scratch. Good times!

The good news is that I’ve somewhat shifted my focus in my career, so a new website makes sense for me. I’m moving into the game development realm more, and now have several games in the App Store under developer titles Todd Perkins and Wedgekase Games. Here’s a list of them:

All of the games that aren’t free do have free versions that you can check out as well.

I have also been creating a team of game creators to build a full-service game development studio. If you’re interested in hiring us, contact me through the Contact page.