Author Archives: Stkim1

Super easy way to self-sign on OSX for XCode

AKA : Self Code-Signing your OSX app without Apple’s developer certificate
(Tested with XCode 4.6 on OSX 10.8.2)
  1. Open up ‘Keychain Access’
  2. Go to ‘Certificate Assistance’ -> ‘Create a Certificate’
  3. Type whatever name you’d like. Then go with ‘Self Signed Root’ and ‘Code Signing’ options.
    Keychain create a certficiate
  4. Click ‘Create’
  5. Check if a certificate is successfully created.
    self signed cert
  6. Open up an XCode project.
  7. Override all of ‘Code Signing Identity’ with the sign-signed certificate, and off you go.XCode Code Sign Identity

Update : This trick works like a charm on OSX applications. Unfortunately, it does not on iOS apps.

Reason being that, I suspect, your certificate and iOS devices registered to Apple should pair up. Otherwise, XCode says the certificate is expired.

*Reference : Code Sign

NSLogger viewer architecture

Whew, two months went by like a bullet. Previously, I wrote a post about what NSLogger is, and why we should exploit it to solve a problem. (About a month ago, even HN talked about NSLogger.)

In order to recap, NSLogger is a very powerful utility that collects logs from your application and provides you rich tool sets to analyze them. My goal is to take the power of NSLogger outside your cubicle to monitor how your app really behaves in unfabricated environments.

NSLogger comes with two parts; libraries for clients (iOS & Android. Yes, it does cover android.), a viewer on OSX. All we need is an iPad Viewer app we can carry outside. OSX viewer is thus a good place to start looking since it is written in same language (Object-C), and shares mostly the same ground with iOS.

So here comes an overview of OSX viewer.

An overview of NSLogger

Model
The viewer is, in essence, a server application which accepts logs from client via stream sockets. It is built in classic MVC pattern having abstracted transports, connections, and log message as model.

The viewer supports three different types of streams (non-secure Bonjour, secure Bonjour with SSL, and direct TCP/IP) and abstracts them in LoggerTransport. Each transport runs its own thread managing client connections with LoggerConnection. A connection then collects and handles each log message with LoggerMessage.

Once instantiated, transports are there to be kept running throughout the life-cycle of the viewer. Meanwhile, a connection will get spawned and removed for each run of a client. If we are to look at how they fit altogether from 10,000 feet, it should look like below.

NSLogger message flow

I believe the setup of model layer part is nicely done, and, at some degree, it is beautiful. The beauty is two folded.

1) First one being that with each layer of abstraction, we can expand or modify to totally different types of connections without too much hassle. Not a lot of network libraries get this right; some being too complicated, or some being too poorly constructed to see it through.

2) With each transport running its own thread and especially its own run-loop, stream events do not get in UI events and vice versa. You’d never miss a stream event just because you touch a cell too long. Plus, we can set up as many transports as we need and no stream event will interfere another as transports are all separated in their own thread and run-roop. Imagine you have ten stream sockets all running on main thread’s run loop. What mayhem are you willing to go though? This seems really no-brainer, but believe me. Even the most popular socket libraries are not built in this way.

Controller
NSLogger Controller

LoggerDocument, a NSDocument subclass, is controller part of OSX viewer. It sticks to the idea ‘fat model, thin controller’, and really carries out. All the heavy lifting is done in model layer and LoggerDocument only routes the messages to view layer.

Each LoggerDocument instance organizes log messages and related views in the context of a client’s activity. LoggerDocument holds all the connections from a single client, and a connection holds all the log messages for a run. If you’re to navigate from a connection to another, you are effectively navigating log messages from one run to another. If you jump from a LoggerDocument to another, you actually move from an activity of a single client to that of another.

Looking down from LoggerDocument, you can see it really represents a whole collection of a client’s activity. This enables the Viewer to have multiple clients connected simultaneously, and to manage them in very organized fashion.

View
NSLogger View

Finally, the view. LoggerWindowController, a subclass of NSWindowController, forms 1 to 1 relationship between LoggerMessageCell and LoggerMessage. LoggerMessageCell then draws LoggerMessage’s content. Simple as that. The thing that makes interesting is how LoggerMessage never gets opened between LoggerTransport and LoggerMessageCell. If you are with me until this point, you can see the whole OSX viewer really comes down to two parts; one that handles socket stream and unpacks raw log, and one that displays the unpacked message. You can take the two parts and put them together as an app, and none will stop you.

The structure in between the two parts, however, keeps collected data very neatly organized, and enables further modification/maintenance without headache. NSLogger OSX viewer really is an exemplary case to carefully study MVC pattern as well as handling of socket stream. I was blown away as soon as I found this was BSD licensed opensource.

In next post, I will describe how to setup iOS keychain to handle self-signed cert to open SSL connections. Please consider subscribing my blog as more awesome stuffs are already in pipeline, and dropping a word to Florent, who single-handedly made all these possible.

