Rabu, 28 Juli 2010

App Licensing

Google took an interesting step recently by adding a service called App Licensing to the Android SDK. I haven't looked at it in detail, but the gist of it is that it's a license validation system for third party apps. It allows third party apps to check with the Android Marketplace to see if it's authorized to run on the particular device. To simplify it beyond recognition: It's sort of like Steam for Android Apps.

This is a bit of a double-edged sword for Google, though. Steam-style online authentication isn't exactly warmly embraced by the proponents of "open" systems, but given how easy it is to pirate applications downloaded from the Android Marketplace (and then return them for a refund!), it's probably a necessary step to attract developers to the platform. Google has to at least look like they're trying to stop the rampant piracy.

But here's the thing: With an open source OS, I can think of a dozen different ways to try and circumvent something like this, and I'm hardly a 1337 hacker. Google can add complexity and make it harder to circumvent, but if someone with the right skills has full access and control over the hardware and software, you can't stop them from getting around any kind of licensing authentication scheme you create. It's like DRM. Within a few months (at most), there'll be an exploit or hack to allow pirated Marketplace apps that use App Licensing to be run without a license. I can almost guarantee it. Google can keep changing the process to fight the pirates, but it's a losing battle, and likely would entail a lot of inconvenience to developers in the process.

This is one area where a closed system has advantages. For us iPhone developers, only about 10% of our potential audience can possibly pirate our apps because pirating requires jailbreaking. That 10% is the starting point. The most it can be. Jailbraking is a quid pro quo, so 90% of our potential market can't, won't, or wouldn't know how to pirate an app. But the real number is even smaller than that. Not everybody who jailbreaks their phone pirates apps - there are other valid reasons to jailbreak (so I'm told, I've never been tempted myself) - and I know people who have jailbroken their phones who are ethical and wouldn't consider pirating an app.

There's no doubt that there are advantages to "open" systems, but there are also disadvantages. In this particular case, one of the most major drawbacks of "open" doesn't hurt Google or the Wireless providers, it hurts third party developers. If that wasn't true, Google wouldn't be devoting engineering hours to try and stop it with 'app licensing'.

Life as an iPhone Dev has it's problems, no doubt. When you have an app sitting in review for months, the way Briefs has been, when you get rejected on seemingly arbitrary or inconsistent grounds, or when you can't implement something that would benefit your users because of a term in the license agreement, it sucks. But, when all is said and done, a good app on the App Store properly promoted can make enough money for a development team to live on. Until that can be said about the "open" Android Marketplace, I simply can't buy into the "open is better" mantra.

If a curated platform offers a better user experience and allows third party developers to actually make money, I just don't see "curated" as a dirty word, no matter how many times Google's Android Evangelist tweets it.

Selasa, 20 Juli 2010

Those Were the Days…

The Computer History Museum has recently posted the original source code for MacPaint and QuickDraw! Apple has given them permission to publish them both, and they're well worth taking a look at if for no other reason than to realize just how good we programmers have it today.

The source code is a combination of 68k assembly, resource files, and Pascal, and all of the code was written by the incomparable Bill Atkinson, one of the early heroes of Mac programming and author of Hypercard (among many other things).

As an interesting aside, Bill stopped programming several years ago to focus on photography, but started programming again after the iPhone SDK came out so that he could create PhotoCard.

If you're not really familiar with who Bill is, you might want to read some of the stories on Folklore.org, but be warned, it's easy to lose track of time at that site if you have any interest in Apple history.

Note: One question that occurred to me looking at this source code was "how could Bill could have coded this back then?" These were written before the Mac shipped, and the Mac shipped with only 128k of RAM, which is smaller than the MacPaint Pascal source. You couldn't have opened some of these source code files on an early Mac due to their size. The answer appears to be that they were written on a Lisa, which shipped with a meg of RAM. That was some crazy amount of memory for the day and part of the reason the Lisa cost $9,999 (somewhere between $19k and $40k in today's dollars. I do seem to recall reading, though, that the early versions of QuickDraw (aka LisaGraf) were written on some model of Apple 2, though.

Minggu, 18 Juli 2010

