Posts Tagged 'Programming'

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: http://www.libnui.net

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 →
6

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:

slidingsections

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 →
0

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.

#if HEARTBEAT_CHECK_PIRACY
+ (BOOL)isCracked {
#if TARGET_IPHONE_SIMULATOR
        return NO;
#else
        static BOOL isCracked = NO;
        static BOOL didCheck = NO;
        if(didCheck) return isCracked;
#if HEARTBEAT_PIRACY_THRESHOLD >= 1
if([[[NSBundle mainBundle] infoDictionary] objectForKey:@"SignerIdentity"] != nil) {
#if HEARTBEAT_PIRACY_THRESHOLD >= 2
NSString* infoPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
if([[NSString stringWithContentsOfFile:infoPath encoding:NSUTF8StringEncoding error:NULL] rangeOfString:@"</plist>"].location != NSNotFound) {
#if HEARTBEAT_PIRACY_THRESHOLD >= 3
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]) {
#endif
#endif
isCracked = YES;
#if HEARTBEAT_PIRACY_THRESHOLD >= 2
#if HEARTBEAT_PIRACY_THRESHOLD >= 3
}
#endif
}
#endif
}
#endif
didCheck = YES;
return isCracked;
#endif
}
#endif

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 →
0

KVC Key Paths

If you just haven’t gotten around yet to sorting out what this funky KVC stuff in Objective-C is all about, here’s a good article explaining just how helpful — insanely helpful, to quote a phrase — they can be.

How would you use this in the real world? What if you had a shockingly descriptive object model of your friends and you wanted to find all of your friends who had a dad named “Bob”. No problem with key paths! Just throw in this NSArray category and you are set!

@implementation NSArray (Find)
- (NSArray *)findAllWhereKeyPath:(NSString *)keyPath equals:(id)value {
NSMutableArray *matches = [NSMutableArray array];
for (id object in self) {
id objectValue = [object valueForKeyPath:keyPath];
if ([objectValue isEqual:value] || objectValue == value) [matches addObject:object];
}
return matches;
}
@end// Implementation example NSArray *friendsWithDadsNamedBob = [friends findAllWhereKeyPath:@"father.name" equals:@"Bob"]

Yep, that is mildly nifty, isn’t it? But here’s the seriously nifty stuff that we’d managed to overlook so far:

But that’s not all! key paths have magic keywords you can throw in like sum, distinctUnionOfObjects and avg.

NSArray *animals = [NSArray arrayWithObjects:@"pig",
@"dog",
@"human",
@"bear",
@"frog",
nil];
NSLog(@"Sum: %@", [animals valueForKeyPath:@"@sum.length"]);
NSLog(@"Avg: %@", [animals valueForKeyPath:@"@avg.length"]);
// Sum: 19
// Avg: 3.8

Didn’t know just how nifty this KVC stuff can be, didja?

h/t: iPhoneKicks!

UPDATES:

Objective-C Collection Operators

Continue Reading →
0

Code: Image Processing

Here’s a good project on Google Code to bookmark in case you ever need to do any image processing tasks with UIImage:

I’ve written a simple C++ class with an Objective-C wrapper that provides a set of common image processing tasks along with conversion to and from UIImage.

The code supports the following operations:

Beats writing all that of scratch, indeed!

h/t: iPhone Development!

Continue Reading →
0

Source: SC68 Player

Here’s another nifty open source project for you to mine for code tips: the SC68 Player!

SC68 Player allows you to browse and play songs from the Atari ST SNDH YM2149 Archive on your iPhone or iPod Touch.The Atari ST music archive consists of old “chip”-music from games, and the Atari ST demo-scene that are in the public domain. A song is generally less than 10k and there is currently over 3000 songs available.

This is from the same fellow who did the sorted insert NSArray code we mentioned a couple days back, and there’s all sorts more interesting stuff in here. You particularly have to take a look at his awesome “VisualMoveQue” cell selection animation. It’s worth downloading the app just to check that out, even if you’re not into Atari ST music. Seriously.

SC68 Player

And once you’re impressed enough to think hey we are so doing something like that in our apps — download the code here and dig away in ‘UIWindow+VisualMoveQue.m’ to figure out just how he’s doing that neat trick!

Continue Reading →
1

3D Engine Roundup

Here’s a well worth your time to read up-to-date roundup of 3D engines for your iPhone development pleasure. To skip details, the two that came out on top by this fellow’s requirements we’ve mentioned before:

  • SIO2 Interactive, SIO2: An opensource (LGPL) game engine for the iPhone. It uses the Bullet physics library and 3D objects and scenes are prepared using the opensource tool Blender. The project offers many tutorials (16) some of which are screencasts. The project also boasts a healthy number (15) of deployed iPhone applications available in the AppStore. The engine has a free version that imposes a flash screen (advertisement for the engine), an indie version is available without this restriction for $50USD. The volume of developer documentation in the form of tutorials is great, although the seeming dependence on Blender to prepare the 3D models and scenes used by the engine may be a deal breaker if there is no programmatic workaround.
  • Oolong Game Engine (on google code): An opensource (MIT License) game engine for the iPhone with some credibility given that it was developed in large part by Wolfgang Engel, Rockstar Games‘ lead graphics programmer. It uses the Bullet Physics Library for 3D physics and fluid studios for memory management. It has seemingly been used in a small number of titles (3?) currently available in the AppStore and proposes that it was used as the basis for the iTorque Game Builder. The source code comes with a number of demonstrations, although developer support documentation and tutorials are really lacking, and the mailing list is quite empty. This might be an engine for hard core developers.

