Thursday 10 November 2011

UINavigationBar and UINavigationItem background image

UINavigationBarItem Background Image


navigationController.parentViewController action:@selector(yourmethod:)];
             self.navigationItem.leftBarButtonItem.image = [UIImage imageNamed:@"leftbar.png"];

UINavigationBar Background Image

 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"header.png"] forBarMetrics:UIBarMetricsDefault];



iOS Application starts from main method

iOS application starts from main method


int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}



int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
// If nil is specified for principalClassName, the value for NSPrincipalClass from the Info.plist is used. If there is no NSPrincipalClass key specified, the UIApplication class is used. The delegate class will be instantiated using init.



Handle Orientation in iPhone/iPad


  
By default iOS5 and earlier supports only portrait mode orientation, if we want to enable all orientation we have to implement shouldAutorotateToInterfaceOrientation method in UIViewController.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES; //YES for supporting all orientation. NO- disable orientation
}

iOS have four orientations are 
   UIInterfaceOrientationPortrait
   UIInterfaceOrientationPortraitUpsideDown
   UIInterfaceOrientationLandscapeLeft    
   UIInterfaceOrientationLandscapeRight
if dont want any one orientation, then check the orientation and return NO

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(UIInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    return NO; //disable UIInterfaceOrientationLandscapeLeft orientation
else
   return YES;
}

Find device orientation changes :-

//implement this method to find the device orientation changes - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { } If your application doesn't call didRotateFromInterfaceOrientation method then you have to add your controller as child view controller in then rootview controller. - (void)viewDidLoad { [super viewDidLoad]; [self addChildViewController:(UIViewController*) self.yourChildController]; }

Changing UIView when Orientation change :-

Here i created two UIView and assigned when orientation changed. I created two dashboard UIView for portrait and landscape , get the IBOutlet from XIB 
Views.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight ) { self.view = self.LandscapeView; } else { self.view = self.portraitView; } return YES; }
Download the source code for better understanding : https://github.com/karthikprabhuA/iPhoneOrientationHandling



Launch iPhone/iPad email composer in your application


MFMailComposeViewController  class is used to editing and email, its present in MessageUI.framework.

canSendMail method is used to find whether the user has set up the device for sending email .

Here launched email composer in my application, presenting as a modal popover.

if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.navigationBar.tintColor = [UIColor redColor]; // your navigationbar color
mail.mailComposeDelegate = self;
[mail setSubject:@"Check out my iPhone/iPad app"];
[mail setMessageBody:@"<html><body>Check out <a href='http://karthik-prabhu.blogspot.in/'>iVerde</a></body></html>" isHTML:YES];
        //mail.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
       // [self setModalPresentationStyle:UIViewAnimationOptionTransitionFlipFromTop];
            [self presentViewController:mail animated:YES completion:NULL ]; //presentModalViewController deprecated from iOS5 and above 
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"App name Message" message:@"Please setup at least One email account." delegate:self cancelButtonTitle:nil      otherButtonTitles: @"OK", nil];
[alert show];
[alert release];
}





Wednesday 2 November 2011

How to get iPhone iPad System Properties

