Posts Tagged 'Programming'

Snippet: App Store Links

So, you ever wondered how to get your iPhone “Lite” app to trigger the App Store to load the full version’s page? And you didn’t stumble across QA1629? Well, here’s the quick notes version for you.

Step 1: Copy the URL of your full app from the App Store by right-clicking its name, which will be something like

http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=306469222&mt=8

Step 2: Replace “itunes” with “phobos”. This is so it doesn’t start Safari.

http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=306469222&mt=8

Step 3: Have the system load it.

NSString *iTunesLink = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=306469222&mt=8";
[[UIApplication sharedApplication]
   openURL:[NSURL URLWithString:iTunesLink]
];

Ah, but what if you want to use your iTunes affiliate account? After all, no point leaving 5% off the table! Well, that’s a trifle more complicated, since there’s redirects involved. So take your big long LinkShare string, change “itunes” to “phobos” as above, and create a NSURLConnection to sort out the URL that actually needs to be loaded. Like this:

- (IBAction)buyFullVersion
{
   NSString *referralLink = @"http://click.linksynergy.com/yadayadayada";
   self.iTunesURL = [NSURL URLWithString:referralLink];
   NSURLRequest *referralRequest = [NSURLRequest
   requestWithURL:self.iTunesURL
   ];
   NSURLConnection *referralConnection = [[NSURLConnection alloc]
      initWithRequest:referralRequest
   delegate:self
   startImmediately:YES
   ];
   [referralConnection release];
}

// Save the most recent URL in case multiple redirects occur
- (NSURLRequest *)connection:(NSURLConnection *)connection
   willSendRequest:(NSURLRequest *)request
   redirectResponse:(NSURLResponse *)response
{
   self.iTunesURL = [response URL];
   return request;
}

// No more redirects; use the last URL saved
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
   [[UIApplication sharedApplication] openURL:self.iTunesURL];
}

And that, dear friends, is how you get 75% instead of 70% on your in-app referrals. You’re welcome.

UPDATES:

And check out this followup post on how to get individually tracked analytics into your Linkshare links!]

GeoRiot promises to internationalize all your links.

User Friendly iTunes Affiliate Links

Implementing Smart App Banners

Continue Reading →
21

UIWebView internals

As you’ve no doubt noticed if you’ve tried to do anything even mildly different with UIWebView — oh, like, just to take a completely random sample, wanting to call -setCustomUserAgent: on it for the convenience of the server your application is presenting content from — the public interface is very limited, and WebKit/WebView.h is a private framework, so no SDK-compliant coding for YOU!

However, if you’re not overly concerned with the strictest adherence possible to the rules, here’s a fellow who’s worked out how to get at the internal WebView, for purposes of presenting a progress bar:

So, say you have a UIWebView called officialSDKWebView. We want to extract the main WebView from that to get the progress. To do so, we have to use another internal class called UIWebDocumentView. From there, we can get the WebView easily. Here’s the code:

UIWebDocumentView *documentView = [officialSDKWebView _documentView];
WebView *coreWebView = [documentView webView];

There’s a couple ah, non-standard header files required, and maybe a bit of other messing about in the project, but it’s all provided in that post. And once you follow it, you do appear to indeed have a genuine WebKit WebView that you can call anything from your desktop code on. Like, in the case of our completely random sample above,

[coreWebView setCustomUserAgent:@"I'm an iPhone!"];

Ex-cellent.

Of course, we would never actually recommend that you violate the published SDK guidelines, that is unsafe and irresponsible, yada yada yada. That said, relying on the iPhone SDK’s WebView to have its internals remain consistent with the desktop SDK’s … that is, most likely, a pretty darn safe bet.

h/t: iPhoneKicks!

Continue Reading →
2

URL IPC update

You may recall us mentioning back a while that some clever sparks had come up with the idea of implementing inter-iPhone-application IPC by means of registering custom URL schemes. Although there’s still a number of rough edges, it has worked out fairly functional and more work’s been done around that area, to “allow iPhone apps to work similarly to Android’s Intents”. Whatever it is that those might be.

Here’s a screencast demonstrating URL IPC in a diceshaker application.

The code for the above applications is at diceshaker and iphone-ipc-sample-diceshaker on GitHub.

There’s a page “ChooseYourOwniPhoneURLScheme” on cocoadev.com where you can see what schemes have been publicized for you to use.

