Search This Blog

Tuesday, 3 November 2015

Application States

Hi,

We are about to learn all different states of an iOS app.
The system moves your app from state to state in response to actions happening throughout the system. For example, when the user presses the Home button, a phone call comes in, or any of several other interruptions occurs, the currently running apps change state in response.Following are the app states,

1. Not running : The app has not been launched or was running but was terminated by the system.

2. Inactive : The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state.

3. Active : The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.

4. Background : The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state.

5. Suspended : The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code.

When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.



fig. Change of App States


Most state transitions are accompanied by a corresponding call to the methods of your app delegate object. These methods are your chance to respond to state changes in an appropriate way. These methods are listed below, along with a summary of how you might use them. 






Thursday, 17 April 2014

Localization

Hi,

Today i will guide you to make your app to support different languages in the same app.

To support Localization in the app, there are two ways :

    First, is to create separate .xib files or create new storyboard for other language for eg. Hebrew. It means if we want to have English and Hebrew version of the app,then we will need to create 2 separate .xibs for each controller or if we are using storyboard then need to create 2 separate storyboard files for each language. Here, for every .xib ,we have to set the "text" as per the language. Eg. if we have label on the .xib say "titleLabel" for ENGLISH language, then we will set the "text" property in property window as "This is a Label" in English. But for other .xib, which is in HEBREW,its label title would be set as "זה מדבקה" in Hebrew and same with other tools.

    Second, is to have only 1 xib for all languages or only 1 storyboard file for all languages we are going to support in our app.Here, for every tool we have to set IBOUTLets,so that their values would be set through code(run-time),not on .xib.

The Second method is preferred,so i will explain you the same.

1. Click on the Project name > your project name under PROJECTS > Info > Go to Localizations             option. You would see default language as "English".Go down you would see "+" sign,select your       language to support in the app apart from English, in our eg "Hebrew".

2. We set Language for the entire app.Now we would set all the images we would be using in app.So       drag all images into the app.Now select images one by one and go to property window and click on        "Localize..." button under "Localization" section.Select Localize button on Popup.Now select the         same image again and see tow languages would appear under "Localization" section in property             window.

3. You would see that the image precedes with arrow to open.Click on it,you would see 2 images for 2     different languages.Click on "Hebrew" image > right click > "show in finder" replace this english         version image with respective "Hebrew" image for it.Thus, you would see "Hebrew" image                   here.Repeat the same procedure for all images.We are done with images now.

4.Now for Text like label text,button title etc. we need to add Localizable.string file in app and repeat        the same procedure we did for images so you would have 2 files inside Localizable.string.
   Here you would add "Key-Value" pair in both the files.Eg. We would write
    "SAVE" = "SAVE"; 
    entry for the text "SAVE" in English file.Here, First is a "key" and second is its "value".

   Now for the same eg, we would have,
   "SAVE" = "KAYDET";
   entry would be in Hebrew file.Here key is "SAVE" and its value is "KAYDET".

5.We create 2 Localizable.string file for both languages which has all the ENG and Hebrew text we          would use in app.Now we would see how to use it.


      NSLocalizedString(@"SAVE", nil) 
  
  using this method we would get test as SAVE or KAYDET based on language you set on the device.

so for "titleLabel" would set as ,

titleLabel.text = NSLocalizedString(@"SAVE", nil) ;

if device language is Eng then it would return SAVE else KAYDET.

That's it. You are done.

Feel free to ask questions...

Thank you :)


Scroll up view when keyboard appears

Hi,

Here I am about to help you to tackle the textfield or textview invisibility problem when keyboard appears on the screen.There are 2 delegate methods related to UITextfield and UITextView.You just have to move the current view up slightly to make the controls visible.

Here are the 2 delegates of UITextField.

1. Just declare  
   
          CGFloat animatedDistance;
     in viewController.h file.

2. Add these Constants as well,

          static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
          static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
          static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
          static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 240;
          static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 140;

