Archive for the ‘iPhone’ Category

Extend UIWebView to handle all special links

Thursday, October 29th, 2009 Share on Twitter

Have you ever wanted to add an UIWebView to your application, so you can browse the internets without leaving your application? While it is a trivial task to add an UIWebView to a project, there are some links that an UIWebView will not handle. These are: mailto YouTube maps.google.com iTunes AppStore I've written a generic BrowserViewController, code ...

Designing an iPhone Application: tools round up

Thursday, September 24th, 2009 Share on Twitter

There are different schools on how to start the design of an iPhone app. Some will prefer designing on paper (I do), others will use the computer to design their next breath-taking GUI. So here is a list of some of the tools, template to design your next iPhone application. Templates: Keynote '09: ...

Arbitrary rotation of a CGImage

Friday, September 4th, 2009 Share on Twitter

For my current project, I have to rotate a CGImageRef by an arbitrary angle. Here is the code: - (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle { CGFloat angleInRadians = angle * (M_PI / 180); CGFloat width = CGImageGetWidth(imgRef); CGFloat height = CGImageGetHeight(imgRef); CGRect imgRect = CGRectMake(0, 0, width, height); ...

Apple Push Notification Service Gateways

Friday, August 7th, 2009 Share on Twitter

I've not yet had the request to implement Push in an iPhone app, but a thread on the Developer Forums gave me a hint: Some companies are already providing (or planning to provide) a gateway to the APN: These are: Urban Airship iLime AppNotify These are in closed beta: Push.io iPushServer.com msgpush Urban Airship and iLime also provide In App ...

Increase the responsiveness of your UITableViews

Monday, May 4th, 2009 Share on Twitter

Let's say you have an UITableView in which rows, when touched, changes the display to another view with an animation. If you touch quickly a row, the row will highlight just before the animation starts. If the action performed when touching the row takes some time (let's say more than 0.5 seconds), ...

Relative date to now

Friday, February 20th, 2009 Share on Twitter

In my current project, I needed to know if a given NSDate was today, yesterday or earlier. Simple task, I thought. Until I looked at the documentation for NSCalendar, NSDateComponents and NSDate. While these are extremely powerful, I am not proud of the code I've written. It should be easier. Anyway, ...

Reading the battery level programmatically

Saturday, February 14th, 2009 Share on Twitter

A beta-tester was complaining the application was draining its battery. To check if this was really the case, I needed to get the battery level with a better accuracy than just looking at the battery icon. So I used this little routine to check. This routine is adapted from a post ...

Redirect NSLog to a file on the iPhone

Friday, January 9th, 2009 Share on Twitter

If you need to debug your app when disconnected from your Mac (and from the console), redirect all your NSLog calls to a file so you can later read it. The method below will create a file name "console.log" in the Documents folder of your application so you can later read ...

Macros for Xcode

Monday, January 5th, 2009 Share on Twitter

These are some of the macros I use with Xcode: CMLog: I use this macro to replace NSLog: #define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]); When you use this macro, it outputs text to the console, including the class and method from where it was called. So, if you call this macro ...

HowTo fit text inside a UIWebView

Monday, January 5th, 2009 Share on Twitter

If, like me, you want to make sure your text will fit inside your UIWebView (without scrolling), you can implement the following javascript: <script language='javascript' type="text/javascript"> function adjustHeight(maxHeight) { elem = document.getElementById("sign"); height = ...