Jun 17, 2010
We all know by now that Adobe is almost as evil as …, well let’s say they pioneered a couple of functionalities that where great for the longest time. One being the PDF format which is actually totally built into OSX everywhere. On OSX you’re able to print into a PDF without having to install extra software. Also iOS comes with PDF support and today we’ll look at how we can draw a PDF in a view.
How UIWebView sees it
The first idea you might have is to use UIWebView to display PDFs which is not difficult, just get the URL, make a NSURLRequest and pass this to a web view.
_webView = [[UIWebView alloc] initWithFrame:frame];
_webView.delegate = self;
_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
// we don't want interaction, full size
_webView.scalesPageToFit = YES;
_webView.userInteractionEnabled = NO;
_webView.backgroundColor = [UIColor whiteColor];
//fileURL is an NSURL to a PDF file
[_webView loadRequest:[NSURLRequest requestWithURL:fileURL]];
But there is one drawback: you cannot really control how it will arrive on screen. For one thing, UIWebView draws a fat gray border and shadow which might somewhat mess up your UI design.
Wouldn’t it be great if you could draw the PDF somehow into a view? Yes, we can!
Jun 04, 2010
I started out with a simple project of mine, the demo I made for DTNotepadViewController. This is a navigation stack which has a UITableView. From there you can select an entry to get a detail view looking like note paper.
The goal is to convert this iPhone-only app into a hybrid app that uses a split view on iPad.
May 25, 2010
Back in April Oliver wrote an excellent article entitled “Making Your Own iPhone Frameworks”, in which he explained how to do what many developers still proclaim as impossible: how to create custom frameworks that you can use in your iPhone apps! I would recommend that you read Oliver’s article first, especially if you’re wondering what a framework is… or, possibly, why you should consider making your own frameworks. I wont talk about that here :).
To build frameworks Oliver wrote a simple shell script that first creates a typical framework bundle, and then copies resources into the appropriate directories. In this followup article, I’ll show you how to create the framework bundle entirely within Xcode, without any scripts, plugins, product-, or package-types. While this has a few advantages, I’m not claiming that my approach is in any way perfect, and there may be problems that I haven’t encountered yet. As always, this is a work in progress, so if you have any suggestions, please feel free to leave your comments below.
Enough talking. Lets get started –
May 25, 2010
Once a year you are required to refresh your two certificates and all provisioning profiles that use these. Mine had expired and so I made a screen capture to show you how painless the renewal process can be. At the same time it also shows newcomers how to best set up their stuff on the provisioning portal.
Hint: if you find that the Submit button is not working, you can also go into the provisioning profile name field and hit Enter.
For regular development work it’s generally sufficient to have only 3 provisioning profiles:
- “Development” – uses your “iPhone Developer” certificate, a * wildcard app identifier and all your development devices
- “AdHoc” – uses your “iPhone Distribution” certificate, a * wildcard app identifier and all devices you want to do ad-hoc builds for
- “AppStore” – uses your “iPhone Distribution” certificate, and if you don’t do IAP or Push Notifications you can use a wildcard app identifier as well
You don’t need to create a new app identifier on the portal for each new app that you begin. You only ever need unique app identifiers if you publish an app capable of InAppPurchases or Push Notifications.You can change the app identifier with every upload to Apple, contrary to the bundle identifier in the info.plist which has to stay the same for the app to be accepted as an update. New bundle identifier means new app.
Once you have gone through the steps shown in the video you are good to go for another year, until the certificates expire once more.
May 21, 2010
I’m coming out of highly concentrated work (approx 87 hours) on my latest project. It’s an app that allows you to organize a betting pool for the upcoming FIFA World Cup.
The simplest method of communicating with our web-based API we found to be having the server send array or dictionary PLISTs which I could load and parse in a single line of code synchronously. So first I created all the API calls in synchronous blocking mode. When they where working I added a method by the same name prefixed with “async” and would have the blocking code executed on an NSOperationQueue.
If the synchronous method needed zero or one parameter then you can use NSInvocationOperation of calling it and have the queue work it off in the background. In some cases more than one parameter has to be passed. Here an NSInvocation has to constructed with multiple parameters, which I explained previously.
Once the API call is done processing it needs to tell the app about its result. This is done conveniently by sending NSNotifications. And in all the places in the UI where specific notifications should have an effect, you simply subscribe to the notifications by adding an observer for them to the default NSNotificationCenter. NSOperationQueue automatically uses multiple threads and takes care of the autorelease pool. So any operation might either run on the main thread or on a background thread.
Warning: Crash Ahead!
This causes a problem I have only ever seen happen on Simulator, so I’m not sure if it would also happen on the device. Generally you want the NSNotifications to be sent on the main thread as well, especially if they trigger UI activities like dismissing a modal login dialog. I don’t know if Apple will tweak NSNotificationCenter to send on the main thread in the future, but until they do, here’s my drop in solution.
May 08, 2010
Andreas Heller asks:
When parsing an RSS feed I get a date from pubDate, but as NSString and not NSDate. How do I get a date that I can use for sorting?
That’s a problem you face quite often when dealing with dates which are encoded in XML, be it an RSS feed or any other XML-based file format that you would be getting via HTTP GET. Contrary to other languages where any properly formatted date can be automatically parsed we have to do this ourselves in Cocoa.
Fortunately there is the NSDateFormatter class which can do it both ways: from date to nicely-formatted string as well as the other way around.
Let’s do like a Unix-pro and get ourselves some test data by getting some pubDates from my RSS feed. In terminal type:
curl www.drobnik.com/touch/feed/ | grep pubDate
This gets us the pubDates from the 10 latest articles on my blog. We see that WordPress encodes the pubDates in this format “Mon, 03 May 2010 18:54:26 +0000”, not really a very easy to parse one I concede. According to the RSS 2.0 spec this is supposed to be in RFC822 standard. If anyone would ask me, personally I think that the inventor of this date format should be poisoned, then hanged and maybe shot for good measure. Who in his right mind would create a date representation that does not allow for string sorting?
May 06, 2010
Objective-C has several powerful methods of working “Meta”. Besides of handling methods and objects themselves you can also save a method’s signature in a variable, and call it later. That’s a “selector”. Or you could construct an object representing the entire call of a method, including one or multiple parameters and then use this object in place of the actual call.
Why would one do such a complicated thing? Well, there are several pretty useful scenarios where it is useful to know this technique. The main benefit of this method is that you can construct method calls during runtime using information that you only get while your app is running.
May 03, 2010
Personally I was most at the edge of my seat at the “Voices that Matters Conference” in Seattle when Rod Strougo showed us how to make a physics-enabled game with Cocos2D and Box2D in under an hour. It really was as sexy as he sounds. Eros did what every good TV-cook would do, he had most things already prepared. On the flight home I wanted to see if I could just take the physics part (without Cocos2D) and make a UIKit app with it.
The goal of this experiment was to have a UIView with multiple square subviews of different sizes that would start falling as soon as the app starts. The first tricky part is how to add the latest version of the Box2D physics engine to your iPhone project. Then we need to mediate between the different units and coordinate systems of UIKit and Box2D. Finally when we got it all running, we also want to add the current gravity vector to affect the boxes.
Apr 16, 2010
Previously I explained how to make a static library that simultaneously supports multiple different CPUs. At that time I was ignorant to the reason why there are no means to make iPhone frameworks. But I did not give up searching, especially since apparently a few individuals seemed to have pulled it off without properly documenting their method for others to duplicate.
The only guide I found is from two years ago, but I was able to verify that it works and so I will document it in an article so that many more people can use this great mechanism. But first, let’s briefly explore what it really IS that Apple does not want us to do. The generic statement that you can read on thousands of pages is “Apple does not want you to make iPhone frameworks”.
But is that really so? It turns out, this statement is not entirely accurate or rather specific enough to be the truth.