3. Finally,add the UITextField delegates in your viewController.m as below,

    - (void)textFieldDidBeginEditing:(UITextField *)textField
    {    
         CGRect textFieldRect =
         [self.view.window convertRect:textField.bounds fromView:textField];
         CGRect viewRect =
         [self.view.window convertRect:self.view.bounds fromView:self.view];
         CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
         CGFloat numerator =
            midline - viewRect.origin.y
           - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
        CGFloat denominator =
              (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)
                 * viewRect.size.height;
        CGFloat heightFraction = numerator / denominator;

       if (heightFraction < 0.0){

             heightFraction = 0.0;

        }else if (heightFraction > 1.0) {

                  heightFraction = 2.0;
        }
     
        UIInterfaceOrientation orientation =
               [[UIApplication sharedApplication] statusBarOrientation];
 
        if (orientation == UIInterfaceOrientationPortrait ||
                        orientation == UIInterfaceOrientationPortraitUpsideDown)
        {
                animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
         }
        else
        {
              animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
        }


        CGRect viewFrame = self.view.frame;
        viewFrame.origin.y -= animatedDistance;
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
    
        [self.view setFrame:viewFrame];
    
        [UIView commitAnimations];
    }


    - (void)textFieldDidEndEditing:(UITextField *)textField
    {
    
        if(self.view.frame.origin.y == 0)
              return;
    
        if (animatedDistance == 0.0)
             return;
    
         CGRect viewFrame = self.view.frame;
         viewFrame.origin.y += animatedDistance;
    
         [UIView beginAnimations:nil context:NULL];
         [UIView setAnimationBeginsFromCurrentState:YES];
         [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
    
         [self.view setFrame:viewFrame];
    
         [UIView commitAnimations];
    
         animatedDistance = 0.0;

     }

You are done !

For UITextView you have to replace above delegate methods with

- (void)textViewDidBeginEditing:(UITextView *)textVield and
- (void)textViewDidEndEditing:(UITextView *)textView

respectively.



Feel free to comment. Thanks :)

Monday, 15 July 2013

Customising and using UIFonts

Hi Friends,

I am going to explain you how to add and use customised UIFonts in our app.

When you have UIFont files such as .otf etc. you can simply use it in your code.

Lets start with following steps,

1.Add all UIFont files (.otf etc) in project bundle (drag and drop in project) and select copy and add to Target.It will show the fonts in project.

2.Go to .plist file of your project and create Array new entry as 'Fonts provided by application'.

3.Add key in that item 0,item 1,etc. based on your number of fonts you want to use and their values should be the names of Font files.for eg. Value of item 0 can be 'MyriadPro-Regular.otf' etc.Here, 'MyriadPro-Bold' is the name of font.

We are done with it.Now we need to use this fonts.Its the normal way you are setting UIFonts.

If I want to set the custom font to tableView cell then I write,


            cell.textLabel.font = [UIFont fontWithName:@"MyriadPro-Regular" size:20];

In this way you can simply use this fonts in your code.

Feel free to comment.

Happy coding :)





Tuesday, 11 June 2013

New Features Of iOS 7

Hi,
Apple just changed the operating system for the iPhone and iPad in a big way. On Monday at its World Wide Developers Conference, Apple unveiled iOS 7, a redesigned version of the software that runs its mobile devices. It is almost everything that we expected from Apple… and a little bit more.
Apple has several primary new features in iOS 7 to go along with a new design from its top developer, Jony Ive. The new iOS is sleeker and has gone “flat,” eschewing shadows and real-life objects (like notebooks and bookshelves) to give the operating system a more modern look, which is a big departure from how Apple has presented iOS in the past. 

Outside the simplified design, here are the biggest new features to in iOS 7:

Multi-tasking: Apple has brought multi-tasking to every single app, not just a select few. The new multi-tasking features will allow apps to interact with the operating system and sometimes other apps. A new multi-tasking application programming interface (API) will allow all apps to run in the background and allow users to switch between apps. iOS 7 will know what apps that consumers use most and keep those running in the background.



Control Center: The new settings menu for iOS that will control features such as Wi-Fi, Bluetooth, mute, screen brightness and so forth. If you are familiar with Google’s Android operating system, the iOS 7 Control Center will seem quite familiar, but instead of accessing the settings by dragging from the top of the smartphone screen, users in iOS 7drag from the bottom. 