UIDevice Class is used to get the phone name, model, localizedModel, systemname, system version,orientation,battery level etc.

  [[UIDevice currentDevicename]
  [[UIDevice currentDevice] model]
  [[UIDevice currentDevicelocalizedModel]
  [[UIDevice currentDevicesystemName]
  [[UIDevice currentDevicesystemVersion]
  [[UIDevice currentDeviceorientation]
  [[UIDevice currentDevicebatteryLevel]


The main advantage is to check the battery level ;

float btlevel = [[UIDevice currentDevice] batteryLevel]; // range is from 0.0 to 1.0 UIDeviceBatteryState btstate = [UIDevice currentDevice] batteryStatus];


iOS(iPhone and iPad) Application Development for Beginner




  • First you need to learn objective C basics.
  • Should know about the iOS Framework.
  • Should know how the iOS controller works like UIViewController,UITableviewcontroller, UINavigationControler,UITabBarcontroller etc. 
  • Do some homework with all the controls with xib and programatically then you will get a clear idea.
  • If you want to become a master dont skip the basics.
  • My advise is to start with stanford tutorial (pdf and video) for iOS5 (http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2011-fall and http://itunes.apple.com/us/itunes-u/ipad-iphone-application-development/id473757255).


Here I attached Stanford iOS basics tutorial


Stanford iOS development basics tutorial

Monday 17 October 2011

iOS Architecture and its Layers


                                  iOS is derived from MacOS X,which it shares the Darwin foundation, and is a Unix operating system.
  
 iOS consist of four Abstract layers are 
  • Cocoa Touch

  • Media

  • Core Services

  • Core OS 


    Core OS

                      Core OS consist of  C API based on unix, not a object oriented. Core OS handles the following functionalities are OSX kerner,Mach 3.0, BSD, Sockets, Security,Power Management, KeyChain Access, Certificates, File System, Bonjour.

 Core Services 

                                   Core Services classes are Object Oriented.Core Services handles the following functionalities are Collections,Core Location, Address Book, Net Services, Networking, Threading, File Access, Preferences, SQLite, URL Utilities.

 Media

                    Media handles the following functionalities are Core Audio, OpenAL, Audio Mixing, Audio Recording, Video Playback, JPEG,PNG,TIFF, PDF, Quartz(2D), Core Animation, OpenGL ES.

   Cocoa Touch

                                      Cocoa Touch handles the following functionalities are Multie Picker-Touch, Core Motion, View Hierarchy, Localization, Alerts, WebView, Map Kit, Image Picker, Camera, Controls.


How to use UIPopOverController in iPad

             How to use UIPopOverController in iPad

UIPopOverController is used to show the Content as a popover, it is used in iPad to display a content temporarily. PopOver will be displayed over the existing UIView or UIButton or UIBarButton as a special type of window, Popover will remains visible until user touch outside the popover window or you dismiss programmatically.

Create TableViewController  for popover content
    UITableViewController  *tbView = [[UITableViewController alloc]initWithStyle:UITableViewStyleGrouped]; 
    tbView.delegate = self;

Create and show PopOverController :-
   UIPopoverController *listPopover = [[UIPopoverController alloc]initWithContentViewController:tbView];   //initialized with tableview controller
//displaying popover on top of UIView inherited classes
    [listPopover presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:yourUIButtonObject permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

//for dispalying popover in UIBarbuttonItem
    [listPopover presentPopoverFromBarButtonItem:yourBarbuttonItemObject 
                                  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Dismiss PopOverController :-
      [listPopover dismissPopoverAnimated:YES];   

Can set the popover content size in two methods
    1) popoverContentSize property
    2)setPopoverContentSize:animated: method  ( particularly effective when need to animate changes to     the popover’s size)

Note :-
  should handle the orientation carefully when your barbutton hidden.



Foundation Framework in iOS (iPhone/iPad)


Foundation Framework in iOS

                                Foundation framework defines base layer of the objective C classes.

 The goal of the Foundation framework is

     - Object creation and  deallocation

     - Supports Unicode strings, object persistence, and object distribution

     - Basic utility classes like NSData , NSDate , NSString etc.

     - OS independent to provide portability

NSObject is the base class for all classes in objective C. Foundation Framework classes functionalities are

  • Object creation and deallocation(NSAutoReleasePool)
  • Data storage(NSData,NSString)
  • Text and strings(NSCharacterSet,NSScanner)
  • Dates and times(NSDate, NSTimeZone, NSCalendar, NSLocale)
  • Application coordination and timing(NSNotification,NSNotificationCenter, NSNotificationQueue)\
  • Object distribution and persistence(NSPropertyListSerialization, NSCoder)
  • Operating-system services(NSThread,NSFileManager,NSProcessInfo)
  • URL loading system