Wednesday 26 June 2013

iOs question

1. What are the Application states. Explain them?
Answer : 
Not running State:  The app has not been launched or was running but was terminated by the  system.if its background and crash.
Inactive state: 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. The only time it stays inactive for any period of time is when the user locks the screen or the system prompts the user to respond to some event, such as an incoming phone call or SMS message. Generally  call VoIP support application.
Active state: The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.User work on its.
Background state:  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. For information about how to execute code while in the background, see “Background Execution and Multitasking.” Most of location based application.
Suspended state: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.like its receive push notification.
More
-----------------------------------------------------------------------------------------------------------

2. Difference between shallow copy and deep copy?
Answer :
Shallow copy is also known as address copy. In this process you only copy address not actual data while in deep copy you copy data.

-----------------------------------------------------------------------------------------------------------


3. Whats the difference between frame and bounds?
Answer :
The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within. The bounds of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).
What is difference between NSNotification and delegate?
Delegate is passing message from one object to other object. It is like one to one communication while nsnotification is like passing message to multiple objects at the same time. All other objects that have subscribed to that notification or acting observers to that notification can or can’t respond to that event. Notifications are easier but you can get into trouble by using those like bad architecture. Delegates are more frequently used and are used with help of protocols.
56.What are KVO and KVC?
KVC: Normally instance variables are accessed through properties or accessors but KVC gives another way to access variables in form of strings. In this way your class acts like a dictionary and your property name for example “age” becomes key and value that property holds becomes value for that key. For example, you have employee class with name property.
KVO : The mechanism through which objects are notified when there is change in any of property is called KVO.


hope this will useful to you. If any new question please share with us....Thank you...:)

Statusbar - How to hide/show status bar in i Os

The status bar can be gradient gray (with black text), black opaque (with white text), or black translucent. By default the status bar is gray. If your app features standard iPhone UI elements, then stick with the default status bar. However if your app has custom views with dark backgrounds, then a black status bar will look better.
Black and white status bars push the underlying views down, giving you 320 x 460 pixels of screen space to work with in your app. A translucent status bar overlays the underlying view, giving you the full 320 x 480 pixels of screen space.
You can set the status bar style either programmatically or in your Info.plist file. If you change it in Info.plist, then the style is changed when the app launches (while the app is loading). If you change it programmatically, then the style changes after the app finishes loading.


//To hide
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];


//To Show
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];


Hope this i useful to your coding. If and new important on status bar then please share with us …. thank you…:)

Friday 21 June 2013

UIImage - Make Image Blur

In iOs 7 there is grate use of blur image. Its look awesome .. Here is function to make any image blur. In that original image is blur start with 0.0 and increase it unto 1.0 as requirement.

Example :

- (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur {
    if ((blur < 0.0f) || (blur > 1.0f)) {
        blur = 0.5f;
    }
   
    int boxSize1 = (int)(blur * 100);
    boxSize1 -= (boxSize1 % 2) + 1;
   
    CGImageRef img = image.CGImage;
   
    vImage_Buffer inBuffer, outBuffer;
    vImage_Error error;
    void *pixelBuffer;
   
    CGDataProviderRef inProvider = CGImageGetDataProvider(img);
    CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);
   
    inBuffer.width = CGImageGetWidth(img);
    inBuffer.height = CGImageGetHeight(img);
    inBuffer.rowBytes = CGImageGetBytesPerRow(img);
   
    inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData);
   
    pixelBuffer = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img));
       
    outBuffer.data = pixelBuffer;
    outBuffer.width = CGImageGetWidth(img);
    outBuffer.height = CGImageGetHeight(img);
    outBuffer.rowBytes = CGImageGetBytesPerRow(img);
   
    error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL,
                                       0, 0, boxSize1, boxSize1, NULL,
                                       kvImageEdgeExtend);
   
   
    if (error) {
        NSLog(@"error from convolution %ld", error);
    }
   
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef ctx = CGBitmapContextCreate(
                                             outBuffer.data,
                                             outBuffer.width,
                                             outBuffer.height,
                                             8,
                                             outBuffer.rowBytes,
                                             colorSpace,
                                             CGImageGetBitmapInfo(image.CGImage));
   
    CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
    UIImage *returnImage = [UIImage imageWithCGImage:imageRef];
   
    //clean up
    CGContextRelease(ctx);
    CGColorSpaceRelease(colorSpace);
   
    free(pixelBuffer);
    CFRelease(inBitmapData);
   
    CGColorSpaceRelease(colorSpace);
    CGImageRelease(imageRef);
   
    return returnImage;
}