Here’s a writeup from the people who integrated a credit card app and a point of sale app.

And here’s a thread on the developer forums for further discussion!

Continue Reading →
2

OmniObjectMeter freed!

Here’s a nice gift for Cocoa programmers: OmniObjectMeter is now free! And for regular users, so are OmniDiskSweeper, OmniDazzle, and OmniWeb. What, is it Christmas again already?

OmniObjectMeter tracks every retain, release, and autorelease in your  application, and helps you pair them up to find zombies and leaks. We’ve been selling it for years, but today we’ve decided to release it as freeware (along with OmniWeb, OmniDiskSweeper, and OmniDazzle) as we focus our development efforts on our major products (OmniGraffle,  OmniFocus, OmniPlan, and OmniOutliner).

And not only are they giving all these goodies away, there’s new versions of their open source frameworks too:

P.S. — We also recently posted updated versions of our open source Omni frameworks to github, including OmniDataObjects (our CoreData-like implementation which works on both Mac and iPhone).  For more information, see <http://www.omnigroup.com/developer/>.

What nice people Omni are, indeed!

h/t: cocoa-dev!

Continue Reading →
0

OpenGL ES + CATransform3D

Well, here’s a followup to yesterday’s post on CATransform3D: The fellow who wrote the 3D molecular visualizer Molecules that we mentioned back when it was open sourced decided to apply that work to Molecules’ rendering routines, and it worked out pretty well!

It turns out that the CATransform3D struct provided by Core Animation for doing manipulation of CALayers is identical in structure to the model view matrix in OpenGL (ES). In fact, Apple has provided us with a number of functions for manipulating this CATransform3D struct in ways that correspond to glRotate, glScale, and glTranslate calls.

This solves the biggest known problem I had with Molecules’ rendering routines: for me to do rotation and translation relative to the user’s touch input, I had to know the state of the model view matrix at all times. In the current version of the program, that means that I had to use a few glGetFloatv calls to query the current state of the model view matrix. Each of these calls halted the rendering pipeline, so I needed a way to get rid of them.

CATransform3D and its supporting functions provide the means to do that. I could keep track of the current model view matrix in a CATransform3D, perform manipulations on that structure, and just replace the OpenGL model view matrix with it every time there was a change…

…this quick set of optimizations leads to an increase of 14-25% (depending on the specific model) in the number of triangles per second that Molecules was able to push through the iPhone’s GPU. This means that on the iPhone 2.2 firmware, I’m now getting a max of 310,000 triangles per second. This is still short of the 470,000 triangles per second the iPhone is capable of under these conditions, as reported elsewhere. There’s still some room to improve, but I’m getting there.

So there you go. If you’ve got any complicated OpenGL transformations to keep track of, look into CoreAnimation!

h/t: iPhoneKicks!

Continue Reading →
1

Code: Trackball

Now here’s a nifty piece: How to do 3D object transformations without OpenGL — all simply using CoreAnimation! It’s called Trackball and the details can be found here:

The idea is that you have a 2D viewport into a 3D scene, this view port has a width and height (i.e. the CGRect that defines the layers bounds). In this 3D world you construct an imaginary sphere with a radius of the minimum of height or width of your view port centered on the center of your scene. When the event begins (with a touchesBegan:withEvent:) you initialize the trackball with the touches location as the starting point. A vector is constructed from the center of the sphere to the touch (the depth dimension is calculated based on the radius of the sphere). As the user moves her finger around on the screen another vector is constructed from the center of the sphere to the current touch location (as received in touchesMoved:withEvent:). The cross product of these two vectors is the vector of rotation and the angle between them is the magnitude of the rotation.

If all that is a little bit overwhelming, there’s a followup post with a sample application — but an even better example can be found on github where some bright spark has put together a project called ‘Cubo’ which makes it really easy to visualize the transformations by use of a numbered cube, like this:

cubo

Cool stuff, indeed. We’d also like to point out that the originator of the Trackball code is the Bill Dudney that wrote the most excellent Core Animation for Mac OS X and the iPhone book, which if you don’t have you should click on that link and purchase immediately, and is coauthor on a new iPhone SDK Development book which will no doubt also be well worth your time to order!