Notification Center: The drop-down notification center is now available from the lock screen on your iOS device and will provide you with details of your day, such as calendar appointments or weather updates. 



AirDrop: This is a new content sharing feature that works wirelessly. AirDrop allows you to share content with your contacts that are close to you. Select who you want to share with, select what you want to share and AirDrop will send that content to the person. By doing it through Wi-Fi or cellular data, Apple has essentially said that Near Field Communications (NFC, a technology that allows sharing with a “tap”) is not coming to the new iPhone later this year.


Camera features: Apple has long been known to push the camera functionality of its iPhones. We will likely see more of what Apple has up its sleeve with its camera when the new iPhone is announced later this year. But iOS 7 gives us a sneak peek. Apple thinks it is four cameras in one as it has several different settings like a “square mode.” The other three modes of the camera are video, normal photos and panorama. Users will be able to flip between the different modes with a swipe.



Photo gallery: More than any other new feature in iOS 7, the photo gallery benefits from Apple’s personal cloud product, iCloud. The Photos app features the iCloud Photo Stream that aggregates all of your pictures through the years into one long timeline. The iCloud Photo Stream will allow users to easily share photos with other iCloud users.



Safari: Apple could not update its mobile operating system without giving its browser a big update. Mobile Safari should be faster, have simplified search and a new browser tab interface that is based on rotating tiles. It will also save your passwords with the iCloud Keychain and has enhanced parental controls.



Siri: Apple’s virtual assistant got a little bit better. Siri now hooks straight to Twitter, Wikipedia and Microsoft’s Bing search engine. Users will also be able to control device features straight from Siri, such as turning on Wi-Fi or adjusting screen brightness. Siri will also have male and female voices as well as being available in several new languages. Siri will also have new features for automobiles.

iTunes Radio: The worst-kept secret before the WWDC keynote was the fact that Apple was coming out with a streaming radio music player. The rumors were not quite right in calling it iRadio though, as the new music app’s streaming capabilities are called iTunes Radio. It is similar to Pandora or Spotify’s radio app and has distinct similarities to Google’s Play All Access music service. iTunes Radio is meant for music discovery and will be free to users. If you are an iTunes subscriber, it will be served without advertisements.



Auto Updates For Apps: No longer will your iOS device has a long backlog of apps that you have not gotten around to updating. Apple will now update those apps automatically for you. 
Apple also has a slew of secondary features in iOS 7 such as an “Activation Lock” for the “Find My iPhone” feature that integrates your iCloud Apple ID password to thwart people from stealing your phone and accessing your information. Night Mode responds to ambient light and adjusts the brightness of the screen to help you see. 


Apple has nearly 1,500 new software developer kit (SDK) features for developers to access within iOS 7. That is a fairly considerable update. Developers will have access to iOS 7 beta today and users will see it this fall when Apple releases the next iPhone. 

Thursday, 30 May 2013

Customize Grid view with Images iOS

Hi,

I am going to explain you here how to create Grid view of image view and buttons that allows us to select any images,mark selected and recognize which image was selected.I am using NOT using UITableView,just using UIImageViews and UIButtons to create Grid.

Here is the grid you will see before you select any image :


Next,the grid you will see after you select any images :

Lets start,

1.Create a master details navigation project or any project.I used storyboard in sample.
2.Drag and drop any images into your project to present those in grid.

 We are creating grid with uiimages and uibuttons programmatically adding it onto the uiview setting x,y coordinates.We are adding scroll view as because we may have thousands of images to display.

3.Go to DetailViewController.h, where you want to create grid and add following,

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
{
    UIScrollView *myScrollView;
    UIImageView *image;
NSMutableArray *arr_Images;
    NSMutableArray *arr_isImagesChecked;

UIButton *btn_imageBackground;

}
@property (strong, nonatomic) id detailItem;
@property (nonatomic,retain) UIScrollView *myScrollView;
@property (nonatomic,retain) UIImageView *image;
@property (nonatomic,retain) UIButton *btn_imageBackground;

