Visit my site @ mugunthkumar.com



iPhone Tutorial: Elegant way to send formatted In-App email

March 7th, 2010 by Mugunth Kumar

By now, most of you know how to send emails using the Message UI framework without quitting the app. In this tutorial, we will briefly discuss the techniques for sending a HTML formatted email with user generated content. Though sending a HTML formatted email is as easy as setting the option to HTML

[picker setMessageBody:emailBody isHTML:YES];


There are some cases that this method that this method doesn’t take care of. In short, this method works great for sending “Tell a friend about this app” email. But if your app needs much more sophistication, especially, if it needs to email data created by the user, you can follow the approach I suggest. Using this method, you can also adapt your code for International support and send the same email in multiple languages without any “hard-coding

Though the method promises some great features, it is ridiculously simple. :)

Step 1:

Create a HTML File with the contents of your email and add it to your project. You should NOT create any css or link it to any external CSS files. All your styles whether embedded withing the <STYLE> tag or kept as a separate CSS file will mostly be stripped by email clients. The reason could be because email clients don’t want your CSS to mess around with their client CSS. Read this article for more details. A sample is given below.

Step 2:

Insert placeholder markers within your HTML file. Your HTML file should look something like this.

<font size = '1' color= "#222222" style = "font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial;"><i>//TEXT_PLACEHOLDER//</i></font>
<font size = '2' color= "#000000" style = "font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial;"> Have a great day! <br/>//FRIENDNAME_PLACEHOLDER// <br/></font>

The bold markers are the placeholders. You can assume them to be variables in the email. We will be replacing them later.

Step 3:

Do exactly the same steps for sending an in app email explained in one of my previous tutorial, but rather than hardcoding the email body like this,

NSString *emailBody =
[NSString stringWithFormat:@"%@\n\n
Sent from MyGreatApp on iPhone. Download yours from AppStore now!
", content, pageLink, iTunesLink];

Read it from your HTML File you created in Step 2.

NSString *langString = [[userDefaults dictionaryRepresentation] objectForKey:@"NSLocaleCode"];
NSString *emailFileName = [NSString stringWithFormat:@"email_%@.html", langString];
NSString *emailFilePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: emailFileName];
NSString *body = [NSString stringWithContentsOfFile:emailFilePath encoding:NSUTF8StringEncoding error:nil];

Note that, I’m appending the locale code with the email filename. That means you should create your email file by name email_en_US.html and similarly for other language files.

Step 4:

Replace placeholder texts with your contents generated within the app.

body = [body stringByReplacingOccurrencesOfString:@"//TEXT_PLACEHOLDER//" withString:myText];
body = [body stringByReplacingOccurrencesOfString:@"//FRIENDNAME_PLACEHOLDER//" withString:myFriendName];

The values myText and myFriendName should be passed to this email function.

With this architecture in place, you can format your email, change language and do a lot more without much changes to your code. After all, writing cleaner code is more important in the long run.


Mugunth

How to deploy on iPhone OS 3.1.3 without downloading the 2GB SDK

February 3rd, 2010 by Mugunth Kumar

Like most of you, I too downloaded the 3.2 beta and was playing around with some iPad stuff. Today when iPhone OS 3.1.3 is released, without second thought, I immediately updated my iPhone. My iPhone being a development device, I understood that I can no longer use the current XCode installation to run apps on device. When I launched XCode, the Organizer reported,


“The version of iPhone OS on “ABC’s iPhone” does not match any of the versions of iPhone OS supported for development with this installation of the iPhone SDK”

So does that mean, you should re-install the SDK? Just like me, you will probably have confusions like,

Will installing it corrupt or overwrite your 3.2 beta?

Should I re-install 3.2 beta again?

I too had these. Fortunately, I decided to hack things myself and got the 3.1.3 working without downloading the entire SDK. This is how I did. Type the following command into your terminal.


ln -s /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.2\ \(7D11\) /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.3