A few things iOS developers ought to know about the ARM architecture

The Wandering Coder has a great post today titled A few things iOS developers ought to know about the ARM architecture. There's some really good information about the different ARM architectures in different iOS devices and different generations of certain devices. Well worth the read.

Sabtu, 17 Juli 2010

On Swords, Perspective, and Spin…

Although I thought Apple started off a little too defensive yesterday, when you boil it down, I thought they did the right thing. If you're having a problem and a case can fix it, here, have a free case. If you already bought a case, they'll refund the money you paid for that case. If you bought an iPhone 4 and the problem keeps you from being able to use or enjoy your phone, they'll take it back, no restocking fee, no questions asked.

All other issues aside, I'm not sure what more Apple could or should have done. There aren't many products that come with an unconditional guarantee any more, yet reading some of the output of various so-called tech "journalists" since yesterday's press conference, it seems that there are many who think that Apple didn't do enough and didn't "do the right thing". Short of Apple's senior management taking out swords and falling on them (at least proverbially, if not literally), I don't think anything would have made certain journalists (and I use the term very loosely) happy.

Of course, it's not exactly good for the tech press if this quietly goes away or turns out to be much ado about nothing. They're having a grand old time and raking in a lot of page hits on this whole "antennagate" thing they've created, so I guess it's understandable that they don't want to accept a reasonable response from Apple. They clearly wanted nothing less than a fall from grace… an admission that Apple didn't design or test properly. Instead, they got treated to a number of facts that didn't jive with what they wanted to hear. They were shown other phones experiencing similar phenomenon. They were shown a little about the testing procedures the phone went through and the investment Apple has made toward testing their antenna designs. They were shown, in short, why Steve doesn't think they did anything wrong.

The natural reaction to cognitive dissonance is anger, so I guess I shouldn't be surprised by the angry diatribes from some sectors of the tech press, especially those who aren't fans of Apple to begin with. But anybody who expected anything else out of yesterday's conference call are either intentionally stoking the fires for their own benefit or else they're morons who fail to realize there are perspectives other than their own. Perspective is an interesting thing, and it's not quite the same thing as "spin", which it is often mistaken for. Perspective is your own world view. It's a combination of a whole bunch of things that make up the way one person thinks about things: their likes, dislikes, biases, priorities, and fears. Spin, on the other hand, is when somebody intentionally tries to conflate facts, or select facts to make their position look better.

And make no mistake, we saw some spin yesterday. Some of the statistics early on were very carefully selected. The iPhone 4 dropped call rate being 1 in 100 less more than the 3Gs call drop rate, for example, sounds small, but what was the 3Gs' dropped call rate? If it was 1 in 10,000, then that's a statistically huge change. If it was 3 in 100, then it's statistically tiny, probably within the margin of error. We weren't given enough information to know what that statistic meant. If I had to guess, I'd say the difference was probably statistically significant (though not necessarily huge) or they wouldn't have presented the data that way.

But, even with the spin, it was pretty clear that from Steve's perspective Apple went through a very rational, valid design and testing process and achieved something pretty amazing. And I tend to agree. I wouldn't easily give up my iPhone 4 now. It's an amazing piece of technology. It really is. I love just holding the damn thing in my hand. It's such a refreshing change from all the cheap plastic consumer devices in my life. Every other device that the iPhone manages to replace in my life (my point and shoot camera was the latest casualty), the happier I am. I would quite honestly give up using cell phones before I'd let somebody replace my iPhone 4 with a junky plastic Blackberry or Nokia phone with their confusing, poorly written and terribly designed software.

