Mail Send from iPad

This is the very simple application. In this application we will see how to mail send from the iPad.

Step 1: Create a View base application using template. Give the application name “MailComposer”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Expand classes and notice Interface Builder created the MailComposerViewController class for you. Expand Resources and notice the template generated a separate nib, MailComposerViewController.xib, for the “MailComposer”.

Step 4: We need to add MessageUI Framework. Select Frameworks folder ->Add -> Existing Framework -> Add MessageUI Framework.

Step 5: In the MailComposerViewController.h file , we have import MessageUI framework. Create an instance of UIButton class and add one buttonPressed method. So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface MailComposerViewController : UIViewController
<MFMailComposeViewControllerDelegate>
{
        IBOutlet UIButton *button;
}

(IBAction)buttonPressed;

Step 6: Double click MailComposerViewController.xib file and open it to the Interface Builder. First drag the Round Rect button from the library and place it to the view window. Connect File’s Owner icon to the View icon and select view. Drag File’s Owner icon to the round Rect button and select button and select the Round Rect button and bring up Connection Inspector next drag Touch Up Inside to the File’s Owner icon and select buttonPressed: action. Now save the MailComposerViewController.xib file, close it and go back to the Xcode.

Step 7: Open the MailComposerViewController.m file and make the following changes in the file.

(void)viewDidLoad {
        if ([MFMailComposeViewController canSendMail])
                button.enabled = YES;
}

(IBAction)buttonPressed {
        MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
        mailController.mailComposeDelegate = self;
        [mailController setSubject:@"Hello World"];
        [mailController setMessageBody:@"This is the MailSend Application…." isHTML:NO];
        [self presentModalViewController:mailController animated:YES];
        [mailController release];
}

(void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
        [self becomeFirstResponder];
        [self dismissModalViewControllerAnimated:YES];
}

Step 8: Now Compile and run the application in the Simulator.

You can Download SourceCode from here MailComposer

MapKit example in iPhone

In this application we will see how to map display and how to point out any location using latitude and longitude.

Step 1: Create a View base application using template. Give the application name “MapKitDisplay”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the MapKitDisplayViewController class for you. Expand Resources and notice the template generated a separate nib, MapKitDisplay ViewController.xib, for the “ MapKitDisplay”.

Step 4: We need to add NSObject class in the project. Select Classes -> Add -> New File -> Cocoa Touch Class -> Objective C class -> select NSObject from the Subclass of. Give the file name “DisplayMap”.

Step 5: We have added two framework in the project. Select Frameworks -> Add -> Existing Frameworks -> Add CoreLocation.framework and MapKit.framework.

Step 6: In the MapKitDisplayViewController.h file, we have import MapKit framework, and define MKMapViewDelegate protocol in the file, also add Outlet with a pointer to the MkMapView class. So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@class DisplayMap;

@interface MapKitDisplayViewController : UIViewController <MKMapViewDelegate> {
       