Hope this will useful in your code…. if any useful code for same please share it with us…..Thank You…:)

Wednesday 19 June 2013

Animation Example


Simple Animation

Here (In example 1) is simple animation code. That is straight forward and easy please read its step by step comment.
Example 1
---------------------------------------------------------------------------------
[UIView beginAnimations:nil context:nil];    //Animation Start
[UIView setAnimationDuration:0.70];    //How long animation is run.
[UIView setAnimationDelay:0.0];    //Is there any wait to perform animation.
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];    //Animation Type
//Your Code For Animating Element.
[UIView commitAnimations];    //End Animation
---------------------------------------------------------------------------------

Simple Animation Block

In example 2 its display simple animation block. That take only animation time and other element work as default for customize those element please refers other example.
Example 2
---------------------------------------------------------------------------------
[UIView animateWithDuration:1.0f animations:^{ //Your Code For Animating Element.
}];
---------------------------------------------------------------------------------
Animation With Completion Block
This(In example 3) is simple animation block that use when condition like wait until animation is done. In below example we create one animation block in that first line we its duration as 1 then start animation that mean animation is completed in 1 minute you can edit that as per your requirement. Then in second block , its call completion that mean that block execution when animation is completed in below case that call after 1 min.

Example : 3
---------------------------------------------------------------------------------
[UIView animateWithDuration:1.0
                 animations:^{
                     //Your Code For Animating Element.
                 }
                 completion:^(BOOL finished){
                     //Wait until above animation is done.
                 }];
---------------------------------------------------------------------------------

Animation With Completion Block and Other Parameter.
Example : 4
---------------------------------------------------------------------------------
[UIView animateWithDuration:0.5
                      delay:0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     //Your Code For Animating Element.
                 }
                 completion:^(BOOL finished){
                    
                 }];
---------------------------------------------------------------------------------

Example : 5
---------------------------------------------------------------------------------
[UIView animateWithDuration:0.5
                      delay:0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     //Your Code For Animating Element.
                 }
                 completion:^(BOOL finished){
                     //Second Animation Block.
                     [UIView animateWithDuration:0.5
                                           delay:0
                                         options:UIViewAnimationOptionBeginFromCurrentState
                                      animations:^{
                                      completion:nil];
                                      }];
---------------------------------------------------------------------------------
                    
   What Can Be Animated ?                 
                
Here is Some sample animation code that may useful to you.
Flip button with two image.
                    
 //First Click
     [button setImage:[UIImage imageNamed:@"listimage.png"] forState:UIControlStateHighlighted];
     [button setImage:[UIImage imageNamed:@"listimage.png"] forState:UIControlStateNormal];
     [button setImage:[UIImage imageNamed:@"listimage.png"] forState:UIControlStateSelected];
                    
     [UIView beginAnimations:nil context:nil];
     [UIView setAnimationDuration:0.75];
     [UIView setAnimationDelegate:self];
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:btnListCal cache:YES];
                    
     [button setImage:[UIImage imageNamed:@"calandarimage.png"] forState:UIControlStateHighlighted];
     [button setImage:[UIImage imageNamed:@"calandarimage.png"] forState:UIControlStateNormal];
     [button setImage:[UIImage imageNamed:@"calandarimage.png"] forState:UIControlStateSelected];
     [UIView commitAnimations];
                    
 //Second Click
    [button setImage:[UIImage imageNamed:@"calandarimage.png"] forState:UIControlStateHighlighted];
    [button setImage:[UIImage imageNamed:@"calandarimage.png"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"calandarimage.png"] forState:UIControlStateSelected];
                    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:btnListCal cache:YES];
                    
     [button setImage:[UIImage imageNamed:@"listimage.png"] forState:UIControlStateHighlighted];
     [button setImage:[UIImage imageNamed:@"listimage.png"] forState:UIControlStateNormal];
     [button setImage:[UIImage imageNamed:@"listimage.png"] forState:UIControlStateSelected];       
     [UIView commitAnimations];
                    
