Your programs need to deal gracefully with being offline. Mugunth Kumar has built an excellent toolkit that manages REST connections while offline called MKNetworkKit, and Chapter 17 of our book is devoted to the ins-and-outs of this subject.
But sometimes you just have a simple UIWebView, and you want to cache the last version of the page. You’d think that NSURLCache would handle this for you, but it’s much more complicated than that. NSURLCache doesn’t cache everything you’d think it would. Sometimes this is because of Apple’s decisions in order to save space. Just as often, however, it’s because the HTTP caching rules explicitly prevent caching a particular resource.
What I wanted was a simple mechanism for the following case:
- You have a UIWebView that points to a website with embedded images
- When you’re online, you want the normal caching algorithms (nothing fancy)
- When you’re offline, you want to show the last version of the page
My test case was simple: a webview that loads cnn.com (a nice complicated webpage with lots of images). Run it once. Quit. Turn off the network. Run it again. CNN should display.
Read more…
For those who have asked (and it’s the #1 question I’m asked about the book), iOS 5 Programming Pushing the Limits is now available in Kindle format, along with iBook and Adobe eBook. Enjoy
For those who have asked, the Adobe E-Book version of iOS 5 Programming is available now from Wiley. I’m not certain yet when the Kindle version will be out, but I’m looking into it, along with getting a list of what other formats are planned.
I have no idea what Amazon rankings really mean right around a book launch. Since they weight towards recent sales, I’m sure they spike, so you have to take these things with a grain of salt. But for at least a little while, we have the #1 book in Mobile & Wireless Programming. I promise I won’t keep spamming you all with book updates, but it’s the first time I’ve been at the top of a “best sellers” list.

Amazon's product details 2011-12-14
I’ve mentioned that Mugunth Kumar and I have been working on a book, iOS 5 Programming Pushing the Limits. It’s available now for pre-order and should be shipping by 12/20. It will be available in several eBook formats, though I don’t have all the details for that yet. I’m proud of what we’ve been able to put together here. The target audience are developers who have some iOS development under their belts, and are ready to move to the next level. Rather than just focus on the nuts and bolts of getting things done, we cover how to do things well. In the process, we cover a lot of more advanced ground, often of frameworks with “Core” in their names like Core Animation, Core Text, and Core Foundation. We also address practical issues like how to optimize your application for offline work, and how to best handle REST and JSON.
Please send any comments or corrections to me at robnapier@gmail.com. In the meantime, you can take a look at the example code.
Update: You can now download the full example code from my book at the Wiley site. This comes from Chapter 11, “Batten the Hatches with Security Services.”
I see a lot of example code out there showing how to use CCCrypt(), and most of it is unfortunately wrong. Since I just got finished writing about 10 pages of explanation for my upcoming book, I thought I’d post a shortened form here and hopefully help clear things up a little. This is going to be a little bit of a whirlwind, focused on the simplest case. If you want the gory details including performance improvements for large amounts of data, well, the book will be out later this year. :D
Read more…
I went out to NSCoder RTP for the first time last night and met up with Josh Johnson, who has been interested in taking up PandoraBoy development. So expect some changes coming up. Probably a move to github. Probably dropping 10.5 support soon. And who knows, it might even really work again.
The whole reason I learned Cocoa in the first place was so I could work on PandoraBoy. It’s a great project, but I haven’t really worked on it in quite some time. As Pandora changes, PandoraBoy becomes more and more broken. I barely have time to look at the patches that have been sent it, let alone apply them. My life has moved onto many other projects.
I’m actively looking for a new maintainer. It’s a good project, and the code base is in decent repair, though I don’t know if it builds with Xcode 4. The system basically works, but there’s a long list of things that could be improved, and some things that are now downright broken. If you’re interested, let me know and I’ll help hand it off. I took it over when I knew next to nothing about Macs. It’s a great place to learn.
I don’t usually shill for my company’s products, but I’m really impressed with the new M300 we just put out. It’s an IT management appliance targeted at companies with 50-200 computers. I like how simple it makes setup; reminds me of Apple. Fewer “fiddly-knobs” and more “just works out of the box stop messing with it.” We’ve got the K1000 for those companies who need lots of configuration, but I’m excited to see us get into the SMB space like this. I know most of you don’t need an SMB IT management appliance, but it’s just a pretty cool box and I’m proud to be involved.
Working at Dell KACE has been awesome. Yes, it’s strange being a “Mac developer at Dell,” but KACE is like this little startup inside of Dell. It’s like having the best parts of a startup, without having to worry about funding. And Mac is a big deal to a lot of our customers, so we take the cross-platform work very seriously. As a low-level guy, it’s interesting keeping everything working smoothly across Windows, Mac and Linux (and what seems an ever-growing number of Linux distros….)
I’ll try to bring back some Cocoa content soon. When not pushing product out the door at KACE, I’ve been continuing work on my upcoming book, which takes up most of my non-KACE time. The title is now official: iOS 5 Programming: Pushing the Limits with Mobile Apps for Apple iPhone, iPad, and iPod Touch. It should be out in a few months. I’m working with Mugunth Kumar, who has been an excellent coauthor, and I’m really pleased to have added Mithilesh Kumar (no relation) as technical editor. I like how the book is shaping up. We’re targeting those who want a more advanced iOS book, focused on the non-obvious things you can’t easily get by skimming the docs. Hope you all like it.
I’m back in full book-writing mode, now working with Mugunth Kumar, who is brilliant. Go check out his stuff. Hopefully we’ll have something published and in all your hands by the end of the year. The book has taken up most of my writing time, so the blog will continue to be a bit quiet, but sometimes I like to answer a Stackoverflow question a bit more fully than I can there.
Today’s question is about laying out text without CTFramesetter. We’re going to take a whirlwind tour through some CoreText code to demonstrate this. It’s not quite what the OP was asking about, but it shows some techniques and I had it handy. I’ll be writing a whole chapter on Core Text soon.
The goal of this project was to make “pinch” view. It lays out text in a view, and where ever you touch, the text is pinched towards that point. It’s not meant to be really useful. Everything is done in drawRect:, which is ok in this case, since we only draw when we’re dirty, and when we’re dirty we have to redraw everything anyway. But in many cases, you’d want to do these calculations elsewhere, and only do final drawing in drawRect:.
We start with some basic view layout, and loop until we run out of text or run out of vertical space in the view.
Read more…