Wednesday, October 28, 2009

More iPhone 3 Development Update

Posted by Hidayat Hidayat at 6:59 AM
The writing of More iPhone 3 Development is starting to move faster now, at least in terms of the number of pages we're churning out. It's not going as fast as we'd like, and nowhere near as fast as Apress would like, unfortunately, but it is going faster. The good news is that we're really happy with what we've written so far. More iPhone 3 Development is not just more of what was in Beginning iPhone 3 Development. We have a much greater focus in this book on application design and on writing code for maximum reuse. Many of the objects we write can be used unmodified in your own applications. We assume that the reader has done some development and is ready to take things to another level.

We're just finishing up the networked applications chapters. Our original plan was to just cover GameKit networking over Bluetooth, which is relatively straightforward since Apple provides high-level objects that handle all the gnarley aspects for you. We were originally not going to cover online play over regular network connections. Our original thinking was that because there's no high-level objects yet for sending and receiving over the network that are suitable to network play, that to do an online play chapter well would require a really long chapter. Long both in terms of number of pages, and in terms of how long it would take us to write, and we didn't feel like we could afford another long chapter in light of our schedule.

To be perfectly honest, I had hoped that GameKit would add support for online play and then the whole thing would become a moot point since the GameKit chapter would be all you needed. Apple may still add that functionality to GameKit at some point (there are certainly hints in GameKit), but they haven't yet, and frankly, there just isn't a good place to go and find out how to do online play. All the information is out there, but nobody's put all the steps together in a single, easy, comprehensive place, at least as far as I've been able to find.

So, after some back and forth discussions with Dave, we came to the conclusion that we needed to cover online play in addition to the straight GameKit chapter in our original Table of Contents. We decided to do it as a follow-on chapter to the GameKit chapter. We take the game that we created in the GameKit chapter and add online play to it. We show how to use Bonjour to let the user find other peers (pretty much the same way GameKit does over Bluetooth) and show how to connect to them and exchange data in a similar manner to GameKit so we don't have to substantially rewrite the application's logic. The use of Bonjour limits play to opponents on the same network subnet (basically, phones connected to the same router or WiFi base station), but the techniques are the same for play over the internet, and we're going to have a sidebar that shows how to connect to remote machines based on a DNS name or IP number and port. The other thing this offers over GameKit is that the code can be used on a Mac, so you can write code that lets an application on a Mac talk to one on an iPhone, which opens up a whole slew of possibilities.

As with the Core Data chapters, our focus has been on writing code generically to maximize reuse, and I think we've done a good job as far as the online play stuff is concerned. We've created a class that works very similarly to GameKit's GKSession class. You pass it NSData instances to send, and it takes care of sending and receiving the data, re-assembling the packets, and making sure its delegate receives the data in the same order it was sent in. You should be able to just drop this class (along with another supporting class) into your other projects and use them as-is, making it relatively easy to implement network play. To add online play to an existing GameKit app with this should also be relatively trivial since that's what we do in the chapter.

For those who have asked what fruit will be on the new book, it'll be a blood orange.

I don't know if the cover to the left is final, but it's what is on Amazon right now, so I figure it's okay to share. Until it's approved, it definitely could change, but this is the cover image you'll see if you pull it up on Amazon. Note that the description on Amazon definitely isn't final, either.

0 comments:

Post a Comment

Related Post

 

Copyright © 2011 Next Iphone | Store Mobile Phone Store