        IBOutlet MKMapView *mapView;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;

Step 7: Double click the MapKitDisplayViewController.xib file and open it to the Interface Builder. First drag the MapView from the library and place it to the view window. Connect File’s Owner icon to the View icon and select view. Connect File’s Owner icon to the MKMapView and select mapView. Now save the MapKitDisplayViewController.xib file, close it and go back to the Xcode.

Step 8: Open the MapKitDisplayViewController.m file and make the following changes in the file:

(void)viewDidLoad {
    [super viewDidLoad];
       
        [mapView setMapType:MKMapTypeStandard];
        [mapView setZoomEnabled:YES];
        [mapView setScrollEnabled:YES];
        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
        region.center.latitude = 22.569722 ;
        region.center.longitude = 88.369722;
        region.span.longitudeDelta = 0.01f;
        region.span.latitudeDelta = 0.01f;
        [mapView setRegion:region animated:YES];
       
        [mapView setDelegate:self];
       
        DisplayMap *ann = [[DisplayMap alloc] init];
        ann.title = @" Kolkata";
        ann.subtitle = @"Mahatma Gandhi Road";
        ann.coordinate = region.center;
        [mapView addAnnotation:ann];
}

(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
 (id <MKAnnotation>)annotation {
        MKPinAnnotationView *pinView = nil;
        if(annotation != mapView.userLocation)
        {
                static NSString *defaultPinID = @"com.invasivecode.pin";
                pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
                if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                                                                  initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

                pinView.pinColor = MKPinAnnotationColorRed;
                pinView.canShowCallout = YES;
                pinView.animatesDrop = YES;
                }
        else {
                [mapView.userLocation setTitle:@"I am here"];
        }
        return pinView;
}

We define here first, coordinate regions to zeros, Then we enter coordinates of our place that, Kolkata (Mahatma Gandhi Road), define the latitude and longitude of this place. We create an instantiate of DisplayView object and add it to our map. To do this, we add the delegate function that will display the annotations on to our map. We start by having DisplayView name a pointer we’ll call “ann.”

Step 8: In the DisplayView.h file , we have import and set CLLocation class reference to incorporate the geographical coordinates and altitude of our device. So make the following changes in the file.

#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>

@interface DisplayMap : NSObject <MKAnnotation> {

        CLLocationCoordinate2D coordinate;
        NSString *title;
        NSString *subtitle;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;

Step 9: Open the DisplayView.m file and make the following changes in the file:

#import "DisplayMap.h"

@implementation DisplayMap

@synthesize coordinate,title,subtitle;

(void)dealloc{
        [title release];
        [super dealloc];
}

Step 10: Now compile and run the application on the simulator.

You can Download SourceCode from here MapKitDisplay

How to play Video in iPad

This is the very simple application . In this application we will see how to play video in the iPad.

Step 1: Create a View base application using template. Give the application name “VideoPlay_iPad”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the VideoPlay_iPadViewController class for you. Expand Resources and notice the template generated a separate nib,VideoPlay_iPadViewController.xib, for the “VideoPlay_iPad”.

Step 4: We need to add MediaPlayer.framework in the Frameworks folder. Select-> Frameworks folder -> Add ->Existing Frameworks -> then select MediaPlayer.framework.

Step 5: In the VideoPlay_iPadViewController.h file, we have created instance of MPMoviePlayerController class, that manage the playback of a movie from a file or from the network, and create a instance of NSURL class . So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface VideoPlay_iPadViewController : UIViewController {

        MPMoviePlayerController *videoPlayer;
        NSURL *videoURL;
       
}

Step 6: Open the VideoPlay_iPadViewController.m file and make the following changes in the file.

(void)viewWillAppear:(BOOL)animated
{
        NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
        NSURL *url = [NSURL fileURLWithPath:urlStr];
        videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
        [self.view addSubview:videoPlayer.view];
        videoPlayer.view.frame = CGRectMake(0, 0,768, 1000);  
        [videoPlayer play];
}

Step 7: Now compile and run the application in the Simulator.

You can Download SourceCode from here VideoPlay_iPad

Hello World with Navigation Base application in iPhone

This is the very simple example. In this example we will see how to Hello iPhone display using navigation base application.

Step 1: Create a Navigation Base application using template. Give the application name “HelloWorld_NavigationBase”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the RootViewController class for you (See the figure below). Expand Resources and notice the template generated a separate nib,RootViewController.xib, for the “HelloWorld_NavigationBase”.

Step 4: Open the RootViewController.m file, for this example we need to add only two lines of code in this file . So make the changes.

(void)viewDidLoad {
    [super viewDidLoad];

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
     self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

  (UITableViewCell *)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   static NSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
   cell = [[[UITableViewCell alloc]   initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]    autorelease];
}

  // Configure the cell. // added below two line
    [[cell textLabel] setTextAlignment:UITextAlignmentCenter];
    [cell.textLabel setText:@"Hello iPhone!"];

   return cell;
}

Step 5: Now compile and run the application in the Simulator.

You can Download SourceCode from here HelloWorld_NavigationBase

ViewBase application in iPad

This is the simple View Base application. In this application we will display image,  button and label.

Step 1: Create a View base application using template. Give the application name “ViewBase_iPad”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the ViewBase_iPadViewController class for you. Expand Resources and notice the template generated a separate nib,ViewBase_iPadViewController.xib, for the “ViewBase_iPad”.

Step 4: In the ViewBase_iPadViewController.h file, we have created instance of UILabel and UIImage class. Define one IBAction method. So make the following changes.

#import <UIKit/UIKit.h>

@interface ViewBase_iPadViewController : UIViewController {
       
 IBOutlet UILabel *myLabel;
 IBOutlet UIImage *myImage;

}

@property(nonatomic,retain) IBOutlet UILabel *myLabel;
@property(nonatomic,retain) IBOutlet UIImage *myImage;

(IBAction)ButtonPressed:(id)sender;

Step 5: Double click the ViewBase_iPadViewController.xib file and open it to the Interface Builder.First drag the Image View from the library and place it to the View window. Next drag label and Round Rect from the library and place it to the view window. Select the Round Rect from the view window and bring up Connection iNspector. Drag from the Touch Up Inside to the File’s Owner icon and select ButtonPressed: method. Connect File’s Owner icon to the View icon and select view and connect File’s Owner icon to the label select myLabel. Now save the ViewBase_iPadViewController.xib file, close it and go back to the Xcode.

Step 6: Open the ViewBase_iPadViewController.m file and make the following changes in the file.

(IBAction)ButtonPressed:(id)sender{

myLabel.text = @"Welocome to the Real World!!!";
}

Step 7: Now compile and run the application in the Simulator.

You can Download SourceCode from here ViewBase_iPad

Download Apple WWDC 2010 Session Videos and Source Code

This might be a bit late, but just in case you missed this one and did not get the email from Apple – please do have a look! You don’t need to purchase the DVDs if you missed this years Apple WWDC session. To access them, all you need is a registered Apple developer account from – http://developer.apple.com/videos/wwdc/2010/. Grab them in both low and high definition, and if you don’t have an account ask your friendly neighbor or get on Youtube or some other video sharing sites to see what is uploaded there :)

Here is the link – Must Watch WWDC 2010 Keynotes!

Image change using touch function in iPhone

In this application we will see how to images change using touch function.

Step 1: Create a Window base application using template. Give the application name “MovingBall12”.

Step 2 : Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: We need to add UIView class i the project. Select Classes -> Add -> New File -> Cocoa Touch Class -> Objective C class -> select UIView from the Subclass of. Give the file name “BallView”.

Step 4: We have added two resources in the Resources folder. Give the name of the resource “1.png”,”2.png”.

Step 5: In the MovingBall12AppDeleagte.h file, we have added BallView class, NSTimer , so make the following changes in the file.

#import <UIKit/UIKit.h>

@class BallView;

@interface MovingBall12AppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
        BallView *ballView;
        int count;
        NSTimer *ViewTimer;
       
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet BallView *ballView;
@property (nonatomic, retain) IBOutlet NSTimer *ViewTimer;

Step 6: Open the BallView.h file, we have added UIImageView, UILabel, NSTimer, so make the following chnages:

#import <UIKit/UIKit.h>

@interface BallView : UIView {
       
        NSTimer *ViewTimer;
        UIImageView *theBall;
        UILabel *touchMe;
        CGRect touchMeFrame;
        int count,switcher;
        int directionX, directionY;
        BOOL gameRunning;
        NSArray *images;
}

@property(nonatomic,retain) NSTimer *ViewTimer;
@property(nonatomic,retain) IBOutlet UIImageView *theBall;
@property(nonatomic,retain) IBOutlet UILabel *touchMe;
@property(nonatomic,retain) NSArray *images;

@property CGRect touchMeFrame;
@property int directionX, directionY;
@property BOOL gameRunning;

Step 7: Double click the MainWindow,xib file and open it to the Interface Builder. Double click the window icon from the main window and open it , first drag the View from the library and place it to the window. Next drag label and ImageView from the library and place it to the view window. Select the View from the main window and bring up Identity Inspector and change the class name into BallView. Connect BallView to the label and select touchMe,and connect BallView to the ImageView and select the theBall (See the figure below). Now save MainWindow.xib file, close it and go back to the Xcode.

Step 8: Open the BallView.m fie make the following changes in the file.

(void)onTimer {
        CGPoint center = theBall.center;
       
        float newX = center.x + directionX;
        float newY = center.y + directionY;
       
        int rndX = rand() % 3 + 1;
        int rndY = rand() % 3 + 1;
       
        int screenX = self.frame.origin.x + self.frame.size.width;
        int screenY = self.frame.origin.y + self.frame.size.height;
       
        BOOL changed = NO;
        if (newX < 0) {
                directionX = rndX;
                newX = 0;
                changed = YES;
        } else if (newX > screenX) {
                directionX = rndX;
                newX = screenX;
                changed = YES;
        }
       
        if (newY < 0) {
                directionY = rndY;
                newY = 0;
                changed = YES;
        } else if (newY > screenY) {
                directionY = rndY;
                newY = screenY;
                changed = YES;
        }
       
        if ((rand() % 1000) > 997) {
                directionY *= 1;
                changed = YES;
        }
       
        if ((rand() % 1000) > 997) {
                directionX *= 1;
                changed = YES;
        }
       
        if (changed == YES) {
                int img = switcher++ % (int)[images count];
                theBall.image = [images objectAtIndex:img];
               
        }
       
        CGPoint newCenter = CGPointMake(newX, newY);
        [theBall setCenter:newCenter];
       
}

(void)toggleTimer:(int)withCount {
        if (withCount % 2 != 0) {
                [ViewTimer invalidate];
                touchMe.backgroundColor = [UIColor whiteColor];
                touchMe.textColor = [UIColor blackColor];
               
                               
                gameRunning = NO;
               
        } else {
                ViewTimer = [NSTimer scheduledTimerWithTimeInterval:0.0075 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];  
                touchMe.backgroundColor = [UIColor blackColor];
                touchMe.textColor = [UIColor whiteColor];
               
                gameRunning = YES;
        }
}

(void)doInitialSetup {
        sranddev();
       
        count = 0;
       
        int rndX = rand() % 3 + 1;
        int rndY = rand() % 3 + 1;
       
        directionX = rndX;
        directionY = rndY;
       
        UIImage *img1 = [UIImage imageNamed:@"1.png"];
        UIImage *img2 = [UIImage imageNamed:@"2.png"];
       
        self.images = [NSArray arrayWithObjects:img1, img2, nil];
       
        int img = (int)count % (int)[images count];
        theBall.image = [images objectAtIndex:img];
       
        gameRunning = NO;
}

(BOOL) isPointInTouchMe:(CGPoint)point {
        return (point.x >= touchMe.frame.origin.x
                        && point.x <= touchMe.frame.origin.x + touchMe.frame.size.width
                        && point.y >= touchMe.frame.origin.y
                        && point.y <= touchMe.frame.origin.y + touchMe.frame.size.height);
}

(BOOL) isPointInTheBall:(CGPoint)point {
        return (point.x >= theBall.frame.origin.x
                        && point.x <= theBall.frame.origin.x + theBall.frame.size.width
                        && point.y >= theBall.frame.origin.y
                        && point.y <= theBall.frame.origin.y + theBall.frame.size.height);
}

(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        CGPoint point = [touch locationInView:self];
       
        if ([self isPointInTouchMe:point]) {
                [self toggleTimer:count++];
        }
       
}
(void) awakeFromNib {
        [self doInitialSetup];
}

(id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
                [self doInitialSetup];
    }
    return self;
}

(void)drawRect:(CGRect)rect {
        [super drawRect:rect];
}

Step 9: Now compile and run the application on the Simulator.

You can Download SourceCode from here MovingBall12

That Flash on the iPhone

I am not quite sure how often Flash has been discussed on the iPhone and how often we have seen prototypes running on it. Given the development of HTML5 as well as the memory and battery issues that come with Flash, Flash is turning out to be a nice-to-have feature and not so much a must have. But if you really must run Flash on an iPhone, now you can, thanks to Frash that runs on jailbroken iPhones. We haven’t tested it yet, but we thought you would like to know. If you run it, keep in mind that Comex says that Frash is not what you would describe as stable.

Of course, there is now an interesting legal situation that legalizes jailbreaking, even if such a move still voids the warranty of the iPhone. We doubt that Flash will become a major deal on the iPhoen, but it is worth watching whether this story develops.

Apple is unlikely to change its opinion and if you forget Mark Papermaster’s departure from the company, it is rather quiet about the phone lately. Despite the success of Android, Apple appears to be still selling every iPhone it can make and the Apple Store still says that there is a delay between your order and actual delivery. Sterne Agee analyst Vijay Rakesh this morning told investors that Apple is likely to address this situation, especially since the iPhone 4 is making its way to a total of 88 countries by the end of September. Q3 orders have been increased to more than 10 million, according to Rakesh, which would translate into a 20% production increase over Q2.

We should see data and app use still increase over the next months. For those of you who are keeping track of the numbers, Google recently said that Android is selling some 6 million phones every month now.

That Flash on the iPhone

I am not quite sure how often Flash has been discussed on the iPhone and how often we have seen prototypes running on it. Given the development of HTML5 as well as the memory and battery issues that come with Flash, Flash is turning out to be a nice-to-have feature and not so much a must have. But if you really must run Flash on an iPhone, now you can, thanks to Frash that runs on jailbroken iPhones. We haven’t tested it yet, but we thought you would like to know. If you run it, keep in mind that Comex says that Frash is not what you would describe as stable.

Of course, there is now an interesting legal situation that legalizes jailbreaking, even if such a move still voids the warranty of the iPhone. We doubt that Flash will become a major deal on the iPhoen, but it is worth watching whether this story develops.

Apple is unlikely to change its opinion and if you forget Mark Papermaster’s departure from the company, it is rather quiet about the phone lately. Despite the success of Android, Apple appears to be still selling every iPhone it can make and the Apple Store still says that there is a delay between your order and actual delivery. Sterne Agee analyst Vijay Rakesh this morning told investors that Apple is likely to address this situation, especially since the iPhone 4 is making its way to a total of 88 countries by the end of September. Q3 orders have been increased to more than 10 million, according to Rakesh, which would translate into a 20% production increase over Q2.

We should see data and app use still increase over the next months. For those of you who are keeping track of the numbers, Google recently said that Android is selling some 6 million phones every month now.

The Foundry’s CameraTracker Giveaway!

Following Part 1 and Part 2 of the CameraTracker Overview, we conclude today with Part 3. We’ll composite our 3D light rays into our final scene with dust interaction.

We all love new plug-ins, and we all love free stuff! So, instead of just showing off The Foundry’s new CameraTracker plug-in, we figured we’d give a few licenses away to our loyal viewers! Details below!


Tutorial

Download Tutorial .flv

File size 156MB


CameraTracker Giveaway Details

We Are Giving Away:

