Translate

Monday, April 2, 2012

WebView Application in iPhone

In this application we will see how to WebView display in the view window . So let see how it will worked.
Step 1: Open the Xcode, Create a new project using View Base application. Give the application “MapViewiPhone”.
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 ViewController class for you. Expand Resources and notice the template generated a separate nib, MapViewiPhoneViewController.xib for the MapViewiPhone application.
Step 4: We need to add MapKit.framework in the Frameworks folder.
Step 5: Open the MapViewiPhoneViewController.h file and make the following changes:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewiPhoneViewController : UIViewController {
 
    IBOutlet MKMapView *map;
   
}
@property(nonatomic, retain) IBOutlet MKMapView *map; @end
Step 6: Double click the MapViewiPhoneViewController.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 window and select map. Now save the .xib file, close it , and go back to the Xcode.
Step 7: Open the MapViewiPhoneViewController.m file and make the following changes:
#import "MapViewiPhoneViewController.h"
@implementation MapViewiPhoneViewController @synthesize map;
- (void)dealloc
{
    [super dealloc];
}
- (void)didReceiveMemoryWarning
{

    [super didReceiveMemoryWarning];
   
}
#pragma mark – View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
   
        map.mapType = MKMapTypeSatellite;
        map.mapType=MKMapTypeStandard;
       
}
- (void)viewDidUnload
{
    [super viewDidUnload];
   
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Step 8: Now compile and run the application on the Simulator.



You can Download SourceCode from here MapViewiPhone

Programmatically Segmented Control in iPhone

In this application we will see how to implement Segmented Control programmatically in iPhone. So let see how it will
worked.
Step 1: Open the Xcode, Create a new project using View Base application. Give the application
“ProgrammaticallySegmentedControl”.
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 FirstViewController and SecondViewController class
for you. Expand Resources and notice the template generated a separate nib,
ProgrammaticallySegmentedControlViewController.xib for the ProgrammaticallySegmentedControl application.
Step 4: Open the ProgrammaticallySegmentedControlViewController.m file and make the following changes:

#import "programmaticallySegmentedControlViewController.h"
#define HeightSegmControl 40.0
#define TextHeight 30.0
#define LeftMargin 30.0
#define RightMargin 30.0
#define TweenMargin 30.0
@implementation programmaticallySegmentedControlViewController
- (void)SegmentControl
{
NSArray *text = [NSArray arrayWithObjects: @" Segmented", @"Control", @"iPhone", nil];
CGFloat yPlacement = (TweenMargin * 3.0) + HeightSegmControl;
CGRect frame=CGRectMake(LeftMargin, yPlacement, self.view.bounds.size.width-(RightMargin *
3.0),TextHeight);
UISegmentedControl *control= [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects: nil]];
control = [[UISegmentedControl alloc] initWithItems:text];
control.frame = frame;
//control.selectedSegmentIndex = 0;
[self.view addSubview:control];
[control release];
// label
//yPlacement += (mTweenMargin * 3.0) + mSegmentedControlHeight;
control = [[UISegmentedControl alloc] initWithItems:text];
frame = CGRectMake(LeftMargin,yPlacement,self.view.bounds.size.width-(RightMargin *
2.0),HeightSegmControl);
control.frame = frame;
control.segmentedControlStyle = UISegmentedControlStyleBar;
//control.tintColor = [UIColor colorWithRed:0.80 green:0.171 blue:0.5 alpha:1.0];
control.selectedSegmentIndex = 1;
[self.view addSubview:control];
[control release];
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
#pragma mark – View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
[self SegmentControl];
}
- (void)segmentAction:(id)sender
{}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
 
 
Step 5: Now Compile and run the application on the Simulator.




You can Download SourceCode from here
 
 

Table View Application in iPhone

