Converting UIImage to NSString to embedded image in email body from iphone app

December 29, 2009 § 3 Comments

Including image within email body from iphone app is a very tricky business. Using Base64 encoding according to my search results works on all mail server except Gmail. Gmail won’t allow embedded images.
These are the Objective-C methods converting from UIView to NSString for email body.
  • Converting the UIView to a UIImage using UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  • Converting the UIImage to NSData using NSData *imageData = UIImagePNGRepresentation(viewImage);
  • Convert the NSData to Base64
  • Converting the Base64 encoded image data into an NSString using NSString *dataStr = [NSString stringWithCString:encodeArray length:strlen(encodeArray)];
  • Embedding the image into email using NSString *body       = [@"" stringByAppendingFormat:@"<b><img src='data:image/png;base64,%@' alt='Interpolate Chart'></b>", dataStr];
  • <b> and </b> in the embedded image code above must be present, or mail will strip your image.

Xcode Program received signal: “EXC_BAD_ACCESS”

December 25, 2009 § Leave a comment

Program received signal: “EXC_BAD_ACCESS”

This error occurs in device not simulator.

Possible Errors:

  • access protected or non-existent memory space as result of a bad pointer
  • access memory without alloc init
  • access memory after released object
  • remove the [object release] only if you don’t use alloc/copy/retain
  • trying to access release objects
  • illegal memory access

This show you how to use Cocoa’s NSZombie debugging class and the command line “malloc_history” tool to find exactly what released object has been accessed in you code.

Running Instruments and checking for leaks will not help troubleshoot EXEC_BAD_ACCESS.

Debugging Techniques

NSAssert() call to validate method parameters is to track and avoid passing nils set a breakpoint on objc_exception_throw.


Error occur:
NSMutableString *string; [string   appendWithFormat:@”foo”];
NSMutableString *string = [[NSMutableString alloc] init];
[string appendWithFormat:@”foo”];

Error occur:
NSLog(@”Message %@-%@”);

NSLog(@”SMessage %@-%@”, object1, object2);

Code Sign Errors: profile doesn’t match any valid certificate/private key pair in the default keychain

December 25, 2009 § 25 Comments

In order to audit and test the app on device before app submission you would have to build the app with valid matching certificate and provisioning profile.

Possible causes to trigger a Code Sign error

  • switch from individual developer account to corporate developer account on the same mac
  • upgrade iPhone SDK version
  • upgrade device iPhone OS version
  • switch to another mac
  • lost public/private key
  • certificate expired
  • certificate invalid

Possible Code Sign Errors:

  • developer certificate can’t be found
  • provisioning profile can’t be found
  • profile doesn’t match any valid certificate/private key pair in the default key chain

Code sign errors will cause device errors showing orange light

I am sharing the process of removing the Code Sign errors and/or device error orange light. Keep in mind you would have to follow the Program Portal instruction for detail steps. Don’t skip any steps or mix any step orders.

Provisioning profile would throw you errors if you didn’t use the valid certificate to generate the public/private key and provisioning profiles.

What can be kept the same

  • App IDs
  • Devices
  • Provisioning

First of all you must delete the following to avoid unnecessary troubleshooting and matching conflicts on your mac in keychain, harddrive, Xcode organizer, and on your device.

  • keychain > developer certificate
  • keychain > private/public key
  • device > settings > general > profile > provisioning profile
  • xcode > organizer > devices > provisioning > provisioning profile
  • iphone configuration utility > provisioning profiles > provisioning profile

Note: iphone Configuration Utility is a FREE tool you can download. If you don’t have it you can manually delete the provisioning profile.

Revoke your certificate even it is not expired. Revoke your existing certificate and re-create your certificate again. Every step must be executed in the right order. If you forget a single step you would get the same Code Sign error.

Step 1) Generate a Certificate Signing Request (CSR)
Applications > Utilities > Keychain Access
In the Preferences menu, set Online Certificate Status Protocol (OSCP) and Certificate Revocation List (CRL) to “Off”.

Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority

Name and email address entered matches the information that was submitted when you registered as an iPhone Developer.

Select the ‘Saved to Disk’ radio button and if prompted, select ‘Let me specify key pair information’ and click ‘Continue’. No CA (Certificate Authority) Email Address is required.

If ‘Let me specify key pair’ was selected, specify a file name and click ‘Save’. In the following screen select ‘2048 bits’ for the Key Size and ‘RSA’ for the Algorithm. Click ‘Continue’.

CertificateSigningRequest.certSigningRequest CSR file on your desktop is created on desktop.

Step 2) Submitting a Certificate Signing Request for Approval
Revoke Certificate.

Certificates > Development
Request a certificate. Click the ‘Choose file’ button, select your CSR and click ‘Submit’. Request your page until you see the update status. Click the ‘Approve’ button.

Step 3) Download & Install Developing Certificates
Certificates > Distribution
Control-click the WWDR Intermediate Certificate link and select “Saved Linked File to Downloads” on desktop

Double-click the WWDR Intermediate certificate AppleWWDRCA.cer to launch Keychain Access and install

Download their certificates. Double-click the downloaded .cer file developer_identity.cer to launch Keychain Access and install your certificate.

To verify the success install, you would see  1) Apple Worldwide Developer Relations Certfication Authority Certificate 2) iPhone Developer: Team Leader Certificate

Step 4) Update the existing Provisioning

No need to remove the provisioning profile. Click the ‘Modify’ button. Check the box on Certificates. Submit to save the Development Provisioning Profile.

Step 5) Install a Development Provisioning Profile
Download the profile developer_profile.mobileprovision

Drag the downloaded file into the ‘Organizer’ window within Xcode. This will automatically copy the .mobileprovision file to the proper directory. If the directory does not exist you will need to create it. Click on the ‘+’ button in the Provisioning section of the Organizer window to install your .mobileprovision file.

Step 6) Build & Install App on device
Launch Xcode and open your project. Select ‘Device – iPhone OS’ from the ‘Device | Debug’ drop down menu.

Highlight the project Target and select the ‘Info’ icon from the top menu bar. Navigate to the ‘Build’ pane. Click the ‘Any iPhone OS Device’ pop-up menu below the ‘Code Signing Identity’ field and select the iPhone Development Certificate/Provisioning Profile pair you wish to sign and install your code with.

Your iPhone Development certificate will be in bold with the Provisioning Profile associated with it in grey above. In the example below, ‘iPhone Developer: Team Leader’ is the Development Certificate and ‘My Development Provisioning Profile’ is the .mobileprovision file paired with it.

If the private key for your iPhone Development certificate is missing, or if your iPhone Development certificate is not included in a provisioning profile, you will be unable to select the iPhone Development Certificate/Provisioning Profile pair and you will see the following. Re-installing the private key or downloading a provisioning profile with your iPhone Development certificate included in it will correct this.

How to code ActionScript to softkey on Flash Lite Nokia Mobile App

December 21, 2009 § Leave a comment

By default you can define pressed key event to softkey using ActionScript on Flash Lite Nokia mobile app.

Flash Lite 1.1

You can assign pressed key events to a button. You can map the for navigation keys, numeric keypad, and softkeys.

Convert a shape into a button and assign the code.