Explanation :
      button is UIButton reference. The best example for fill button is in iPod Music application in iPhone.
                        
                        
 Hope this will useful to you please share your trick and tip for UIAnimation. Thank You….:)

Tuesday 18 June 2013

get address using reverseGeocodeLocation

A geocoder object uses a network service to convert between latitude and longitude values and a user-friendly placemark, which is a collection of data such as the street, city, state, and country information. Reverse geocoding is the process of converting a latitude and longitude into a placemark. Forward geocoding is the process of converting place name information into a latitude and longitude value. Reverse geocoding is supported in all versions of iOS but forward geocoding is supported only in iOS 5.0 and later.


Function That get currunt address
-------------------------------------------------------------
-(void)getAddressFromCurruntLocation:(CLLocation *)location{
   
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
     {
         if(placemarks && placemarks.count > 0)
         {
             CLPlacemark *placemark= [placemarks objectAtIndex:0];
             //address is NSString variable that declare in .h file.
             address = [[NSString stringWithFormat:@"%@ , %@ , %@",[placemark thoroughfare],[placemark locality],[placemark administrativeArea]] retain];
             NSLog(@"New Address Is:%@",address);
         }
     }];
}
-------------------------------------------------------------

Additional References


Hope this will useful for getting current address. If any suggestion or improvement then please share it. Thank You....:)



NSURLConnection Asynchronous Request

An NSURLConnection object provides support to perform the loading of a URL request. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request.
NSURLConnection’s delegate methods—defined by the NSURLConnectionDelegate Protocol protocol—allow an object to receive informational callbacks about the asynchronous load of a URL request. Other delegate methods provide facilities that allow the delegate to customize the process of performing an asynchronous URL load. These delegate methods are called on the thread that started the asynchronous load operation for the associated NSURLConnection object.
NSURLConnection has a convenience class method, sendSynchronousRequest:returningResponse:error:, to load a URL request synchronously.

Example Code