In this application we will see how to content delete , edit from the Table View. So let see how it will worked.
Step 1: Open the Xcode, Create a new project using View Base application. Give the application “TableView”.
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 FirstViewController and SecondViewController
class for you. Expand Resources and notice the template generated a separate nib, TableViewViewController.xib for the TableView application.

Step 4: Open the TableViewAppDelegate.m file make the following changes:

#import "TableViewAppDelegate.h"
#import "TableViewViewController.h"
@implementation TableViewAppDelegate
@synthesize window=_window;
@synthesize viewController=_viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)
launchOptions
{
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:_viewController];
[self.window addSubview:navController.view];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
@end
 
Step 5: Open the TableViewViewController.h file make the following changes:
#import <UIKit/UIKit.h>
@interface TableViewViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *tableView1;
NSMutableArray *arry;
}
- (IBAction) EditTable:(id)sender;
@end
 
Step 6: Double click the TableViewViewController.xib file and open it to the Interface Builder. First drag the table view from the library and place it to the view window.Select the Table View from the view and bring up Connection Inspector and connect datasource to File’s owner icon and delegate to the File’s owner icon. Now save the .xib file, close it and go back to the Xcode.
Step 7: Open the TableViewViewController.m file make the following changes:

#import "TableViewViewController.h"
@implementation TableViewViewController
- (void)viewDidLoad
{
arry = [[NSMutableArray alloc]
initWithObjects:@"iPhone",@"MacMini",@"iMac",@"MacBookProAir",@"MacBookPro",nil];
self.title = @"Table View ";
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit"
style:UIBarButtonItemStyleBordered target:self action:@selector(EditTable:)];
[self.navigationItem setLeftBarButtonItem:addButton];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)dealloc
{
[super dealloc];
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int count = [arry count];
if(self.editing) count++;
return count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
int count = 0;
if(self.editing && indexPath.row != 0)
count = 1;
if(indexPath.row == ([arry count]) && self.editing)
{
cell.textLabel.text = @"ADD";
return cell;
}
cell.textLabel.text = [arry objectAtIndex:indexPath.row];
return cell;
}
- (IBAction)AddButtonAction:(id)sender
{
[arry addObject:@"MacBookPro "];
[tableView1 reloadData];
}
- (IBAction)DeleteButtonAction:(id)sender
{
[arry removeLastObject];
[tableView1 reloadData];
}
- (IBAction) EditTable:(id)sender
{
if(self.editing)
{
[super setEditing:NO animated:NO];
[tableView1 setEditing:NO animated:NO];
[tableView1 reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Edit"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else
{
[super setEditing:YES animated:YES];
[tableView1 setEditing:YES animated:YES];
[tableView1 reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Done"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:
(NSIndexPath *)indexPath
{
if (self.editing == NO || !indexPath) return UITableViewCellEditingStyleNone;
if (self.editing && indexPath.row == ([arry count]))
{
return UITableViewCellEditingStyleInsert;
} else
{
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)
editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[arry removeObjectAtIndex:indexPath.row];
[tableView1 reloadData];
} else if (editingStyle == UITableViewCellEditingStyleInsert)
{
[arry insertObject:@"MacBookPro" atIndex:[arry count]];
[tableView1 reloadData];
}
}
#pragma mark Row reordering
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
@end
Step 8: Now Compile and run the application on the Simulator.

 you can download source code here: www.edumobile.org/iphone/wp-content/uploads/2011/09/TableView.zip






How to Receive data from the Server in iPhone

In this application we will see how to receive data from the server. This is the simple login application and when you login in the screen it will display the message, whatever we set in the server page. So let see how it will be worked.
In this application we will see how to receive data from the server. This is the simple login application and when you login in the screen it will display the message, whatever we set in the server page. So let see how it will be worked.
Step 1: Create a View base application using template. Give the application name “SendReceiveData”.
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 SendReceiveDataViewController class for you. Expand Resources and notice the template generated a separate nib, SendReceiveDatayViewController.xib, for the “SendReceiveData”.
Step 4: In the SendReceiveDataViewController.h file, we have added UITextField, UILabel, and one buttonClick method. So make the following changes in the file.
#import <UIKit/UIKit.h> @interface SendReceiveDataViewController :
UIViewController<UITextFieldDelegate> {
        IBOutlet UITextField *nameInput;
        IBOutlet UITextField *passInput;
        IBOutlet UILabel *greeting;
        NSMutableData *webData;
       
}
@property(nonatomic, retain) IBOutlet UITextField *nameInput;
@property(nonatomic, retain) IBOutlet UITextField *passInput;
@property(nonatomic, retain) IBOutlet UILabel *greeting;
@property(nonatomic, retain) NSMutableData *webData;
-(IBAction)buttonClick: (id) sender;
Step 5: Double click the SendReceiveDataViewController.xib file and open it to the Interface Builder. Drag three labels, one Round Rect Button and two TextField from the library and place it to the view window(See the figure below). Connect File’s Owner icon to the view icon and select view and drag File’s Owner icon to the “Input Your Values” and select greeting . Next drag File’s Owner icon to the first text field and select nameInput,do the same thing for the next text field and select passInput. Select the login button and bring up Connection Inspector and drag TouchUpInside to the File’s Owner icon and select buttonClick: action. Now save the SendReceiveDataViewController.xib file, close it and go back to the Xcode.

Step 6: Open the SendReceiveDataViewController.m file and make the following changes in the file:
-(IBAction)buttonClick:(id)sender
{
       
        NSString* username = nameInput.text;
        NSString* pass = passInput.text;
       
        if([nameInput.text isEqualToString:@"" ]|| [passInput.text isEqualToString:@""])
        {
               
                greeting.text = @"Input Your Value";
                [nameInput resignFirstResponder];
                [passInput resignFirstResponder];
                return;
        }
       
        NSString *post =
        [[NSString alloc] initWithFormat:@"uname=%@&pwd=%@",username,pass];
       
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
       
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
       
        NSURL *url = [NSURL URLWithString:@"http://www.chakrainteractive.com/mob/iphone/login/chckusr.php"];
        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
        [theRequest setHTTPMethod:@"POST"];
        [theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [theRequest setHTTPBody:postData];     
       
       
        NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
       
        if( theConnection )
        {
                webData = [[NSMutableData data] retain];
        }
        else
        {
               
        }
       
        [nameInput resignFirstResponder];
        [passInput resignFirstResponder];
        nameInput.text = nil;
        passInput.text = nil;
       
} -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
        [webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
       
       
        [webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
       
        [connection release];
        [webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
       
        NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
        NSLog(loginStatus);
        greeting.text = loginStatus;
        [loginStatus release];
       
       
       
        [connection release];
        [webData release];
}
Step 7: Now compile and run the application in the Simulator.

                                                              

Sunday, April 1, 2012

To create adhoc for device

STEP 1:  Sign in with your app id
STEP 2:  Create app id(if we don't have)
STEP 3:  Give app id name, select bundle seed id, and bundle identifier
STEP 4:  Provisioning--->distribution--->distribution method--->adhoc
STEP 5:  get device id from itunes--> device UID
STEP 6:  device--->add device

        ********* XCode**********
STEP 7:  Create plist though  new file--->resource--->property list
STEP 8:  Root--->get-task-allow  Boolean(Don't enable that)
STEP 9:  Project Info--->Config Tab--->Duplicate--->appstore(Distribution)/adhoc(Adhoc Distribution)
                    --->Build Tab--->Config--->Select Adhoc Distribution--->type code---> any ios--->select create provisioning profile
STEP 10:  Target--->Project Info--->Properties tab--->give bundle identifier name(com.____.___ name)
                        Build tab--->type code---> any ios--->select create provisioning profile
STEP 11:  Products--->project name.app--->reveal in finder--->get project build file