  • 3x Licenses of The Foundry’s CameraTracker plug-in ($250 value!)

CameraTracker will allow matchmoving directly inside After Effects!

The same production tested algorithm seen in NukeX, a cutting edge VFX tool used on films such as ‘Avatar’ & ‘Iron Man II,’ right inside the After Effects environment. Invaluable for integrating VFX and motion graphics into moving camera shots!


How To Enter The Giveaway:

All you have to do is log in to your Twitter or Facebook below and tell the world what you’re after! You’ll get one entry for this…. BUT! Get this… For each person that retweets or enters through your facebook post, you’ll get another entry! We’re not gonna hack your facebook and change your gender (though we would if we knew how)… We’re just having you log into to help spread the word… that’s all. We will be closing this giveaway this Friday, the 13th at 12pm noon, EST.

Enter Through Twitter:

Enter Through Facebook:


The Foundry’s CameraTracker Giveaway!

Following Part 1 and Part 2 of the CameraTracker Overview, we conclude today with Part 3. We’ll composite our 3D light rays into our final scene with dust interaction.

We all love new plug-ins, and we all love free stuff! So, instead of just showing off The Foundry’s new CameraTracker plug-in, we figured we’d give a few licenses away to our loyal viewers! Details below!


Tutorial

Download Tutorial .flv

File size 156MB


CameraTracker Giveaway Details

We Are Giving Away:

  • 3x Licenses of The Foundry’s CameraTracker plug-in ($250 value!)

CameraTracker will allow matchmoving directly inside After Effects!

The same production tested algorithm seen in NukeX, a cutting edge VFX tool used on films such as ‘Avatar’ & ‘Iron Man II,’ right inside the After Effects environment. Invaluable for integrating VFX and motion graphics into moving camera shots!


How To Enter The Giveaway:

All you have to do is log in to your Twitter or Facebook below and tell the world what you’re after! You’ll get one entry for this…. BUT! Get this… For each person that retweets or enters through your facebook post, you’ll get another entry! We’re not gonna hack your facebook and change your gender (though we would if we knew how)… We’re just having you log into to help spread the word… that’s all. We will be closing this giveaway this Friday, the 13th at 12pm noon, EST.

Enter Through Twitter:

Enter Through Facebook:


Quick Tip: How to Create Transparent Gradients Using Blends


Introduction

It wasn’t until Illustrator CS4 that you were able to create transparent gradients. However there is a way to create them with any version of CS. By using blends, you can create a variety of radial and linear gradients, just as you can in CS4+.

Continue reading “Quick Tip: How to Create Transparent Gradients Using Blends”

Quick Tip: How to Create Transparent Gradients Using Blends


Introduction

It wasn’t until Illustrator CS4 that you were able to create transparent gradients. However there is a way to create them with any version of CS. By using blends, you can create a variety of radial and linear gradients, just as you can in CS4+.

Continue reading “Quick Tip: How to Create Transparent Gradients Using Blends”