* Update : Controller and View parts were added.

Caught at the scene

*This is the first post of series I am going to write. The series is about mobile, all-out-in-the-field logging that might help app developers.

It was back in 2010 when I worked on a location based iOS app. Building the app and its backend altogether was crash-tastic overall, but I managed to come out intact, mostly.

One thing, however, really cornered was logging out in the field. Basically, whenever I took a device outside with my latest build on, the device transformed into a mere consumer gadget. I wanted to know everything that was going on my app right at the spot; ‘is network thread properly handling task queue?’, ‘does location scheduler properly catch input?’, and many more. The device only told me, for example, there were 18 vanues I might be interested. Vanues my ass!!!

I did not want to go back to check if all connections to server went through ok from outside. I did not like to be bothered with a console blocking my pretty app screen telling me things were ok. Nonetheless, I wanted to catch everything right at the moment with ease as they happened without any stunt, y’know? I was a stubborn believer of developer experience (DX), and I still am! As far as I can tell, nothing, I mean not-a-thing, remotely came close to my reach back then. Bummer!

S&W handcuffs. http://www.flickr.com/photos/37815348@N00/5398546351/

Fast forward 2012, I was staring at a websocket library, and I realized it just needed to be re-written so bad. I would do that with smile on my face all the way but on one condition. I needed a good logger library. Like Quinn “the Eskimo” said in WWDC I needed a good logger to come out network mayhem in one piece. There are many options, but I believe only one comes out on top.

It is dubbed as “NSLogger” and written by Florent Pillet.

NSLogger screenshot

In short words, NSLogger is “NSLog + Console” on steroid. NSLogger is basically a server-client logging pair that provides you clients for two major mobile platforms and a separate logger viewer. With the viewer, you can filter log messages however you want as you go.

Here comes a nice introduction by Matthew Burke.

Surely, that is not the end of story. The amazing part is NSLogger not only makes your logging life easy, but also has every element that could finally give us a field logger I was so badly looking for back in 2010. Just about everything we need is right in one place. All we need is some good hard work, and we will have a different notch of mobile app development experience.

If you have come down this far, please consider subscribing my blog, and drop a word to ‘da man’, Florent.

Time to go to work. Stay tuned.

The end of internet application as we know of

I am an iOS developer with the background of building internet application since 1998. I am not an market analysts but I believe I have at least a despicable sense of seeing where things are heading.

As Siri starts making its way into the hands of millions of consumers, everyone starts taking a poke at it and glancing the future Siri might bring to us.

But no one seems to talk about what Siri might do to internet applications such as Google, Facebook, Youtube, and most importantly the ones I am working my ass off for. To make it short, it seems clear to me internet applications are now facing a very stiff challenge. May I dare to say Siri and its clones will end the internet applications as we know of. I am going to explain why I believe so.

Siri, the life delegate
After short period of poking, we will gradually converge our life into Siri. Firstly, we’ll probably start with simple questions such as a reminder for wife’s gift or rescheduling a meeting as they are shown in Apple’s Ad.

Then, we will start throwing more serious ones.

“Siri, find me a good romance book I can read during flight”
“Siri, what do you say about the new movie Matt Damen just shot?”
“Siri, find the most important person in this room I should talk to”
“Siri, do you believe my blind-date today is hot?”

All these question could be answered because Siri isn’t exactly a speech recognizer. Siri is an Artificial Intelligence that can learn, reflect, and extract the best information for the context you are in based on its service partners and experience with you. Siri could access Amazon, Itunes, Klout, and Foursquare. Even Facebook for that matter. Siri aggregates ratings, meta data, your location, your social graph, and, personal preferences. Thanks to its forever-getting-smarter A.I. engine, Siri will understand what you mean by ‘good’, ‘how about’, ‘important’, and ‘hot’, and then bring you the best choice for your context. Your previous complex tasks to find out the best Sushi restaurant for your date is now reduced to simply saying “I want #5″.

I have been wondering why this particularly interesting video doesn’t get more attention than it should. Tom Gruber at Semantic Web in 2008 demonstrated Siri.

KEYNOTE: The Game Changer: Siri, a Virtual Personal Assistant from Semantic Web on Vimeo.

Siri will eventually take vast majority of decision-making tasks for your day-to-day life, and it will soon to be very inconvenient to live without having Siri right besides you. I for one surely join the party.

Siri, the gatekeeper
So let us look at Siri from internet application developers’ view. We have lived up and developed applications with expectations of receiving ‘direct user interaction’ to help users getting answers for very subjective questions such as ‘how about the movie Matt Damen just shot’, or ‘who is the important person in twitter to follow’. We just barely start recognizing the value of user interaction, and start recommending venues, movies, and books to pay attention.

In the video above, Tom clearly explains that Siri is like a librarian. It reaches out all the applications, aggregates data, judges based on users’ historial preference and context, and comes up with the ‘best’ options.

