Monday 19 December 2011

How to Send Email with Attachments – Example Using iPhone Camera to Email a Photo


In this post: Camera Application to Take Pictures and Save Images to Photo Album, I demonstrated how you can take photos with the iPhone camera and save the captured images to the Photo Album. A reader asked if it would be possible to email the camera image in place of writing to the Photo Album, which is the focus of this tip.
Building on the previous post, the example created here starts the camera on the iPhone, and once a photo is snapped, launches the email application, attaching the resulting image to the email.
Start the iPhone Camera
The user interface of this application is quite simple, there is one button on the UI that will start the camera. Once the button is tapped, the method shown below will be called. Here we create an image picker controller, set the source type to the camera, point the delegate to self and specify not to allow image editing. From there, simply show a modal view controller to enable the camera.
- (void)buttonPressed:(UIButton *)button
{
  // Create image picker controller
  UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
 
  // Set source to the camera
  imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;
 
  // Delegate is self
  imagePicker.delegate = self;
 
  // Allow editing of image ?
  imagePicker.allowsImageEditing = NO;
 
  // Show image picker
  [self presentModalViewController:imagePicker animated:YES]; 
}
Convert Camera Image to NSData Object
Once the camera has taken a photo, the method below will be called, passing in a dictionary of related information, such as the original image, edited image (if any), URL to a movie (when applicable), etc. We grab the image from the dictionary and create a UIImage object. From there, dismiss the camera, then pass the camera image to the method emailImage where we will construct an email and append the image.
-- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  // Access the uncropped image from info dictionary
  UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
 
  // Dismiss the camera
  [self dismissModalViewControllerAnimated:YES];
 
  // Pass the image from camera to method that will email the same
  // A delay is needed so camera view can be dismissed
  [self performSelector:@selector(emailImage:) withObject:image afterDelay:1.0];
 
  // Release picker
  [picker release];
}
Email Camera Image
The last step is to compose an email and attach the image from the camera. We begin be creating a MFMailComposeViewController object, setting the delegate to self. We then step through the configuration preferences for the email, setting the subject, the list of recipients (to, carbon copy, and blind carbon copy) and creating the body of the message.
Our next step is to convert theUIImage from the camera into an NSData object, which we can attach to our email. As you’ll notice in the code below, I’ve created the NSData as a PNG representation, you could also use JPG format if you prefer (which allows you to specify a value for image compression).
Once the image is attached to the email, we show a modal view controller which will launch the email application – one note, I am making the assumption that iPhone OS 3.x is the active platform.
- (void)emailImage:(UIImage *)image
{
  MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
  picker.mailComposeDelegate = self;
 
  // Set the subject of email
  [picker setSubject:@"Picture from my iPhone!"];
 
  // Add email addresses
  // Notice three sections: "to" "cc" and "bcc" 
  [picker setToRecipients:[NSArray arrayWithObjects:@"emailaddress1@domainName.com", @"emailaddress2@domainName.com", nil]];
  [picker setCcRecipients:[NSArray arrayWithObject:@"emailaddress3@domainName.com"]]; 
  [picker setBccRecipients:[NSArray arrayWithObject:@"emailaddress4@domainName.com"]];
 
  // Fill out the email body text
  NSString *emailBody = @"I just took this picture, check it out.";
 
  // This is not an HTML formatted email
  [picker setMessageBody:emailBody isHTML:NO];
 
  // Create NSData object as PNG image data from camera image
  NSData *data = UIImagePNGRepresentation(image);
 
  // Attach image data to the email
  // 'CameraImage.png' is the file name that will be attached to the email
  [picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"];
 
  // Show email view 
  [self presentModalViewController:picker animated:YES];
 
  // Release picker
  [picker release];
}
 
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
  // Called once the email is sent
  // Remove the email view controller 
  [self dismissModalViewControllerAnimated:YES];
}
Caveat
To keep things simple, this application runs on a single thread. It works fine, however, there is a few second delay when moving from the camera application to the email application. Ideally you would add a little logic to better manage the user interface.
Source Code
Here is the link to the source code: Email Camera Image Application.

Tutorial Guide to Install Windows 8 on VirtualBox


Microsoft released a developer preview of Windows 8 last night and surprisingly made it available for general public too. Though this brand new OS is half-baked and is meant to be used by developers to build apps for Windows 8, it’s way too tempting for a non-developer to let go the opportunity to get the first taste of a hot & sexy OS.
Not to worry, we have a detailed yet simple guide to help youinstall and test-drive Windows 8 on your existing PC using a free to use virtualization software called VirtualBox. Though there are other VM (virtual machine) software like VMware Workstation and Virtual PC, I would advice you to go with VirtualBox as I have been getting reports of failed installations on VMware and Virtual PC, possible because Windows 8 requires IO APIC enabled to run on VMs, which is available only on VirtualBox.
Ads by Google
2X ApplicationServer XGwww.2x.com/applicationserver/
Free & secure application & desktop delivery to any operating system.
  
Virtual Serverwww.microsoft.com/Private_Cloud
Microsoft® Private Cloud Solutions Full Control Down to the App Level

Pre-requisites

  • It is very important for you to confirm that your PC supports Hardware Virtualization. If you are not sure, use this guide to check.
  • If it supports hardware virtualization, make sure you enable it via BIOS.

How to Install Windows 8 on VirtualBox