Now, that's not meant to downplay the antenna issue, because for some people it is real and a hassle, I'm just stating my own perspective. Regardless of your perspective, however, the evidence seems to show that statistically speaking, most people in most places are going to have better reception with this phone. All design is about tradeoffs and all products are designed to meet the needs of a wide variety of people. Moving to an external antenna system was a conscious choice that Apple made, and it appears to have been well thought-out, researched, and tested. A conscious design decision was made that would make more room for battery and additional sensors and gadgets while making the phone more solid feeling and still thinner than any previous phone. The tradeoff, other than the obvious ones of manufacturing costs, was the increased possibility for attenuation. Now, we know, thanks to Anandtech, that this attenuation can cause a reduction of up to 24dBm of signal strength. We also know that that amount makes no measurable difference in data speed or voice reception for most users in most locations. Months ago, before the iPhone 4 came out, and without the benefit of hindsight or knowing what kind of media circus would ensue, that almost certainly would have seemed like a perfectly valid tradeoff. "Wait, if we do this, most people, most of the time will have better reception and we can make the phone smaller and have better battery life and fit a gyroscope, and the only tradeoff is that some people in some situations if they hold the phone in a certain way will have one or two less bars? Great!"

Was it the right decision? Well, with the benefit of hindsight, perhaps not if you factor in the negative publicity they've gotten. But, was the decision the kind of stupid mistake that deserves payment in blood? Absolutely not. Even suggesting it is ridiculous.

The iPhone is a consumer product. It's like off-the-rack clothing. It's not custom tailored to any one individual. It's the product of a long series of design decisions trying to make the best product for the largest section of the population. If you're an outlier - if you're one of those people for whom the issue is preventing you from using the phone, put it in a free case, or bring it back. Apple will give you your money back, AT&T will let you out of your contract. No questions asked, no restocking fee. You're then free to go find a phone that works better for you.

If you want or expect more than that, you've got pretty serious entitlement issues. If you don't want to do that because you think you can't find a better phone, then maybe you need to re-assess your own perspective.

Jumat, 16 Juli 2010

iPhone 4 Press Conference

Well, the iPhone 4 press conference just ended, and I thought I'd type up my thoughts quickly before diving back into work. Overall, the end result is exactly what I thought they'd do: free cases and refunds for those who want them. Seems very like a fair response to me.

I thought Steve started the presentation sounding a little defensive, though I can understand why. By the middle of the performance, though, he really hit his stride, and by the end I'd have to say it was one of Steve's best performances to date when you factor in that he wasn't announcing a new product, but instead defending an existing one, which is never as much fun or as easy.

The main points were that yes, you can interfere with reception on the iPhone 4 by grasping it a specific way, but you can also do that on most smart phones (they demonstrated it on several models of competitor phones), and that the press was making a bigger deal out of this than customers were in search of a headline. He pointed out that both Apple and AT&T were seeing lower return rates for the iPhone 4 than for the 3GS, in fact the returns have only been a third of what they saw with the 3GS.

There were little bits of insight into life at Apple that were unusual. We don't usually hear much about their actual processes (except manufacturing processes which have been part of their PR since the unibody computers). Seeing the anechoic chamber was cool and it was interesting to hear a bit about the process they go through to test reception on the antenna designs. Hearing about the problems AT&T has with getting new cell towers approved in San Francisco was somewhat enlightening. I've been rather harsh about AT&T's signal in NYC and SF myself, but never really though about the NIMB factor. I'm not ready to become an AT&T fan boy, but I am ready to cut them a little bit of slack on that issue now.

We also heard that Apple has sold over three million iPhone 4s in roughly 3 weeks and that they're still selling every one they can make. That's impressive considering the amount of bad publicity they've gotten from this issue.

At the end of the session, Steve pulled up Bob Mansfield and Tim Cook to answer questions, and I thought that was especially well handled with some nice bits of humor, though they took off the gloves about a few reports, especially one from the NYTs about a supposed software bug contributing to the reception issue. I especially like the comment that was made when Bob Mansfield was talking about how they sometimes send engineers to a customer's house to test reception. Bob said "For the record, we notify them we're coming", and Steve chimed in with "…and we didn't bash in any doors". Just a great response, it showed a sense of humor while getting in a bit of a jab at Gizmodo (who were never once mentioned by name that I can remember - it was always "some website" when talking about things they did).

There were two other things that struck me, but I'm not sure if they are worth mentioning, they might just be be reading too much into things, but I will because it's fun to speculate about such things.

The first thing is that Steve mentioned that Apple has Verizon cells on campus in addition to AT&T cells. Now, it's not uncommon for large companies to have towers onsite to ensure their employees get good reception at work, but it seemed odd that he felt it was worth mentioning that they had Verizon cells on campus when talking about an issue that would only be affected by AT&T towers.