-----------------------------------------------------------------
NSString *strURL= [NSString stringWithFormat:@"http://www.google.com/"];//Here is pass your json link
NSURL *URL = [NSURL URLWithString:[strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest *requestURL = [[NSURLRequest alloc] initWithURL:URL];
    [NSURLConnection sendAsynchronousRequest:requestURL
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
     {
         //When Json request complite then call this block
         NSLog(@"Json Call Done Perform Your Action with data");
         NSLog(@"Reply is:%@",[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]);
     }];
-----------------------------------------------------------------

Additional References



Here is example to use NSURLConnection with asynchronouse. You can use this to call your request while other process is running. Any other useful way to use this code or any correction then please share it. Thank you...:)

Monday 17 June 2013

iOs 7 New Feature

iOs 7 New Feature.

Control Center : Give you quick access for your device setting like Airplane mode, turn Wi-Fi on or off, or adjust the brightness of your display etc. Good feature.
Notification Center : New feature called Today,Missed gives you a convenient summary of, today notification and missed notification .
Multitasking : Multitasking has always been a smart way to switch between apps.
Camera : Camera in iOS 7 puts all your shooting formats — still, video, panorama, and now square — front and center.Very Good feature.
Photos : Change its display format.
AirDrop : Good feature to share our data.
Safari : change looks and some feature.Mostly design is previously we are used.
iTunes Radio : streaming radio stations.
Siri : gets new look ,more natural-sounding
App Store : shows you a collection of popular apps relevant to your current location , new Kids category spotlights the best apps for children based on age.
Find My iPhone : new security features in iOS 7 make it harder for anyone who’s not you to use or sell your device.


Above feature is announced by apple that may improve our development. Other lot may feature that all effect our development but that may know after its launch in market its may change customer requirement and design view. If any new feature that you know apart from this then please share with us.


Other feature that mention in key note

  • Enterprise single sign-on
  • View PDF annotations
  • Inclinometer
  • Long MMS support
  • Per app VPN
  • Maps bookmark syncing
  • Phone, FaceTime and Message blocking
  • Smart download of TV episodes
  • Notification sync
  • Night mode for Maps
  • WiFi HotSpot 2.0
  • Scan to acquire Passbook passes
  • Turn-by-turn walking directions
  • FaceTime audio
  • New smart Mailboxes
  • Managed app configuration
  • App Store Volume Purchase
  • Tencent Weibo
  • Chinese English bilingual dictionary
  • Handwriting recognition for multiple Chinese characters
  • Improved Mail search
  • Streamline MDM enrollment
  • Do Not Track option in Safari
  • Italian, Korean and Dutch dictionaries





Additional Framework Enhancements
With the advent of iOS 7, many frameworks have got significant enhancements, which allow developers to add distinctive functionality to their apps. Below is the list of enhanced APIs:
UIKit Framework
Store Kit Framework
Security Framework
Pass Kit Framework
OpenGL ES
MessageUI Framework
Media Player Framework
Map Kit Framework
Image I/O Framework
iAd Framework
Game Kit Framework
Foundation Framework
Core Telephony Framework
Core Motion Framework
Core Location Framework
Core Foundation Framework
Core Bluetooth Framework
AV Foundation Framework
Accelerate Framework

See more


NSNotificationCenter


Here is note for NSNotificationCenter if you have any new tip on NSNotificationCenter then please write in comment so i'll add in note so it'll useful for other.If you have any tip to use NSNotificationCenter then also share we me.Here is simple way to implement Notifications.

Notifications are an incredibly useful way to send messages (and data) between objects that otherwise don't know about each other. Think of it like a radio station broadcasting messages: the station (sender) broadcasts the message, and listeners can choose to listen in and receive some (or all) of the broadcast messages.
For example, you might have a network reachability check in your app delegate, and post notifications whenever the reachability changes. Other objects would listen for that notification and react accordingly when the network goes up or down.
Some Cocoa frameworks send notifications when certain events happen. In iOS 4.0 and up, the application sends notifications when an app is about to move the background... and when it returns from the background. Your app's objects and controllers can listen for these notifications and stop actions (or save data) when the app is about to quit, and resume when it becomes active again.









Normal Notification.

Step 1 : Register your Notification in class in which you want to use. Unregister its in same class when class is no longer.
Register
             [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(methodName) name:@"myNotificationFire" object:nil];
Unregister - Unresister it in class dealloc method or when notification is not in use.
                [[NSNotificationCenter defaultCenter] removeObserver:self];

Step 2 : Implement its register method 
  -(void) methodName{
      NSLog(@"Notification Method Call");
    }

Step 3 : Use that Notification.
     [[NSNotificationCenter defaultCenter] postNotificationName:@"myNotificationFire" object:nil]


Notification with object.

Step 1 : Register your Notification in class in which you want to use. Unregister its in same class when class is no longer.
Register
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(methodName:) name:@"myNotificationFire" object:nil];
UnRegister - Unresister it in class dealloc method or when notification is not in use.
           [[NSNotificationCenter defaultCenter] removeObserver:self];

Step 2 : Implement its register method 
  -(void) methodName:(NSNotification *)notification{

    NSMutableDictionary *dictionary =(NSMutableDictionary*) [notification object];
      NSLog(@"Notification Method Call.And object content is :%@", dictionary);
    }

Step 3 : Use that Notification.
     [[NSNotificationCenter defaultCenter] postNotificationName:@"myNotificationFire" object:ObjectName]
        //ObjectName that is object that you want to receive at notification receiver method. In our case its "methodName"


Additional References

Here is Apple Official document list for notification.
NSNotificationCenter

If any tip or new idea or change for iOs 7 NSNotificationCenter then please share with us.

Hope this will useful to you. If any suggestion then please write in comment . Thank You.