[EDIT: And also check out tomorrow's post about applying Core Animation to Open GL transformations!]

h/t: iPhoneKicks!

UPDATES:

CATransform3D-Test: “A test app to visualize view transformation when values in CATransform3D matrices change.”

Continue Reading →
3

Library: Route Me

Always interesting to keep track of mapping solutions for the iPhone, and here’s an interesting looking one: Route Me, which is up on Google Code and BSD open-sourced:

sydney

Nice-looking, and remarkably flexible to boot:

Currently OpenStreetMap Microsoft VirtualEarth and CloudMade are supported as map sources.

Use it in your iPhone project. Its licensed under the new BSD license.

You are responsible for getting permission to use the map data.

… of course, that last bit is the trick.

h/t: iPhoneSDK!

Continue Reading →
2

OpenGL roundup

Here’s a blog chock full of meaty programming goodness we hadn’t stumbled over before: iPhone Development. The particular post we found a reference to was a collection of OpenGL articles from December,

These past three days have seen a flurry of postings. I thought I’d just do a quick table of contents to the various tutorials and postings I’ve done recently, in the order they should be read:

but there’s been a good bit of updates since then. Catch them all by looking for the OpenGL ES tag, or if you’d like a bit of a refresher the OpenGL From the Ground Up series, but we’ll draw your attention particularly to this post providing an updated version of the Xcode template post above:

Here is a new version of my OpenGL ES project template for Xcode. This version adds a class called “OpenGLCommon.h”, which contains data structures and inline functions for vertices, vectors, triangles, etc. – mostly stuff from the Wavefront OBJ class that has generic applicability, backported into the template.

h/t: iPhoneKicks!

[UPDATES]

And here’s another good OpenGL ES article at Dr. Dobbs written by the author of The OpenGL SuperBible, which if you don’t have we recommend you buy immediately.

Another roundup post with some new links — and the blog it’s from has lots more OpenGL stuff!

And here’s a very good iPhone focused series of OpenGL tutorials — up to #4 on 09.05.15!

That no glBegin()/glEnd() bit got you stumped? Read OpenGL Vertex Buffer Objects (VBOs): A Simple Tutorial!

Continue Reading →
1

Library: JSON Framework

Here’s a handy library for you if you’re interested in getting into this JSON thing that all the cool kids seem to be excited about these days; the iPhone-friendly JSON Framework, “A strict JSON parser/generator for Objective-C“.

This framework implements a strict JSON parser and generator in Objective-C.

Download the framework, embed it in your application, and import the JSON/JSON.h header. You’re now ready to make your application speak JSON. The framework adds categories to existing Objective-C objects for a super-simple interface, and provides a JSON class for added control.

The author’s blog with release notes is here, and don’t miss the most excellent tutorial at iPhone Developer Tips!

UPDATE 10.07.30:

New JSON library announced today: JSONKit – Yet another JSON library

Not, of course, to be confused with YAJL (Yet Another JSON Library), as found in CocoaREST that we’ve been using for Twitter support.

Mind you, for other JSON needs we’ve been using TouchCode’s TouchJSON, forget why exactly now but probably it was the most developed the first time we had to do iPhone JSON stuff and inertia of library choice tends to continue around here until a compelling reason is found to invest time in deciding whether to fix or switch some problem that shows up.

Also note this post about the benchmarks here, comparing the above mentioned frameworks with Apple’s private JSON library.

And it seems that the commonly known as “SBJSON” project that this was originally about has moved to github, and reportedly will be updated soon.

Continue Reading →
1

UITableView dispatching

And today, we draw your attention to an interesting exploration of how to make your sectionized UITableView handling code less fragile by creating subclasses for each section handling.

I’ve developed a technique … allowing you to delegate the handling of each section in a table view to its own class. It is also easily configurable if you need to add or remove a section type from your controller later, and allows you to localize your changes so that you don’t have to remember to modify code in several places.

The basis of my technique is to create a main view controller for the table view, in this case calledNoteViewController, and separate section controllers for each section that inherit from anAbstractNoteSectionController class that I created. This class defines the interface for the section controllers and provides reasonable default behavior in case I don’t need specific behavior in my subclasses…

Using this technique, I was able to split up a hard to read and manage 700 line behemoth class into much more managable 80-200 line pieces and improve the readability and flexibilty of my code immensely. Hope you find this useful in your iPhone development.

Indeed. Give it a read the next time you start to find yourself buried under switch statements!

Continue Reading →
0
Page 76 of 82 «...5060707475767778...»