@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;

- (IBAction)btnImageClicked:(id)sender;

@end 

Here we are declaring controls.

4.Open DetailViewController.m and add,


#import "DetailViewController.h"

@interface DetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end

@implementation DetailViewController
@synthesize myScrollView;
@synthesize image;
@synthesize btn_imageBackground;

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;
        
        // Update the view.
        [self configureView];
    }

    if (self.masterPopoverController != nil) {
        [self.masterPopoverController dismissPopoverAnimated:YES];
    }        
}

- (void)configureView
{
    // Update the user interface for the detail item.
       self.myScrollView.backgroundColor=[UIColor blackColor];
        int x=10,y=10;
        
        for (int i=0; i<[arr_Images count]; i++) {
            //NSLog(@"IN FOR index i = %d",i);
            //NSLog(@"Array count %d",[arr_Images count]-1);
            
            if (x > 300) {
                x=10;
                y=y+50;

                image =[[UIImageView alloc]initWithImage:[UIImage imageNamed:[arr_Images objectAtIndex:i]]];
                image.frame=CGRectMake(x, y, 45, 45);
                
                               
                btn_imageBackground=[UIButton buttonWithType:UIButtonTypeCustom] ;
                btn_imageBackground.frame=CGRectMake(x, y, 45, 45);
                [btn_imageBackground addTarget:self action:@selector(btnImageClicked:) forControlEvents:UIControlEventTouchUpInside];
                x=x+50;
            }
            else {
                
                image =[[UIImageView alloc]initWithImage:[UIImage imageNamed:[arr_Images objectAtIndex:i]]];
                image.frame=CGRectMake(x, y, 45, 45);
                
                               
                btn_imageBackground=[UIButton buttonWithType:UIButtonTypeCustom] ;
                btn_imageBackground.frame=CGRectMake(x, y, 45, 45);
                [btn_imageBackground addTarget:self action:@selector(btnImageClicked:) forControlEvents:UIControlEventTouchUpInside];
                x=x+50;
                
            }
            image.tag=i;
            btn_imageBackground.tag=i;
            
            [self.myScrollView addSubview:image];
            [self.myScrollView addSubview:btn_imageBackground];
            [self.view addSubview:myScrollView];
            
        }
    

}
- (IBAction)btnImageClicked:(id)sender
{

    if ([[arr_isImagesChecked objectAtIndex:[sender tag]] intValue]) {
        //image selected so deselect it
        [sender setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [arr_isImagesChecked replaceObjectAtIndex:[sender tag] withObject:[NSNumber numberWithUnsignedInteger:0]];
    }else{
    //image not selected so select it by adding checked image onto the UIbutton
        [sender setImage:[UIImage imageNamed:@"Overlay.png"] forState:UIControlStateNormal];
        [arr_isImagesChecked replaceObjectAtIndex:[sender tag] withObject:[NSNumber numberWithUnsignedInteger:1]];
        NSLog(@"%@",arr_isImagesChecked );
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

//Initialize array of images with images
        arr_Images =[[NSMutableArray alloc]initWithObjects:@"images-1.jpeg",@"images-2.jpeg",@"images-3.jpeg",@"images-4.jpeg",@"images1.jpg",@"images2.jpg",@"images3.jpg",@"images4.jpg",@"images-1.jpeg",@"images-2.jpeg",@"images-3.jpeg",@"images-4.jpeg",@"images1.jpg",@"images2.jpg",@"images3.jpg",@"images4.jpg",@"images-1.jpeg",@"images-2.jpeg",@"images-3.jpeg",@"images-4.jpeg",@"images1.jpg",@"images2.jpg",@"images3.jpg",@"images4.jpg",nil];
    arr_isImagesChecked = [[NSMutableArray alloc] init];
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    myScrollView = [[UIScrollView alloc]   initWithFrame:CGRectMake(0, 0, 320, screenBounds.size.height)];
myScrollView.contentSize = CGSizeMake(1, [arr_Images count]*10);

// Initialize array of flag to 0
    for (int i=0; i<[arr_Images count]; i++) {
        [arr_isImagesChecked insertObject:[NSNumber numberWithUnsignedInteger:0] atIndex:i];
    }

    [self configureView];  
}

@end


that's it.Just run the code you will get the output.You can download the code from here.
If you need help,feel free to comment.Happy coding :)

Wednesday, 20 March 2013

Toast Message iOS

Hi,
I am going to show you here how to use Toast message and disappear it automatically after some interval.Many users do not want to use UIAlertView because it needs to close manually.Toast shows the message on the screen for the time we specified and will dismiss automatically after time is up.I have not customized the Toast but i am using some files to show the message in Toast.

Steps :
1. Download two files Toast+UIView.h & Toast+UIView.m from here  and add those in project.
2.Link against QuartzCore.
If you are using ARC,then you will need to add the    -fno-objc-arc compiler flag to  Toast+UIView.m.

3.Now in your project,import the files and use the code as per your specifications,


// basic usage
[self.view makeToast:@"This is a piece of toast."];

// toast with duration, title, and position
[self.view makeToast:@"This is a piece of toast with a title." 
             duration:3.0
             position:@"top"
                title:@"Toast Title"];

// toast with an image
[self.view makeToast:@"This is a piece of toast with an image." 
            duration:3.0
            position:[NSValue valueWithCGPoint:CGPointMake(110, 110)]
               image:[UIImage imageNamed:@"toast.png"]];

// display toast with an activity spinner
[self.view makeToastActivity];

Thats it.We are done.
If you face any issue then please comment.
Happy Coding...!

Thursday, 7 March 2013

NSUserDefaults iOS

Hi ,


In this tutorial, I will be showing you how you can save and retrieve different types of data using the NSUserDefaults object. Saving this way is great for when you want to save small amounts of data such as High Scores, Login Information, and program state.

With the NSUserDefaults class, you can save settings and properties related to application or user data. For example, you could save a profile image set by the user or a default color scheme for the application. The objects will be saved in what is known as the iOS “defaults system”. The iOS defaults system is available throughout all of the code in your app, and any data saved to the defaults system will persist through application sessions. This means that even if the user closes your application or reboots their phone, the saved data will still be available the next time they open the app!

Saving to the NSUserDefaults is great because it does not require any special database knowledge. So if you don’t want/have an SQLite3 database for your app, this would be the way to go.



How to store/save data in NSUserDefaults :



NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// store a NSString
[userDefaults setObject:@"TextToSave" forKey:@"keyToLookupString"];
// store an NSInteger
[userDefaults setInteger:42 forKey:@"integerKey"];
// store a Double
[userDefaults setDouble:3.1415 forKey:@"doubleKey"];
// store a Float
[userDefaults setFloat:1.2345678 forKey:@"floatKey"];
// This is suggested to synch userDefaults
[userDefaults synchronize];
Your stored now.You can retrive it whenever you need.



To Retrieve stored data from NSUserDefaults :

NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [userDefaults stringForKey:@"
keyToLookupString"];
// getting an NSInteger
NSInteger myInt = [userDefaults integerForKey:@"
integerKey"];
// getting an Float
float myFloat = [userDefaults floatForKey:@"
floatKey"];
You just retrieved the values stored.
If you have any questions or comments, feel free to leave them in the comments section of this post. Happy iCoding!

Thursday, 6 December 2012

Fetch Contacts in iOS 6.0 and Lower versions iPhone,iOS

Hi All,

Here I will show you how iOS 6.0 and its lower version differs in AddressBookRef to fetch the contacts.I am going to explain you with the code.Following is the explanation,
This code works on iOS 6.0 as well as on lower versions to fetch the contacts.

We need to declare the macro which stores the iOS version of connected device.
Following macros does this,


#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

after declaring macros whenever you want to fetch the contacts,just write below code,
-(void) didLoad {

// It compares whether current iOS version is than 6.0  
  if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
        NSLog(@"<6.0");
       
        //Code to fetch Contacts from lower version of iOS

        ABAddressBookRef UsersAddressBook = ABAddressBookCreate();
        
        
        
        //contains details for all the contacts
        CFArrayRef ContactInfoArray = ABAddressBookCopyArrayOfAllPeople(UsersAddressBook);
        
        //get the total number of count of the users contact
        CFIndex numberofPeople = CFArrayGetCount(ContactInfoArray);
        
        //iterate through each record and add the value in the array
        for (int i =0; i<numberofPeople; i++) {
            ABRecordRef ref = CFArrayGetValueAtIndex(ContactInfoArray, i);
            ABMultiValueRef names = (NSString*)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
            ABMultiValueRef lastname=(NSString*)ABRecordCopyValue(ref, kABPersonLastNameProperty);
            
            ABMultiValueRef emailMultiValue = ABRecordCopyValue(ref, kABPersonEmailProperty);
            NSArray *emailAddresses = [(NSArray *)ABMultiValueCopyArrayOfAllValues(emailMultiValue) autorelease];
            
            
            ABMultiValueRef multi = ABRecordCopyValue(ref, kABPersonPhoneProperty);
            
            NSArray *no2 = [(NSArray*)ABMultiValueCopyArrayOfAllValues(multi) autorelease];
            
            ABMultiValueRef fullName=[NSString stringWithFormat:@"%@ %@",names,lastname];
          
            
            for (int i=0; i<[no2 count]; i++) {
                [arr_name addObject:fullName];
                [arr_ContactsInfo addObject:[no2 objectAtIndex:i]];
            }
            for (int i=0; i<[emailAddresses count]; i++) {
                [arr_name addObject:fullName];
                [arr_ContactsInfo addObject:[emailAddresses objectAtIndex:i]];
            }
            
            
        }

    }else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
        NSLog(@">=6.0");

        //When Current iOS >= 6.0 
        ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
        
        if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
            ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
                // First time access has been granted, add the contact
                //contains details for all the contacts
                CFArrayRef ContactInfoArray = ABAddressBookCopyArrayOfAllPeople(addressBookRef);
                
                //get the total number of count of the users contact
                CFIndex numberofPeople = CFArrayGetCount(ContactInfoArray);
                
                //iterate through each record and add the value in the array
                for (int i =0; i<numberofPeople; i++) {
                    ABRecordRef ref = CFArrayGetValueAtIndex(ContactInfoArray, i);
                    ABMultiValueRef names = (NSString*)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
                    ABMultiValueRef lastname=(NSString*)ABRecordCopyValue(ref, kABPersonLastNameProperty);
                    
                    ABMultiValueRef emailMultiValue = ABRecordCopyValue(ref, kABPersonEmailProperty);
                    NSArray *emailAddresses = [(NSArray *)ABMultiValueCopyArrayOfAllValues(emailMultiValue) autorelease];
                    //    CFRelease(emailMultiValue);
                    
                    
                    ABMultiValueRef multi = ABRecordCopyValue(ref, kABPersonPhoneProperty);
                    
                    //  ABMultiValueRef no = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
                    NSArray *no2 = [(NSArray*)ABMultiValueCopyArrayOfAllValues(multi) autorelease];
                                       
                    ABMultiValueRef fullName=[NSString stringWithFormat:@"%@ %@",names,lastname];
                    // [arr_name addObject:fullName];
                    //[arr_name addObject:fullName];
                    
                    for (int i=0; i<[no2 count]; i++) {
                        [arr_name addObject:fullName];
                        [arr_ContactsInfo addObject:[no2 objectAtIndex:i]];
                    }
                    for (int i=0; i<[emailAddresses count]; i++) {
                        [arr_name addObject:fullName];
                        [arr_ContactsInfo addObject:[emailAddresses objectAtIndex:i]];
                    }
                    
                    
                    
                }
                
            });
        }
        
     }
     else {
            // The user has previously denied access
            // Send an alert telling user to change privacy setting in settings app
        }


    }

}
If you run the code on iOS < 6.0 it will run as normally and will store the names in arr_name and arr_ContactsInfo array but if you run this code in iOS >= 6.0,it will will ask for the permission from the user whether to allow to fetch contacts.If permission granted,then will store the data in those array.

Happy coding :)