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, 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 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…
CoreText is a very powerful system for laying out text in arbitrary ways. This is going to be a bit of a whirlwind tour of it to help out nonamelive on StackOverflow. I’m working on an advanced iOS book right now, and I’ll have a longer writeup there.
Read more…
I’ve been playing with Core Text recently, and one of the things I wanted to do was layout text in an arbitrary CGPath. On Mac, you’d do this with NSLayoutManager, but iOS doesn’t have that so we have to build our own. I’ll discuss Core Text more later, but one of the steps along this problem is how to clip a CGRect to a CGPath. I found several discussions of finding CGPath intersections, all explaining the basic technique. Draw the things you care about into a bitmap context and then inspect the pixels to see where they overlap. Clear enough, but it was hard to find a small code sample that demonstrated this with Core Graphics.
For my purposes, I want the first full-height rectangle within the intersection of the line rectangle and the CGPath. Later I will expand this code to find all full-height rectangles within the intersection (there can be more than one), but this is enough to demonstrate the point.
Read more…
For those of you having trouble with Flash 10.1, I’ve fixed PB to handle it. This moves from the hackish “dig around in the NetscapePlugin objects and call undocumented methods” approach to a standard CGEvent based keyboard injection. You can’t use NSApp’s sendEvent: to talk to Flash (probably because Flash is not in Cocoa). But the following code is a good general purpose “send me a virtual keystroke.”
Read more…