… but there’s a bunch of others listed which we had not previously been aware of. In particular, the Ston3D engine looks like a worthy alternative to Torque and Unity. If the commercial engine thing is your gig. Personally, we’re more along the mindset of this Jason fellow, so we’re definitely going to follow his experiences with the engines of choice!

Continue Reading →
2

Sorting NSArray

Here’s an excellent article on how to do optimized NSArray sorting and NSMutable Array sorted inserts.

NSArray admits to sorts being a slow operation, and adds a method pair for comultive sorts using hints. This way the operation is done inO(P*LOG(P)+N) time, instead of O(N*LOG(N)). Where N is number of elements, and P is number of additions and deletions since the last sort. Unfortunately that do not work on NSMutableArray. So even if memory consumption will not hit the roof, release retain cycles will take it’s toll.

So why not add methods to find the insertion points, and insert new objects into already sorted NSArray and NSMutableArray object? Best case for inserting single elements should be O(LOG(N)^2), so lets hit that target. And on the way there, we will learn how to;

  • Add functionality to standard classes using categories.
  • Implement high performant Obj-C code for tight loops.

Good stuff, indeed. Here’s the code; take a look if you do Cocoa programming on either the desktop or iPhone!

h/t: LinkedIn’s Cocoa Touch!

Continue Reading →
1

Advertising & Analytics

So you’ve probably at least pondered putting some advertising and/or analytics into your application releases, and here’s a roundup of the most popular products for that:

For Revenue:

  • Medialets : Insert ads into your application using easy to drop in Objects, also track your users interaction with your application, earn a CPM.
  • AdMob : Offers ads for your iPhone using Javascript” code. AdMob has been around for a while and has publisher solutions for mobile phones, not just iPhone applications.
  • PinchMedia : Offers ads and analytics for your iPhone application, exclusively for iPhone applications.
  • [EDIT: You knew it was coming ... Google AdSense for Mobile Applications Beta!
  • [EDIT: And here's yet another ... Greystripe!]
  • [EDIT: Oh look, they just keep coming ... Smaato!]
  • [EDIT: Quattro! VideoEgg! Millennial Media! JumpTap! MdotM! They're everywhere! EVERYWHERE, I tell you!]

Mediation layers:

For Ad Swapping:

  • PurpleTalk : PurpleTalk allows you to join an advertising exchange with other iPhone developers. You earn advertising views of an advertisement for your application when you advertise others. You do not make money with these ads however it is a free way to increase the adoption of your own application.
  • [EDIT: Social Gaming Network has an exchange program now!]
  • [EDIT: And Admob has AdMob Download Exchange!]
  • [EDIT: And some indies started their own little App Treasures exchange club!]
  • [EDIT: Flurry is beta-ing Flurry AppCircle™!]
  • [EDIT: How about Chartboost?]

For Analytics:

  • PinchMedia : Offers analytics for your iPhone application, exclusively for iPhone applications.

And as time goes on, there’s an ever expanding cornucopia of choices in the analytics category:

POSTSCRIPT:

And don’t miss reading this white paper from Skyhook Wireless about all monetization strategies, not just ad serving!

Continue Reading →
10

Ad Hoc icon

Isn’t it annoying when you do your Ad Hoc distributions that your pretty application icon doesn’t show up in iTunes? Well, here’s the trick — fake yourself a folder that looks like an iTunes distribution:

iPhone developer Malcolm Hall explained how he sets up his Ad Hoc applications so they’ll display the proper image. He creates a folder in which he places two items: the first is a JPEG image called iTunesArtwork, the second is a folder called Payload. He adds the app bundle (Whatever.app) into the Payload subfolder, zips up the entire thing and renames the zip file toAppname.ipa.

This ipa package (ipa stands for iPhone application) mimics the way that Apple provides applications for iTunes. When iTunes sees the iTunesArtwork file, it uses it to create the image seen in the Applications library.

The iTunesArtwork file should be added without an explicit extension. Hall suggests you use Get Info (Command-I) and remove the file extension before zipping it up. (You can also remove the extension at the command line.) Use a 512×512 image for the art.

Which describes the layout

- yourapp.ipa (zip renamed to ipa for iPhone Application)
        - iTunesArtwork (512x512 JPEG with no extension)
        - Payload (Folder)
                - yourapp.app (as produced by Xcode)

There you go. Now you can look properly professional with your Ad Hoc distributions! And it’s all about the looks, isn’t it now?

Continue Reading →
0
Page 74 of 82 «...5060707273747576...»