The other thing that struck me as odd was the fact that in one of the question responses, Steve talked about the press "going after" Google because they were successful and that he wished the they wouldn't do things like that. He talked about how great the stuff Google made was and made a weird little comment about people not appreciating innovation that's still happening inside the U.S. Again, it may not mean anything, he could have just been trying to think of a big successful U.S. tech company and that was the first one that jumped to mind, but given the state of affairs between Apple and Google lately, it seemed oddly conciliatory and defensive. Perhaps a hint that the Google/Apple competition is headed back to more civil grounds even if may never go back to the days of friendly coopetition of yore? I dunno, but maybe. We can hope.

That's all, now it's back to work. You should too, slacker.

Update: Apple has just posted a new page explaining attenuation and signal loss.

Kamis, 15 Juli 2010

On the iPhone 4 Reception Issue…

Until today, I've kept pretty much quiet on the iPhone 4 reception issue. Part of that was simply that I didn't own a phone until a week ago when my pre-ordered phone finally arrived. Part of it was just that I'm crazy heads-down on the book and doing client work right now. And part of it is that I'm having trouble deciding exactly what I feel about it. It feels to me like the issue is being overblown, but I doubt that people who are severely impacted feel that way.

I also don't think Apple has handle the situation as well as it, perhaps, could have. Apple is normally exceptionally good at "spin", but the response to this issue has felt a little ham-handed.

For me, I can recreate the issue if I try, but not in the drastic way that some people can, and not consistently. I've been able to get my phone to drop from five bars down to three, on a few occasions even down to two. Sometimes it won't go down at all. I don't know if it's whether there's moisture on my hand or what, but sometimes no amount of pressing will cause it to drop, other times, simply placing my thumb over the break on the left side will cause it to drop one or two bars.