Now quit and restart XCode. Voila! you have effectively “fooled” XCode! and you have saved countless hours which you can effectively use on programming another cool app!

Note that this hack will work *any* minor OS updates. However, if you are using a feature specific to the new version you will probably find yourself in trouble. In other words, don’t try to apply the same technique when 3.2 or 4.0 launches.


Mugunth

Save As vs Exporting – Why Apple excels at UI Design?

January 13th, 2010 by Mugunth Kumar

Most users think, Mac UI is all about slick graphics and “cool” icons. Well, that might be true partially, but user interface design isn’t about photoshopping or designing cool looking icons. According to Jakob Nielsen, aesthetics is just one aspect of usability. There is much more to user friendly software than just the “cool factor” or great icons.


Recently, I was using Microsoft’s Excel to edit a dozen large  CSV files. As a matter of fact, in Excel,  whenever you save “anything” you do as a CSV,  you will practically lose out features that aren’t supported natively by the underlying file format. For Example, CSV doesn’t support coloured cells. So when you colour a cell, and try to “save” it as a CSV, Excel pops up this dialog.

Saving as CSV loses of "certain" features

When you click “Yes”, all that Excel does is to “export” whatever content your file has into what the underlying format can support. So since, excel supports coloured cells but CSV doesn’t it ignores your colouring and proceeds saving it to CSV. Excel even goes one step far and doesn’t clear the “dirty flag” because, Excel hasn’t saved *every* change you made into the CSV.

Sounds good so far. But what’s really wrong here? The real problem is, Excel gives you a sense of feel that “everything” have been saved and you are safe. Things become bad when you quit Excel. Because the dirty flag isn’t cleared and the file haven’t been saved completely, Excel prompts you to “save” the file again. Specious, not wanting to take chances, some users like me, save the file again. Again the same thing happens and the end user is still just dumbfounded and asks, But, why the heck should I save it again?

Microsoft UI designers have failed to understand the end users. In this case, it’s because Excel fails to speak the users’ lingo. According to the user, when he “saves” a file, he saves a copy and he is contended that he can always re-open when something bad happens. But excel just “exports” the file into CSV format and tells the user that it “saved” the file (when it in fact didn’t). As a result what happens is data loss. No not just cell colours, in cases, when the users doesn’t know that CSV doesn’t support multiple sheets, excel doesn’t export (or save) the second sheets data and the user just loses the entire content from the second sheet. Disaster! In one of the cases where I work, a co-worker of mine, has got used to these prompts which Excel shows after you “save” your file as CSV

Prompts user to save the "saved" file again

and he just closes Excel assuming that these prompts are nothing but “bugs” in Excel. (Yeah see, he is a half techie and a little knowledge is dangerous.) Things went fine when he didn’t lose data, but just lost some formatting here and there. But the real disaster happened when his second sheet containing over 1000 lines and 3 hour work was lost.

Now, lets’ see how Numbers, the equivalent software from Apple handles this.

Save As panel for Numbers.app

Apple doesn’t even include CSV or other “lossy” formats in the save as sheet. That doesn’t mean, Numbers can’t “save” your data as CSV. But rather Apple calls it as “Export”. Files you export as CSV aren’t yet saved. So, when the user quit Numbers, and get a prompt to save the document, he will not confused.

Because Microsoft does it this way (wrong way), other software makers like Adobe too make the same mistake. Photoshop “saves” a file as PNG and still give you a sense of feel that you have saved the file. Another such example is audacity and paint.net and even those “save as PDF” plugins. They actually don’t “save” your data, but rather export it. Apple gets it right, but the whole world gets it wrong, Unfortunate!.


11 visitors online now
11 guests, 0 members
Max visitors today: 13 at 12:58 am SGT
This month: 58 at 03-01-2010 02:57 am SGT
This year: 59 at 02-12-2010 06:23 am SGT
All time: 59 at 12-19-2009 09:48 pm SGT