Note: This guide is written for Windows 8 Developer Preview and installed on a Dell Studio 1555 Laptop running Windows 7 64-bit version using VirtualBox 4.1.2 VM software. But it should hold good for all builds of Windows 8 and all versions of VirtualBox 4.x on all PCs running Windows (and may also work on Mac/Linux).
1. Download the latest version of VirtualBox.
3. Install VirtualBox. Installation is quite simple & straight-forward.
4. Click on “New” to create a New Virtual Machine Wizard.
5. Type the name of the VM (“Win8” for example). Make sure you select Microsoft Windows as the Operating System and Windows 7 as the version. Select Windows 7 64-bit if you are on a 64-bit system. Click on Next
windows-8-install-1
6. In the next window, you are supposed to allocate the memory for this VM. The thumb rule is to allocate half of the available RAM. For example, if you have 4GB RAM, allocate 2GB for this VM, so that you will still have 2GB for the host OS.
windows-8-install-2
7. Next step is to create a virtual hard disk. Assuming you haven’t created a startup disk before, it is wiser to leave the default settings and click on Next.
windows-8-install-3
8. Here as well, leave the default setting (VDI) and click on Next.
windows-8-install-4
9. In this step, you are free to choose either of the options, but I recommend Fixed size as it would ensure you don’t end up short of HDD space after sometime.
windows-8-install-5
10. You can increase or decrease the Virtual disk file size as you wish. But make sure you allocate at-least 14GB of space. The default value of 20GB is a safe bet though. Click Next to complete the configuration.
windows-8-install-6
11. You will be greeted with the Summary page with the settings you have chosen. Click on Create button to begin creating virtual disk file.
windows-8-install-7
12. Step back and wait for virtual disk file to be created. It might take some time depending upon the size of the virtual disk file you have allocated.
windows-8-install-8
13. Once the process is completed, you will be greeted with the screen below.
windows-8-install-10
14. Before you go ahead and start the Windows 8 VM, make sure you change a couple of important settings. Click on Settings and
  • Choose System tab on left panel. Make sure Enable IO APIC is checked.
  • Also, under Acceleration tab, make sure both Enable VT-x/AMD-V and Enable Nested Paging are checked. Click OK to exit.
15. Now click on Start button. This will start the “First Run Wizard”. Click on Next.
windows-8-install-11
16. Here, you would need to select the Windows8 ISO file which you downloaded in Step 2. Click on the Yellow folder icon to browse through to the folder containing the ISO file and select the ISO file. Click on Next.
windows-8-install-12
17. Windows 8 installation will start. Choose the appropriate language, Time, Currency and keyboard settings and click on Next.
windows-8-install-13
18. Next few steps are straight-forward and you should then see this “Installing Windows” screen.
windows-8-install-14
19. Once the installation is complete, you will be asked to add an user. If you have a Windows LiveID, just enter your email address and Windows will fetch the details from the web. If not, you can either create a new LiveID or choose to enter a custom username and password. Tip: In Settings page, it is better to choose “Express Settings” instead of “Custom settings” as I had problems connecting to the internet when choosing Custom settings option.
windows-8-install-15
20. Once done, you will be greeted with the new metro style Start screen!
windows-8-install-16

Troubleshooting tips

1. If you get an error “This 64-bit application couldn’t load because your PC does not have a 64-bit processor”, it means you haven’t enabled hardware virtualization and/or IO APIC for the VM. Enable both, shutdown the PC (not just restart) and start again.
2. If you have problem connecting to internet after installing Windows 8, try choosing Intel PRO /1000 MT Desktop under Advanced Configuration of Network tab.
3. I have not been able to get the metro styled apps working as they just don’t open (except for Control Panel, Windows Explorer and Show desktop). There is no fix for this as I know yet. Will update as and when I get to fix that.
Update: The fix is to change the resolution to 1024×768. To do that, go to Control Panel (old style) -> Display -> Resolution

'Find My Car Smart' is the First Low Energy Bluetooth App for iPhone 4S



Earlier this year, Apple introduced a new version of Bluetooth in some of their products. This new version of Bluetooth is known as "Bluetooth Low Energy" or Bluetooth 4.0. The Mac mini and MacBook Air were the first to support the new standard with the iPhone 4Squickly following. 

The Bluetooth Low Energy specification promises a low-power and low-latency implementation that opens the door to a number of new kinds of Bluetooth-powered devices. The expectation is that low power Bluetooth transmitters/receivers will be able to send data to and from your iPhone without complicated setup. Possible examplesincluded a special watch that could receive notifications, proximity detectors, health monitors and more. 






A company called FMC Smart has just launched a Kickstarter for the first Bluetooth Low Energy App and companion module for the iPhone 4S. 

'Find My Car Smart' is a Bluetooth 4.0 take on tracking where you had parked your car. While a number of these applications already exist, those require the manual launching and marking of your car. Find My Car Smart works by pairing up against a Bluetooth 4.0 transmitter in your car and automatically tracks its last parked location.
Right now, there are apps on the iPhone that will save the location of my car, but I have to manually launch the app to drop a pin each and every time I have parked my car. Stopping to launch an app when I'm running into work or trying to catch a plane is a complete waste of time and totally annoying. So I developed an app that allows the iPhone 4S to remember the last place I parked and the only time I have to launch the app is after I've lost my car, not before.
The company posts a nice FAQ which details some of the common questions and how the product works. 

You need to install a small USB-powered Bluetooth proximity adapter in your car, which pairs with your iPhone. This proximity adapter talks to your iPhone's Find My Car Smart App running in the background. When you leave your car, it remembers this last GPS location automatically. No manual intervention is required. They claim there is only a small decrease in battery life of your iPhone due to the background operations, especially if you are only parking your car a few times a day. More extensive drivers may see more of a battery drain. 

Note that as a Kickstarter project, the Bluetooth dongles won't ship until they reach their funding goal, so we haven't been able to test the product nor are we endorsing it. The App Store companion app, however, has been approved by Apple and is already available in the App Store [$0.99]. We have downloaded that app which is shown above in screenshots. 

We should expect to see more Low Energy Bluetooth accessories and applications in the future. For now, the iPhone 4S is the only iOS device that supports the new standard.