Archive for 'iPhone'

Code: Google Docs

Now here’s an interesting idea: Use Google Docs to provide free data sharing in your iPhone app.

In September, my small software company shipped our first iPhone app, a grocery list program called Grocophile. One of the most common requests from our users was the ability to exchange data over the Internet. Greg Robbins of Google’s Mac team suggested that the Google Docs API might be useful, so I jumped in and took a look.

This turned out to be a great way to give our users access to free Internet storage, letting them back up their data and share it across multiple devices…

…  If your app can store and retrieve its data in text, HTML or a spreadsheet, then Google Docs will work well for you. 

That does cover a wide variety of data, indeed. There’s source code here to check out if this sounds like something you’d want to look into!

h/t: iPhoneKicks!

Continue Reading →

Snippet: Building mailtos

Ever got some strange results trying to send emails on the iPhone? Yeah, us too. Here’s a workaround that may help — use the Core Foundation utilities instead of using NSString for everything:

This simple approach ensures that your full message will arrive properly at the iPhone mail program after you have your application open the merged URL. Escaping the html body text ensures that mailto: specific characters will not confuse the URL handler and that your e-mail will be built with the proper headers and body.

NSString *htmlBody = @"you probably want something HTML-y here";  
// First escape the body using a CF call  
NSString *escapedBody = [(NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)htmlBody, NULL,  CFSTR("?=&+"), kCFStringEncodingUTF8) autorelease];

// Then escape the prefix using the NSString method  
NSString *mailtoPrefix = [@"mailto:?subject=Some Subject&body=" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
// Finally, combine to create the fully escaped URL string  
NSString *mailtoStr = [mailtoPrefix stringByAppendingString:escapedBody];  

// And let the application open the merged URL  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailtoStr]];

Now you know!

Continue Reading →

Code: mySettings

Here’s a possibly useful post on constructing a UI by use of a plist:

A lot of iPhone apps have their own settings views similar to the ones in the Settings App on the iPhone home screen. But to my surprise I couldn’t find any general API for it. So I made my own and published it here. It uses a plist configuration file like the one used by the Settings App, with some added options (and some removed ones, but they will hopefully be implemented in the near future).

Particularly if you’d like to recreate your layout inside the application — which is a good idea, as apparently no actual user anywhere has ever found it intuitive that’s where settings are theoretically supposed to be — that would be useful indeed. But we’re looking at it for some other configurable UI as well here … we’ll update here if we have any useful opinions after examining the code more closely!

[EDIT: And check out the very pretty look that the new delegate support enables!]

h/t: iPhoneKicks!

Continue Reading →

Snippet: Pie Chart

So, you ever needed to do a pretty pie chart like this on the iPhone?


Well, no, us neither actually. But if we did, we would certainly start with the handy snippet here rather than go poring through the Quartz documentation…

Continue Reading →

Source: Mover

Now here’s a neat little application called Mover for swiping stuff between iPhones. Yes, swiping. Really.

Mover is a fun way to move images and contacts between iPhones and iPod touches. Put what you want to send on the table and whee!, swipe it where you want it to be.

Check out the link for the video. Wondering just how to do that kind of thing in your own app? Well, the source is here on github, grab it and check it out. (Note the auxiliary repositories also needed, mentioned under “Mover” at the bottom.) Nifty what you can do with a little Bonjoury goodness, isn’t it?

h/t: iphonesdk!

Continue Reading →

Library: FeedParser

Here’s a new option to look into for your RSS parsing coding needs, particularly if you want to share a desktop and iPhone code base:

FeedParser, a brand new NSXMLParser-based RSS parser for Cocoa, has been released as an open source project on GitHub. The goal of this project is to provide an extensible RSS/Atom parser that works on both the iPhone andthe desktop. To that end, it is based on NSXMLParser instead of NSXMLDocument. I recognize that PubSub is available for the desktop, but FeedParser was designed primarily with the iPhone in mind.
In its current incarnation, FeedParser understands all of RSS 2.0 (although it does not expose all of the possible fields). It has also been verified to correctly parse sample RSs 0.91 and RSS 0.92 feeds. It has minimal support for Atom (to the extent that it understands <atom:link> elements embedded in RSS feeds), but the architecture is such that Atom support can be added over time. It also has support for RSS extensions such as DublinCore…

Code is on github and MIT-licensed.

h/t: cocoa-dev!

Continue Reading →

Framework: NUI

And now for something … ok, not completely different, but largely different: a cross-platform application framework for the iPhone, OS X, Win32, and Linux. No, seriously.

We are happy to announce the release of NUI:

NUI is a C++ application framework that runs on the iPhone, MacOSX (universal), Win32 and Linux.
Its main distinctive features is its use of 3D hardware to render the UI via OpenGL, GL Es and Direct3D.

Its features include:
- Low level abstraction: string, files, paths, streams, network, timers, threads, mutexes, etc.
- Widget layout engine
- Really many widgets: text, grids, boxes, collumn views, tree views, etc.
- Integrated widget tree visual introspection/debugging
- Web-like CSS engine
- Modern rendering and compositing engine
- Animations for widgets and their attributes
- Attributes to remote control widgets
- Audio IO and Audio file loading/saving (including compressed audio files decoding)
- Stable and proven lib: many applications have been released since 2001 with NUI at their core.

Intriguing, no? In general we’re solid advocates of the OS specific front end approach, which has a way of turning out much better than attempting to share code if you use decent MVC design, but if you do have the kind of application that lends itself to an OpenGL interface, this could be an interesting option indeed.

h/t: mac-opengl!

Continue Reading →

Snippet: Rounded Images

And today, an answer to the classic question

Anybody know how make image and first cell in grouped table be rounded? Like iTunes album image. 

which is:


static void addRoundedRectToPath(CGContextRef context, 
   CGRect rect, 
   float ovalWidth, 
   float ovalHeight, 
   int i
   float fw, fh; 
   if (ovalWidth == 0 || ovalHeight == 0) { 
       CGContextAddRect(context, rect); 
   CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect)); 
   CGContextScaleCTM(context, ovalWidth, ovalHeight); 
   fw = CGRectGetWidth(rect) / ovalWidth; 
   fh = CGRectGetHeight(rect) / ovalHeight;
   CGContextMoveToPoint(context, fw, fh/2);  // Start at lower right corner 
#pragma mark change the corner size below... 
   if (1 == i) { 
        CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 0);  // Top right corner 
        CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 0); // Top left corner 
        CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner 
        CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 0); // Back to lower right             
   } else { 
        CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 0);  // Top right corner 
        CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner 
        CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 0); // Lower left corner 
        CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 0); // Back to lower right             