Now ‘direct user interaction’ is all gone but Siri instead comes choose data based on its experience with what users want, and go away with what it grabs. Or more precisely to put, what users might want. Do you believe the data Siri takes represents true necessity of end users? Well, at least I don’t.

When Siri finally becomes a life delegate, the applications we pour our sweat and blood could turn into not much more than Siri’s mere library, a data container. If Siri does not want my application somehow, it is out of sight and out users’ mind. The awesome part is users don’t even know my application is gone.

I believe Siri will be the next gatekeeper of information flow, and, like it or not, our applications will need to be liked by Siri first, just like websites have to be liked by Google search engine. Internet applications as we know will have to transform tremendously in order to retain user loyalty by the the time I cannot sleep without telling Siri to set an alarm.

UIViewController retain/release dance in IB

With impending iOS 5 release, Object-C memory management is going to change for good. With all the release/retain/autorelease gone, it will be even more of no-brainer than it is now. But just in case it might help some, I would like to lay out a particular experience I have had with my code.

I assume you are already familiar with Object-C memory management scheme; when to owe, when to release, and when to retain. When you are to, however, use Interface Builder heavily for fast paced projects, you often have to let IB handle all the initial construction of a complex view controller that contains a lot of sub-views and even child view controllers. These child view controllers are usually called “nested UIViewController” and one of 2011 WWDC session video explicitly talks about that. Nested UIViewControllers can have their own .nib/.xib file so that you can build very complex view hierarchy out of collection of simple view controllers. Not to mention that you can reuse the simple view controllers however you see fit.

In that case, the parent/host view controller might get retained in the shade. Eventually when you touch “Back” arrow button on top of screen, the parent view controller gets “popped” or “dismissed” from navigation controller, but it will never be deallocated. This is called “zombie” object. Especially when nested view controllers take the parent view controller as a delegate or some sort of referral in IB, it could be just so much pain in your private part if you are not careful.

Parent-Child view controller connection in IB example

The side effect of having deallocated but retained zombie UIViewController somewhere in your memory is really bad. It will get you all kinds of colorful pain; EXC_BAD_ACCESS will greet you, NSZombie sometimes won’t find you a clue, memory leak of course, even didRecieveMemoryWarning() gets called on supposedly dead objects. Your app crashes on your face.

I am going to demonstrate three cases where nested view controllers take their parent view controller as a delegate. Each case differs slightly in taking the delegate and the outcomes in the end are of course different.

1. A retain delegate property in interface of a nested view controller.

@interface RetainDelegateViewController : UIViewController
@property (nonatomic, retain) IBOutlet id delegate;
@end

Then I connect the delegate IBOutlet to its parent view controller in IB, and my parent view controller gets retained one more time. If I forget to release somehow, it never gets deallocated when it gets popped from navigation controller. So, it exists somewhere in memory as a zombie, does all the things a live object is supposed to, and crashes your app since it is flagged to be deallocated but not really deallocated because of the one extra retain.

This is just as obvious as a flying flag. I would highly discourage you if you are doing it.

2. An IBOutlet delegate of a nested view controller without being a property.

@interface PlainDelegateViewController : UIViewController
{
	IBOutlet id delegate;
}
@end

This is common for subviews and buttons. Simply because it does not send extra “retain” message to your subviews and buttons, you might have better chance of not leaking memory. When I connect the delegate to its parent view controller in IB, however, this does not go in the way I believe. This yields exactly the same result as a retain property does. This is really confusing so I browse through object-c documents but no use. If anyone could point me a right point to look, I would really appreciate.

3. An assign property in interface of a nested view controller.

@interface AssignDelegateViewController : UIViewController
@property (nonatomic, assign) IBOutlet id delegate;
@end

This clears all the issues I have with previous two, and deallocate the parent view controller as soon as it pops off navigation controller.

TL;DR
When you are to refer your parent view controller from a nested view controller, always use assign property. You can download IBDelegateRetainTest from Github to see how different the outcomes are.

IBDelegateRetainTest

*There are three view controllers. When they are popped from navigation controller, they are supposed to be deallocated. Take a look at console log and find out which one gets really deallocated. ;)

Two more doggies

Two more dogs to go.

First one is “Bouncer”
He’s bulky, hyped-up, and blocks you from going forward. Be aware of him!

Last one is “Boink”. He’s extra sensitive and has a special ability to track you down. When you see him on stage, steer clear of him!

Now all four evil dog designs are drafted, and they will be reiterated for color, skin pattern, and minor details. One of challenges for making good iPhone game is to, I think, deliver properly formatted graphic assets for small screen; small details get lost, lines and major features stand out, light plays big role there too. I don’t really think that I can make solid assets with just one stroke. I might need to go over few more time until I ‘get it’ and using vector oriented graphics such as Adobe Illustrator, Inkscape, or even Blender could help very much in doing so.

I will make another post about how to render your still image properly next time.