RSS feed

Nutsmuggling

Plugins list, now compatible with WP 2.7

Hello folks,
this is just to let you know that I updated my Plugins list plugin to version 0.2.2, to make it compatible with WP 2.7.

With the 2.7 upgrade all the links to the plugins and authors homepages had disappeared. Now the situation seems to be back to normal.

Enjoy!

Davide

Und Christmas Chicken ©!

Santa and the XMas Chicken

Merry Christmas, or whatever rocks your boat, to anyone, from Me, Santa Claus, and the, uhm, XMas Chicken ©.

iPhone SDK: sending formatted email

As a part of an iPhone app I’m presently working on1 I was confronted with an apparently simple problem, which turned out to be more difficult than I thought.
Except it was simple, once you knew how to do it.

Question

How do I send a tabular report via e-mail in the iPhone SDK?

Short answer

Use a mailto url + stringByAddingPercentEscapesUsingEncoding + HTML.

Longer answer

So far (iPhone OS 2.2) the de facto way to send e-mail on your iPhone application is using a mailto url.2

NSURL *url = [[NSURL alloc] initWithString:
@"mailto:me@me.com?subject=subject&body=Hi"];
[[UIApplication sharedApplication] openURL:url];

Of course you can use a format to include your own dynamic text, but the url string must be url escaped. Cocoa(Touch) provides a nice way to escape URLs, stringByAddingPercentEscapesUsingEncoding:

NSString *encodedBody = [eMailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

The only problem left was representing tabular data. At first I though I’d use \t to create tabs, but I found out they’re not properly supported in e-mail bodies. Then a discussion on the Google Groups gave me the hint, the body parameter of mailto is actually parsed as HTML.
So, amazing as it seems, this code works:

NSString *eMailBody = @"<table>
<tr><td style='text-align:right'><b>Name</b>:</td>
<td>John</td></tr><tr>
<td style='text-align:right'><b>Surname</b>:</td><td>Doe</td></tr>
<tr><td style='text-align:right'>
 <b>Occupation:<b/></td><td>Placeholder</td></tr></table>";
NSString *encodedBody = 
[eMailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSString *urlString = 
[NSString stringWithFormat:@"mailto:me@me.com?subject=HiPhone&body=%@", encodedBody];
NSURL *url = [[NSURL alloc] initWithString:urlString];
[[UIApplication sharedApplication] openURL:url];

And here’s the result:

IMG_0001.PNG

Bingo!

A weird downside of this method is that the user will be able to edit the email, but not is formatting: the bold characters will stay bold and so on; this seems to be a feature of the mail app itself.

Device vs Simulator

Since the iPhone simulator does not have a Mail.app, you can use e-mail URLs only in the actual device. As a matter of fact, it’s advisable to use compiler statements to create specific simulator/device code:

#if TARGETIPHONESIMULATOR
    //compiler specific code
#else
    // device specific code
#endif

In my app, I use a UIAlertView in the simulator code, so I can have the email text displayed onscreen. Currently I have a UITextView as its subview, but I plan to use a UIWebView, so I can preview the HTML in the simulator.

(Thanks to Slashzero for his comment)

Notes

  1. shush shush, too early to talk about it! []
  2. Please note that, although the mailto protocol might support attachments, you specify attachment with the sdk. I know, it’s a shame, but so far we’re not allowed to send attachments through mail. The alternative is writing your own smtp server, but refrain from doing it, unless the composed mail is sent without any user intervention, otherwise you’ll also have to write your own mail client. []

WordPress 2.7 Vertical Navigation

WordPress 2.7 Dashboard navigation: real life experience

sss

via WordPress 2.7 Vertical Navigation — Design, Web Critique — Konstruktors Notes .

Creepy Santa for Palm

Palm new website introduces a creepy impostor who presents himself as Santa Claus. He could feature in Dexter’s next season.

Via @blankbaby.

PS: As you see, I decided I am going to post asides, it’s quite time, and I’ve been lingering too much over this :)