+ (id)createSingleRoundedCornerImage:(UIImage*)image size:(CGSize)size { 
   // the size of CGContextRef 
   int w = size.width; 
   int h = size.height; 
   CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
   CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst); 
   CGRect rect = CGRectMake(0, 0, w, h);
   addRoundedRectToPath(context, rect, 10, 10, 0); 
   CGContextDrawImage(context, CGRectMake(0, 0, w, h), image.CGImage); 
   CGImageRef imageMasked = CGBitmapContextCreateImage(context); 
   image = [UIImage imageWithCGImage:imageMasked]; 
   return image;


 Now you know!

Continue Reading →

Code: Sliding UITextField

Having trouble with your UITextViews getting stuck under the keyboard? Here’s an elegant approach:

The iPhone’s onscreen keyboard occupies the bottom 216 pixels on screen (140 in landscape mode). That’s around half the screen, so if you ever have a text field you want to edit in the bottom half of the screen, it needs to move or it will get covered.

You can just animate the whole window upwards by the height of the keyboard when editing a text field in the bottom half but this doesn’t work well for text fields in the middle (they can get moved too far up).

Instead, I’m going to show you a method which divides the window as follows:


Everything in the top section will stay still when edited. Everything in the middle section will animate upwards by a fraction of the keyboard’s height (proportional to the field’s height within the middle section). Everything in the bottom section will animate upwards by the keyboard’s full height.

Much prettier than just jumping stuff around, indeed. And hey, it’s all about the pretty, isn’t it?

Continue Reading →

Snippet: isCracked

Whilst we quite firmly believe that every second you spend implementing copy protection instead of things that, you know, actually make people want to buy your application are a striking misallocation of development resources, life as a contract programmer means that you do what your customers want, and it seems to be an unfortunate general rule that people are much more interested in upping the challenge and therefore the attraction for people who aren’t going to buy the application anyway than they are in actually making the application more attractive to people who will pay.

But perhaps we are unduly cynical.

Any-how, should you find yourself in the position of being tasked with implementing copy protection on an iPhone application, our condolences, and here is a snippet which may be of use.

+ (BOOL)isCracked {
        return NO;
        static BOOL isCracked = NO;
        static BOOL didCheck = NO;
        if(didCheck) return isCracked;
if([[[NSBundle mainBundle] infoDictionary] objectForKey:@"SignerIdentity"] != nil) {
NSString* infoPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
if([[NSString stringWithContentsOfFile:infoPath encoding:NSUTF8StringEncoding error:NULL] rangeOfString:@"</plist>"].location != NSNotFound) {
NSDate* infoModifiedDate = [[[NSFileManager defaultManager] fileAttributesAtPath:infoPath traverseLink:YES] fileModificationDate];
NSDate* pkgInfoModifiedDate = [[[NSFileManager defaultManager] fileAttributesAtPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"PkgInfo"] traverseLink:YES] fileModificationDate];
if([infoModifiedDate timeIntervalSinceReferenceDate] > [pkgInfoModifiedDate timeIntervalSinceReferenceDate]) {
isCracked = YES;
didCheck = YES;
return isCracked;

We have no intention of bothering to actually implement it on our own initiative, so this isn’t a recommendation per se, but hey, it looks like it has a chance of working, so if you want something like that, there you go!

[EDIT: And here is a strategy for dealing with crack detection which has some smidgen of sensibility to it.]

Continue Reading →
Page 80 of 97 «...5060707879808182...»