Friday, 25 May 2012

Get Contact Name from Addressbook which have email address...

//Also you need to include AddressBook.framework
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABAddressBook.h>
#import <AddressBook/ABPerson.h>

[contactList removeAllObjects];
// open the default address book. 
ABAddressBookRef m_addressbook = ABAddressBookCreate();
if (!m_addressbook) {
    NSLog(@"opening address book");
// can be cast to NSArray, toll-free
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
// CFStrings can be cast to NSString!
for (int i=0;i < nPeople;i++) { 
MContact *contact = [[MContact allocinit];
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
CFStringRef firstName, lastName;
firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty); = [NSString stringWithFormat:@"%@ %@", firstName, lastName];

ABMutableMultiValueRef eMail  = ABRecordCopyValue(ref, kABPersonEmailProperty);
if(ABMultiValueGetCount(eMail) > 0) { =  (NSString *)ABMultiValueCopyValueAtIndex(eMail, 0);
[contactList addObject:contact];

////and here MContact is NObject (Bean) file bellow

@interface MContact : NSObject { 
NSString *email; 
NSString *name; 
NSString *lastName; 
NSString *phone; 

BOOL isSelected; 

@property (nonatomic, retain) NSString *email; 
@property (nonatomic, retain) NSString *name; 
@property (nonatomic, retain) NSString *lastName; 
@property (nonatomic, retain) NSString *phone; 

@property (nonatomic) BOOL isSelected; 
@property (nonatomic, readonly) NSString *displayName; 

Cell With Image and Title with inbuit TableCell

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        UIImageView *cellBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
        cellBg.image = [UIImage imageNamed:@"cellBgLine"];
        [cell addSubview:cellBg];
    if ([arrData count] != 0) {
        WalletList *objBean = (WalletList *)[arrData objectAtIndex:indexPath.row];
        [cell.textLabel setFont:[UIFont fontWithName:@"Helvetika" size:12.0]];
        cell.textLabel.numberOfLines = 1;
        cell.textLabel.text = objBean.wtitle;
        [cell.textLabel alignTop];
//        cell.textLabel.text = [arrData objectAtIndex:indexPath.row];
return cell;

Friday, 4 May 2012

Save image in library with only in one line....

UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);

You only need completionTarget, completionSelector and contextInfo if you want to be notified when the image is done saving, otherwise you can pass in nil.

Switch View with Programming .....

- (IBAction)switchViews:(id)sender{

    if (self.yellowViewController == nil)
        YellowViewController *yellowController = [[YellowViewController alloc]
                initWithNibName:@"YellowView" bundle:nil];
        self.yellowViewController = yellowController;
        [yellowController release];

    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    UIViewController *coming = nil;
    UIViewController *going = nil;
    UIViewAnimationTransition transition;

    if (self.blueViewController.view.superview == nil) 
        coming = blueViewController;
        going = yellowViewController;
        transition = UIViewAnimationTransitionFlipFromLeft;
        coming = yellowViewController;
        going = blueViewController;
        transition = UIViewAnimationTransitionFlipFromRight;

    [UIView setAnimationTransition: transition forView:self.view cache:YES];
    [coming viewWillAppear:YES];
    [going viewWillDisappear:YES];
    [going.view removeFromSuperview];
    [self.view insertSubview: coming.view atIndex:0];
    [going viewDidDisappear:YES];
    [coming viewDidAppear:YES];

    [UIView commitAnimations];

MapView with display multiple Annotationpin in Dynamic Rect

-(void) locateAllLocationonMap {
    MKCoordinateRegion region;
MKCoordinateSpan span;
// = currentLocation; 
    [mapView removeAnnotations:[mapView annotations]];
    for (objBean in arrFilter) { ////arrFilter is array data
        CLLocationCoordinate2D location;
        location.latitude = [objBean.gps_lat doubleValue];
        location.longitude = [objBean.gps_long doubleValue];
        addAnnotationpins = [[AnnotationPins alloc] init];
        addAnnotationpins.objEvent = objBean;
        addAnnotationpins.title = objBean.title;
        addAnnotationpins.subtitle = [NSString stringWithFormat:@"%@ to %@",objBean.start_date,objBean.end_date];
        addAnnotationpins.coordinate = location;
        [mapView addAnnotation:addAnnotationpins];
        [arrAnnMapRect addObject:addAnnotationpins]; /// arrAnnMapRect is an blank array.... = location; 
        NSString *device = [[UIDevice currentDevice] model];
        if ([device isEqualToString:@"iPhone Simulator"]) {
   = location;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
    [self setMyMapRect];
    MKMapRect flyTo = MKMapRectNull;
for (id <MKAnnotation> annotation in arrAnnMapRect) {
NSLog(@"fly to on");
        MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
        MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
        if (MKMapRectIsNull(flyTo)) {
            flyTo = pointRect;
        } else {
            flyTo = MKMapRectUnion(flyTo, pointRect);
    // Position the map so that all overlays and annotations are visible on screen.
    mapView.visibleMapRect = flyTo;