Under the Bridge

Snippet: Intercepting Touches

Ever wanted to intercept touches on a view that generally eats them, like MKMapView for instance?

I’d like to allow my user to double-tap the map view to place an annotation marker, rather than the default zoom behaviour. What’s the preferred method of having my program intercept touch events, then either passing them along (single-touch) or not (double-tap)?

Well, here’s a question on Stack Overflow that answers that for MKMapView and probably UIWebView as well: create a wrapper view that intercepts the various touch events, then place the functional view inside it, like this:

#import <MapKit/MapKit.h>
- (void)applicationDidFinishLaunching:(UIApplication *)application {

//We create a view wich will catch Events as they occured and Log them in the Console
viewTouch = [[UIViewTouch alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

//Next we create the MKMapView object, which will be added as a subview of viewTouch
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[viewTouch addSubview:mapView];

//And we display everything!
[window addSubview:viewTouch];
[window makeKeyAndVisible];
}

Colophon:

Second day of The Great WordPress Client Test, and today we’re checking out

ecto256.png

ecto 3.0!

Now this acts much more like a Mac program should. Interface is intuitive, category/tag/image composition beats Blogo all hollow, we like that ‘Amazon Helper’ plugin idea, … but there’s some quibbles here too:

  • The Preview window is resolutely blank. Blogo, now, it did a nice job of downloading all the appropriate templates from the blog. On the other hand, ecto actually uploaded it as expected and didn’t muck up the categories or lose text and so on … so we don’t count that as a major flaw.
  • Doesn’t seem to be a way to blockquote selected text, you have to click into blockquote mode then paste apparently. Not a dealbreaker I suppose, but I do rather like the online editor’s behavior that blockquotes the paragraph containing the insertion point.
  • It doesn’t maintain the Undo stack between HTML/text view changes either, even if you don’t actually do anything but switch between the two views.
  • Whilst in general the HTML creation and paste handling is excellent, and it’s a brilliant feature to actually force the HTML to be correct before leaving the HTML editor and offer to fix it for you like ecto does … in the particular circumstance where we’d like to paste source code in and slap <pre> tags around it, this feature actually gets in your way as it insists on making every line a new paragraph, which is not what we want as it loses the indentation. Perchance there’s a way around this, but it’s not immediately obvious.
  • The initial publish disallowed trackbacks/pingbacks. Presumably that’s a trivial setting fix somewhere, but allowing them really should be the default we think…

So yeah, we like this ecto thing overall, we’ll give it a solid eight from first impressions. Definitely worth an indepth evaluation probably … but we’ll see if we’re completely starstruck by any of the remaining five!

Continue Reading →
1

Game Design

And something a little different for you today: Whilst digging around Gamasutra for stuff interesting to iPhone developers, we stumbled across this article dissecting a variety of CPRGs. If you’re at all interested in designing a CRPG at some point — and we do feel the iPhone has not been overly well served in that realm to date — this is an interesting read.

[In the latest in his popular Game Design Essentials series, which has previously spanned subjects from Atari games through ‘mysterious games’‘open world games’‘unusual control schemes’ and ‘difficult games’, writer John Harris examines 10 games from the Western computer RPG (CRPG) tradition and 10 from the Japanese console RPG (JRPG) tradition, to figure out what exactly makes them tick — and why you should care.]

Those other articles in the series all look quite interesting as well!

Continue Reading →
0

Code: Plausible Blocks

So you’re all pumped up about this deft-sounding “Block” (aka Closure) concept that Grand Central Dispatch is going to bring to us in Snow Leopard … but it’s not out yet, and Snow Leopard does not run on the iPhone! So what do you do?

Well, if you’re really excited, you … implement it yourself.

If you caught the sessions on blocks at WWDC, you may be as excited as
I am to make use of them. Unfortunately, they’re only available for
Snow Leopard.

As a result, I decided to back-port block support to iPhoneOS 3.0 and
Mac OS X 10.5…

Dude. That’s hardcore. Here’s the announcement of Plausible Blocks; project page on Google Code; and a tutorial demonstrating its use with NSOperationQueue and UIActionSheet with sample code on github. Enjoy!

UPDATE — More good posts on blocks:

Using Blocks: Understanding the Memory Management Rules

Blocks, Episode 1

Blocks, Episode 2: Life Cycles

UPDATE 2 — Recommendations from the 1.0 release announcement:

Joachim Bengtsson’s Programming with C Blocks

Mike Ash’s Series on Blocks, Part I

Mike Ash’s Series on Blocks, Part II

Landon Fuller’s Using Blocks 1 (as mentioned above)

Landon Fuller’s Using Blocks 2

Google Code Project FAQ

h/t: iPhoneSDK!

Continue Reading →
0

Library: ParseKit

Now here’s something pretty darn nifty: ParseKit, a super-duper set of goodies for both string tokenization

ParseKit provides general-purpose string tokenization services through thePKTokenizer and PKToken classes. Cocoa developers will be familiar with theNSScanner class provided by the Foundation Framework which provides a similar service. However, the PKTokenizer class is much easier to use for many common tokenization tasks, and offers powerful configuration options if the default tokenization behavior doesn’t match your needs…

and grammar-based language parsing. Neat.

ParseKit allows users to build parsers for custom languages from a declarative, BNF-style grammar without writing any code (well, ok.. a single line of code). Under the hood, grammar support is implemented using the ParseKit Objective-C API, so the grammar syntax closely mirrors the features of the Objective-C API…

Cool, huh? This is an Objective-C implementation of the tools described in Building Parsers With Java apparently, and runs on Leopard and iPhone of course; check out the Google Code project page for code and more documentation!

Continue Reading →
1

Tutorial: UIPasteboard

Yet another not quite as thorough but still worth a gander 3.0 tutorial over on Mobile Orchard today, Copy & Paste With UIPasteboard:

There are two system pasteboards: a General system-wide pasteboard that’s used for copy-paste operations and a Find pasteboard that holds the last search string.

Additionally, applications can create their own pasteboards that can be used by other apps. For example, a point-of-sales app and a credit card terminal app could use a shared pasteboard to pass payment details back and forth…

Fairly straightforward stuff, especially if you’ve delved into NSPasteboard on the desktop … but since we actually never had any particular reason to do so all that deeply, it was still a worthwhile read!

Continue Reading →
1

Code: BWToolkit

Here’s a nifty-looking resource for your desktop Cocoa development: BWToolkit! A wide selection of handy-dandy classes for jazzing up and speeding along your interface work — and get this, they come with their own Interface Builder plugin to boot:

BWToolkit is a BSD licensed plugin for Interface Builder 3 that contains commonly used UI elements and other useful objects. Using these objects is as simple as dragging them from the library to your canvas or document window.

When I first heard about the plugin architecture in IB 3, I saw a huge potential for improving the developer user experience and lowering the barrier to entry for developers who are new to Cocoa. I hope to have accomplished that with this plugin…

Yes, the various goodies described in the links would be nifty enough on their own — and the latest version is right up to date with Snow Leopard, no less — but we’re quite looking forward to adding our own collection of custom views and the like to Interface Builder … just as soon as we have some spare time. *laugh* *sob* *whimper*. Well, anyways, in the meantime, grab the source from bitbucket and check it out for yourself!

Continue Reading →
1

Library: CocoaREST

Here’s a library that may be of interest if you’ve got a use for RESTful services in your iPhone or desktop app: CocoaREST, a generalized superset/replacement for libraries such as MGTwitterEngine:

Recently I created a set of Cocoa classes that let developers interact with internet services such as Twitter, Facebook, Friendfeed, etc. The initial intent was simply to support Twitter, but as the classes became more generalized, the possibilities grew exponentially…

My library is written so you won’t need to look at my headers more than once (if that). This is the developer’s workflow I envisioned when I began writing the API:

  • Create a task of a certain service (ie, SDTwitterTask)
  • Set the task’s type appropriately
  • Navigate to the service’s API page for that task (let’s use mentions as an example)
  • Read that page and note all optional and required parameters
  • Set any properties (ivars) on the task that you would like to have passed to the API
  • Run the task and await results (or an error)

As you can see, it’s almost completely transparent. That’s the goal, no intermediate complexity, just a simple gateway to a website’s API.

Sounds promising, yes? Introduction to be found here; source and instructions to be found at github; and check out the author’s other open source projects as well!

h/t: cocoa-dev!

Continue Reading →
1

Tutorial: Migrating Data

Here’s another good tutorial at MobileOrchard — my, they are on a run lately, aren’t they? — Lite To Paid iPhone Application Data Migrations With Custom URL Handlers.

Apple enforces a number of restrictions on applications in the App Store. Among the most painful is the lack of feature-limited trials. Applications are either completely free, or the customer must pay up front, sight unseen. The proliferation of “Lite” applications is a direct result of this shortcoming…

When building a game or other stateless application the approach makes complete sense. However, utility applications often maintain information entered by the device owner. Application authors are faced with a dilemma because the iPhone’s security sandbox prevents one application from reading another application’s files. Thus, when customers upgrade from the Lite application they are penalized by having to re-enter all data!

This is rather apropos, as we’ve been already planning something along these lines for migrating data from paid for 2.0 applications to new StoreKit-using 3.o applications, which is more or less the same basic problem as the Lite-to-Pro style migration they have in mind.

The tutorial goes on into exhaustive detail, but the basic idea is to use URL handlers for IPC between your application versions as we’ve mentioned earlier. We do have one additional tip to add though; they focus on using solely the URL itself to transfer data, which there’s a good chance to be problems with using for data in the dozens of megabytes like we need to do. Luckily, we have another earlier post of ours to point you at what looks like a fruitful avenue of inquiry; figure out where UIImagePickerController writes its photographs, which it seems is and is likely to continue to be necessarily a shared access folder, and stick your large temporary data in there. We’ll let you know how that works out once we’ve tried it!

Continue Reading →
15
Page 91 of 119 «...6070808990919293...»