Fortunately, even though I usually hold my phone in my left hand both for voice and data, this just doesn't affect me. The way I hold my phone, I don't bridge the gap. But even when I do bridge the gap intentionally, my phone still functions fine even with the lower bars. In fact, my reception and data transfer speeds are measurably faster over 3G than they were on my iPhone 3Gs. We have some large "warehouse" stores in the area (Lowes, BJ's) where I have always lost reception with every cell phone I've ever head when I get more than fifteen or twenty feet into the store. That was true even back when I was on Verizon. My iPhone 4 gets signal in those stores, throughout the store. I also haven't had a single dropped call since I got my iPhone 4. So, for me, not only is this not an issue, I'm thrilled with the reception my phone.

I know it's a real and serious issue for some people and for them, it's preventing them from fully using their phone, and that's gotta suck. But for me, and for all but two people that I've talked to (and I know a few people with iPhone 4s) it's mostly a non-issue in terms of real day-to-day usage. The foofoorah over this really seems a bit overblown to me, not that I've come to expect anything more from powerhouses of journalistic integrity like Gizmodo, but still…

If Apple were to recall the phones or offer a refund, I wouldn't let them have mine. I wouldn't willingly go back to an iPhone 3G at this point. Now, if Apple offers a free bumper, I might take them up on that. I've been thinking about getting one anyway, and only the fact that I live 45 miles from the nearest Apple Store has kept me from getting one already, but I'm not going to be upset if they don't.

I'll be curious to hear what Apple does say tomorrow in their press conference. I have to think that the days of ham-handed responses to this issue are over. They can't afford for those days not to be over. This is hurting their reputation far more than it should.

Ahh… the Sweet Smell of "Open"

Rabu, 14 Juli 2010

Core Data Encryption

I've been asked a number of times about the best way to encrypt a Core Data persistent store. The answers I've had to give have always been somewhat kludgey at best. Apparently, with iOS 4, there's a better answer, and I was completely unaware of the change. If you're storing anything remotely secure in Core Data, it's worth a few minutes of your time to read Nick Harris' post.

via Brent Simmon's ranchero.com

Selasa, 13 Juli 2010

OpenGL ES 2.0 Book Teaser

I've been making really good progress on the OpenGL ES 2.0 book for Prags, and I'm really happy with what I've done so far. The book isn't quite as hand-holding as Beginning iPhone 3 Development was, but it's probably more hand-holding than any graphics programming book I've ever read. If you've got prior experience with graphics programming, you may get frustrated with the pace of the book. I'm working on Chapter 8 now, and I haven't even gotten to lighting yet.

Those of you who have never worked with a programmable pipeline engine like OpenGL ES 2.0 or have tried and been frustrated by the books and resources available, will (I hope) appreciate the approach I'm taking. I'm trying to be very, very thorough. I'm trying not to leave any questions hanging in the air. I've found, over the years, graphics programming books to be frustrating in that they assume a certain level of prior knowledge that's not easy to obtain outside of college math classes. It's my goal to explain not only how to do things, but why, and give at least some high-level information about the underlying concepts and math. My goal is to make graphics programming approachable for people who don't necessarily have math knowledge beyond basic high school geometry and trig. I can't do that with everything. For example, with projection matrices, I simply didn't think it was worth trying to cover homogeneous coordinates, so I focused on how projection vectors worked and mostly skipped the why. But that's an exception. In most cases, I'm really focusing on why we do what we do.

Writing books like this is fun, to be honest. I'm learning OpenGL ES 2.0 at a much deeper level than I previously knew and I feel good about the progress of the book. From the discussions I've had, I think there's a lot of people out there who want to program in OpenGL ES 2.0 so they can do cool stuff on the iPhone and iPad, but who just don't really know where to start. It's like all the cool stuff is sitting on a shelf just out of reach. And that's frustrating.

I don't know yet when the book will be available. I'm hoping that it will get accepted into the beta books program when it's far enough along. If that happens, I'll make sure to post about it here, because then the book will be available for reading online before the official release.

Now, no part of the book is ready for public consumption yet, but I'm going to post some of my code from the book today. I know there's a shortage of good, clean, straightforward iOS OpenGL ES 2.0 code out there, so I though I'd post one of the projects from the chapter I'm working on now for anybody who wanted to try and figure out how it all fits together.

Although it's a a simple app, there's a fair amount going on. I take care of setting up a perspective projection and a model view matrix that both moves and rotates the object and also do texture mapping. There's a simple vertex shader and a fragment shader that take care of transforming the scene and doing the texture mapping. Now, in OpenGL ES 2.0, there are no built-in functions to handle any of these tasks, so it's all got to be done manually, primarily in the shaders. There are also some useful classes and functions you may be able to leverage in your own code. Much of what's in here is based on code I've posted in the past, but it's all been updated and tweaked for use in the OpenGL ES 2.0 programmable pipeline.

Screen shot 2010-07-13 at 11.24.55 PM.png
Yes, it's our old friend, the icosahedron, but all dressed up to look like a twenty-side die. Because, you know, what's more geeky than a twenty-sided die?

Now, this project hasn't been code reviewed. Heck, the chapter it's for hasn't even been written yet, so I'm sure there are mistakes and CBBs (could be betters). This is also not particularly efficient code. I'm putting off until later in the book a number of optimizations, including vectorizing the matrix and vector functions, interleaving per-vertex attributes, and using VBOs and VAOs. At this point, I'm much more focused on clarity and concepts than on performance, so just be aware of that before you decide to incorporate any of this code into a production project.

As always, there are no requirements placed on your use of this code. You don't have to give attribution, and you don't have to contribute back changes, though if you do fix or improve something, I'd be glad to hear about it.

You can find the Xcode project right here.

I've also made the original Blender and Pixelmator files I used to create the vertices and texture coordinates of the icosahedron as well as the texture. You can download those here.

I am sorry, but have to say that I won't be able to answer questions about the code. Between the book and client work right, most days I'm at my desk from 8:00 in the morning until 1:00 or 2:00 the next morning, seven days a week, so if you need explanations, you're going to have to wait for the book.

Jumat, 09 Juli 2010

Thumb

I thought I had done a post on this at some point, but after Googling around, I guess I never did. There were a couple of Twitter discussions about the subject in the past few days, so I thought it was worth mentioning. You can get more in-depth detail about this subject by watching the two OpenGL ES videos from the 2009 Tech Talk World Tour Videos (iTunes link, requires logging in with iPhone SDK account).

The ARM architecture has something called thumb mode (or just thumb). Now, I'm not a hardware engineer so the following may not be 100% technically accurate, but my understanding is that basically thumb mode uses a subset of the processor's available operations and passes two 16-bit operations in the space of a single 32-bit operation, allowing commands to be sent to the CPU twice as fast. For most applications, this is great, and leads to an improvement in overall performance.

However, with the ARMv6-based chips in the original iPhone, the iPhone 3g, and the first generation iPod touch¹, thumb mode didn't have access to the vector processors, so floating point operations forced the processor to convert the two 16-bit operations back into two 32-bit operations, perform the floating point math, and then convert back to the thumb operations, meaning you not only didn't see a performance increase, you often saw a dramatic decrease in performance with thumb on when writing heavy floating-point code, such as you would for an OpenGL ES application.

The version of thumb in ARMv7 which is used by the chip in the iPhone 3Gs and which is also used by Apple's A4 chip and therefore available on the iPad and iPhone 4, does have full access to the vector processors, so you can get the benefit of thumb while doing large amounts of floating point operations, so you want thumb on for these processors.

Therefore, if you're writing an OpenGL ES application, or anything else that does a lot of floating point operations, you want to use conditional build settings in Xcode to turn "Compile for Thumb" ON for ARMv7 and OFF for ARMv6.

You can add conditional build settings by selecting the build setting in Xcode and using the little gear button in the lower left corner of the Build Settings window. If you click it, it will popup a menu, and one of the options will be "Add Conditional Build Setting", which will add a new subrow to that setting. Select "ARMv6" on the left column and use the right column to turn it off. Once you do that, your application will build as a fat binary with an ARMv6 version that doesn't use thumb, and an ARMv7 version of the binary that does. Generally, the increase in application size is relatively minor compared to application's image and sound resources, and the performance gains can be substantial.

Jumat, 02 Juli 2010

Pressure Sensitive iPad

One thing that I've wished the iPad had from the beginning was the ability to detect different levels of pressure, similar to a Wacom tablet. That would make it much more useful for things like sketching. I've heard from a few people that the hardware supports it, but I've been skeptical of those claims. How could a capacitative touch device detect pressure? But a few people I talked to at WWDC insisted it was possible with the hardware.

Turns out they were right. This is really cool. I don't know anything about the technology - whether they're really using pressure (I tend to doubt it) or just the relative size of the area being touched, but the results in the video look promising. I also hope the final version can be accomplished with only public APIs somehow.

Kamis, 01 Juli 2010

Synthesize by Default

So, in my previous post, I told you I was excited about the "synthesize by default" functionality that's now available in LLVM 1.5. And I am, very much so. But it turns out there's a caveat that tempers my excitement at the moment.

With synthesized iVars, we've had direct access to the underlying synthesized variable for a while now, so if you created a class like this:

#import <UIKit/UIKit.h>

@interface MyViewController : UIViewController
{
}

@property (nonatomic, retain) NSString *foo;
@end


You're able to access the NSString variable foo that backs the property of the same name within the scope of your class. So, in your dealloc method, you can do this, to give one common example:

- (void)dealloc
{
[foo release], foo = nil;
[super dealloc];
}

However, if you enable the "synthesize by default" feature in LLVM 1.5 and use it, meaning you don't actually have a @synthesize statement for the foo property, you lose this direct access to the underlying variables, leaving you with a bit of a conundrum - how do you do your memory cleanup without unintentionally triggering unwanted functionality, such as those in a lazy accessor or some more involved mutators.

Earlier today, I tweeted a question asking about the correct way to deal with this situation. After a bit of a Who's on First-like back and forth with many smart people, it finally came out that this is a bug in LLVM, not an intentional design decision. Hopefully it will be fixed before too long, but in the meantime, the best answer is probably to just keep using @synthesize.

Thanks to a whole bunch of people on Twitter, many of whom I'm sure I missed!