on(keyPress "<Enter>") {
    trace("Selection key pressed");
on(keyPress "<PageUp>") {
    trace("Left softkey pressed");
on(keyPress "<PageDown>") {
    trace("Right softkey pressed");
on(keyPress "<Up>") {
    trace("Up direction key pressed");

Flash Lite 2.0+

A key listener can be assigned to a button, object or MovieCkip.

// Create the object for the key listener

var keyListener:Object = new Object();

// Define the onKeyDown events to listen to

keyListener.onKeyDown = function() {

    if (Key.getCode() == Key.ENTER) {

        trace("Selection key pressed");


    else if (Key.getCode() == ExtendedKey.SOFT1) {

        trace("Left softkey pressed");


    else if (Key.getCode() == ExtendedKey.SOFT2) {

        trace("Right softkey pressed");


    else if (Key.getCode() == Key.UP) {

        trace("Up direction key pressed");



// Enable the key listener


To customize labels & functions for softkeys
Call the SetSoftKeys command, part of fscommand2() method on the first frame of Flash Lite app. fscommand2() command are mobile focused ActionScript, outside ActionScript library. It maps the labels to softkeys and disables the default softkey functions.

fscommand2(“SetSoftKeys”, “LeftKeyLabel”, “RightKeyLabel”);

Note: Only left and right softkeys can be coded in fscommand2 method.

Design Rules:

1. Clear label

2. Forward-going functions (continue, confirm, zoom, options, menus) should be assigned to the left softkey.

3. Backward-oriented functions (cancel, back, exit) should be assigned to the right softkey.

4. Softkey label should be rotated in position when screen orientation changes

5. Code the softkey on touch event on touch devices

Flash Lite Application Deployment

December 21, 2009 § 3 Comments

Nokia offers 4 options in deploying Flash Lite mobile app.

1. IR (infrared) / Bluetooth / USB cable
Nokia PC Suite is a FREE tool you can download and install Flash Lite applications. You can connect device via IR, Bluebooth or USB cable.

2. Memory card
You can transfer Flash Lite applications to the memory card of a device using a memory card reader.

3. OTA (over-the-air)
You can upload the Flash Lite applications to a Web server and then downloaded to a device via the device’s Web browser.

4. Email / MMS
Flash Lite applications can be sent as email attachments or MMS messages.

Install the Flash Lite app into assigned folders.

[device memory]\Data\Others
[memory card]\Data\Others

S60 3rd Edition and S60 3rd Edition, Feature Pack 1
Run the app with Flash Lite Player

S60 3rd Edition, Feature Pack 2 and newer
Run the app by opening the main SWF file directly using the Media Gallery or File Manager

You can copy the Flash Lite app files to any location or launch from any location within the file system

Packaged App

Packaged app is installable mobile applications including a number of external resource files or additional Flash Lite applications. Files are packaged into a single installation source file.

Use Symbian Installation Source (SIS) package format
Stub applications are specialized lightweight Symbian applications packaged as SIS files to launch other applications

Use Nokia Flash Lite (NFL) package format

Signed Packages

S60 accepts signed SIS package. It can be signed by self-signed certificate for development or request official certificate from Symbian Signed. No signing requires for NFL packages.

Creating and signing a SIS package
Creating an NFL package
Creating a stub application

Flash-Lite Application

December 21, 2009 § Leave a comment

4 simple steps to design a Flash-Lite mobile app. With wider range of mobile models, Flash Lite versions, and Flash Player types one must prepare each step well to achieve a well-balance well-designed mobile app.

  • analyze and define the requirements
  • scope
  • use cases
  • functionality

Flash Lite Application Types

December 20, 2009 § Leave a comment

These are the 3 types of Flash Lite Application.

1. Standalone

Standalone Flash Lite applications are the most common category of Flash Lite applications. It only requires a SWF file.

S60 3rd Ed and/or Feature Pack 1 devices
Flash Lite player can be launched from the Applications menu

S60 3rd Ed and/or Feature Pack 2 devices
Flash player is a hidden application that allows users to access Flash Lite content directly from the Media Gallery or File Manager . Or it is launched from other applications that need to play Flash Lite content.

2. Browser-embedded Content

You can include Flash Lite content in HTML and XHTML Web pages. When a SWF file is coded in the <embed> and <object> elements of a Web page, the file is downloaded and played automatically by the device. It can be used in conjunction with mobile device widgets.

3. Screen Saver

A SWF file that requires no user interaction is a screen saver. Screen saver is available on all S60 devices that support Flash Lite 2.0 or newer and on all Series 40 devices. Wallpapers are a subset of screen savers. Wallpapers are displayed as a background image. Any device that supports screen savers also supports wallpapers.

Where Am I?

You are currently viewing the archives for December, 2009 at Web Builders.