Thursday, October 25, 2012

What is a web service and what does it do.

First of all i apologize for writing this post so late i should have wrote it earlier when i wrote my first post of web service.

Many Freshers who come in iOS development are keen to know what is a web service and why to use it ? So in today's post i am going to clear the air a little bit.

What is a web service : A web service (ws) is a media where you request some information from the server and the server processes your request and provides you with the appropriate response.

The response can be in various formats like XML (Extensible mark up language), JSON (JavaScript Object Notation), CSV (comma separated value)

Example: If you want to display the name of your facebook friends in a table view then what you do is you call the facebook API. You call the required service and get the list of your friends from facebook.

Similarly if you want to get the details of any one of your friend from the list the you call another facebook service which will get the information about your friend.

Another example is google places API where you pass the category name as a parameter like banks, hotels etc and your current location and you get the list of banks or hotels near you.

How to know the response format of the web service: The web developer who has created the web service will tell you regarding the response format. The response format which is mostly used for hand-held devices is JSON since its simple and faster.

Classes for sending request in iPhone : The class named NSURLConnection will help you out in sending a request to the server and it will give you the response in it's delegate method named "connectionDidFinishLoading". But before creating the object of this class you need to create a request object of class type NSMutableURLRequest. You may visit this link for one of my sample demos for web service

Response Issues with web service : Many time what happens is that when the iOS developer parses the web service an HTML response is received instead of JSON or XML, this is because the web developer who was coding might have forgot to turn off his log printing (Just like NSLog that we have) or their might be an SQL / ORACLE exception.

Myth in the minds of web service developers : Many web service developers in the beginning think that making a ws for mobile is somewhat different than the ws they create, i would like to inform those developers that its the one and the same thing the only difference is in the response format where you need to send JSON or XML instead of a String or an Integer.

I hope that this has cleared some air in the minds of freshers and web service developers, if you have any queries then feel free to ask them as a comment to me via comment or mail.

Until then Happy iCoding and have a great day...

Monday, October 22, 2012

Updates in iOS 6

A lot has happened in iOS 6 and apple has a document which you may read it from hereThe above document will guide you out regarding the changes that has happened in iOS technology.

Few of the changes i am mentioning it down so that you can read them as i feel that those are the important changes in iOS6.

UIKIT Framework

·         In iOS 5.1, the UISplitViewController class adopts the sliding presentation style when presenting the left view (previously seen only in Mail). This style is used when presentation is initiated either by the existing bar button item provided by the delegate methods or by a swipe gesture within the right view. No additional API adoption is required to obtain this behavior, and all existing APIs—including that of the UIPopoverController instance provided by the delegate—will continue to work as before. If the gesture would be insupportable in your app, setting the presentsWithGesture property of your split view controller to NO disables the gesture. However, disabling the gesture is discouraged because its use preserves a consistent user experience across all apps.
·         In iOS 6, changes have been introduced so that you no longer need to set a delegate and implement a method for single-finger and single-tap gesture recognizers. This makes them work well with theUIControl objects.
·         In iOS 6 and later, the UIWebView class paints its contents asynchronously.
·         Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use thesupportedInterfaceOrientationsForWindow: and shouldAutorotate methods.
·         More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom andUIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.
·       A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change over time. The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style. Moreover, the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method. The system intersects the view controller’s supported orientations with the app’s supported orientations (as determined by the Info.plist file or the app delegate’s application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.
·         The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by thesupportedInterfaceOrientations method of the top-most full-screen controller.
·         The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This makes the caller responsible for ensuring that the status bar orientation is consistent.
·         For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.
·         The willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods are no longer called on any view controller that makes a full-screen presentation over itself—for example, presentViewController:animated:completion:.
·         You should make sure that your apps are not using these methods to manage the layout of any subviews. Instead, they should use the view controller’s viewWillLayoutSubviews method and adjust the layout using the view’s bounds rectangle.
·         In iOS 6, the viewWillUnload and viewDidUnload methods of UIViewController are now deprecated. If you were using these methods to release data, use the didReceiveMemoryWarning method instead. You can also use this method to release references to the view controller’s view if it is not being used. You would need to test that the view is not in a window before doing this.
·         It is not supported to set values for the shadowOffset or shadowColor properties of a UILabel object if its attributedText property contains a valid attributed string. Instead, use theNSShadowAttributeName attribute of the attributed string to set the shadow.
·         Due to compatibility concerns, the NSBaselineOffsetAttributeName attribute is no longer supported in iOS 6.
·         The NSTextAlignmentNatural value is not supported. It will throw an exception when it is used with the textAlignment property of UILabel or is supplied as the alignment parameter to thedrawInRect:withFont:lineBreakMode:alignment: method of NSString.
·         The setContentStretch: method of UIView has been deprecated. To achieve the same effect, use the resizableImageWithCapInsets: method of UIImage and display the image with aUIImageView.
·         The resizableImageWithCapInsets: method of UIImage effectively resizes images by tiling. As a performance optimization, it uses stretching rather than tiling when the user would not be able to tell the difference, such as when a single column or row is being stretched. But in certain circumstances, the user might want to actually stretch some region of an image. In iOS 6, theresizableImageWithCapInsets:resizingMode: method allows the caller to specify a tiling or stretching resizing mode.
·         The UICollectionViewLayout class has changed:
·         The class now supports the customization of the animations created during rotation. The names of methods for customizing insert and delete animations have also changed, so the same hooks can be used for rotations as well as for insertions and deletions.
·         The class has changed some method names. Specifically, decoration views are no longer referred to by “reuse identifier” but rather by “element kind.” Apps that are using decoration views will need to modify their code and be rebuilt to accommodate this.
·         The bottom edge of a UILabel view is now different from its baseline.
Previously, Auto Layout was interpreting the bottom of a UILabel to be the same as its baseline. While convenient in many cases, it caused problems if you wanted to place the top edge of one label against the bottom edge of another. In such a scenario, the bottom label would overlap the top one, and descenders from the top label could crash into ascenders from the bottom label. Now, Auto Layout interprets UILayoutAttributeBottom as the bottom of the text box (presuming the label is not bigger than its intrinsic content size) and UILayoutAttributeBaseline as the baseline of the text. If you have already created code for laying out labels according to the bottom or center point, your text will move around a little and you will need to adjust your constraints.
·         Apps with table views in their nib or storyboard files, and that were built using previous versions of iOS 6 beta, will require a clean build with beta 3 and newer.
Landscape-only apps that invoke a portrait-only view controller (such as the Game Center login screen) will cause the app to crash.
1.    Apps should provide the delegate method application:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.
2.    When a UIBNavigationController is involved, subclass the UINavigationController and overriding supportedInterfaceOrientations.


·         No privacy alerts are displayed in iOS Simulator for apps that access Photos, Contacts, Calendar, and Reminders.
·         For this release, iOS Simulator does not support testing In-App Purchase. Please use a device to test your apps that use this feature.
·         When attempting to play an MP3 sound in Simulator, you will hear a popping sound instead.
I hope that by reading this post you have some clearance on iOS6.

Wednesday, October 17, 2012

UIActivityViewController iOS 6

Sharing is indeed one of the important concepts when it comes to mobile computing people love to share about the recent events in their life. 

Apple in iOS6 has introduced a class which will help the developers to give multiple options to the users for sharing.

The new class introduced by apple is called UIActivityViewController which will help the developers to do this.

This class makes use of the account settings for various social networks or mail present in your iOS devices.

So let’s see how to make use of this class

Step 1: Open Xcode and create a single view based application, in the viewController.xib add the object of the UIButton class

Step 2: Declare the IBAction method in the viewcontroller.h file and connect it with the UIButton present in the XIB

Step 3: Let’s have a look at the code part of the IBAction method in the view controller.m file.

Code Explanation: In the above code we have to create the object of the UIActivityIndicatorViewController and what so every data you want to post you have to provide it in an array to it.

Step 4: All set and done now run the application and touch the button and when you do you will get the following output.

As i have said earlier it makes use of the accounts that the user has already set up with the iOS device so currently i have not set up any settings for facebook and if i select facebook for sharing then i get a message which asks me to set up my facebook account in the settings option.

If you want to attach an image for sharing then you need to add the image object in the array and leave everything as it is.

Now when you again run the application then you will get the following result

The last part pending is how to tackle completion of a particular posting event by this controller, 

Now when you post using any of the social media then you will receive a pop up which would describe whether the posting was successful or not and in the console you may check which media you have used.

You may download the source code from here.

I hope that this post has helped you out in using the UIActivityIndicatorViewController, in case if you are having any questions or queries then do let me know via mail or via comments.

Until then Happy iCoding and have a great Day.

Tuesday, October 16, 2012

UIRefreshControl in iOS6

All our clients want to have a basic functionality when its regarding the data display in the table view and that is having a spinner at it’s top. To do this you have the EGORefreshDemo that is available and is a little bit tricky to handle but is quite cool.

In iOS 6 apple has been a little open hearted to provide you with a class named UIRefreshControl which is similar in fashion, so in this post we will have a look at the UIRefreshControl and will use it with a table view.

Step 1: Open you Xcode 4.5 and create an empty view based project and add a UITableViewController file to it that will have a list of various products. After you have done this then add your table view controller view in the app delegate and the run your project to see if you have got things right.

Step 2: After completing step no1 select your tableviewcontroller.h file and declare a global object of UIRefreshControl.

Note: This class requires a call back method that will get triggered once you pull it so in simple terms we need a function, which we will assign to the UIRefreshControl and this function will be called when we pull our table to refresh it.

So now in your table view controller.h file you will be doing two things:

1. Creating a global object of the UIRefreshControl

2. Declaring a function that will be called when you pull the refresh control to refresh the table.
Step 3: Alright now after Step no 2 it’s time to switch to your tableviewcontroller.m file and select the view did load method where you will initialize the object of UIRefreshControl.

Code Explanation:I have used comments to make you understand the code.

After initializing the control it’s time to work on the callback method that would be associated with the UIRefreshControl.

Step 4: All set and done its time to run your project and see how it looks try pulling your table view and see apple’s new UIRefreshControl. Given below is the output for the same.

My Views on UIRefreshControl: After looking at this your client may or may not ask you to customize the UIRefreshControl class or stick with EGORefresh library, this class is available for iOS6 and not with any previous versions. But anyways its quite handly and less code is involved so it’s a good class by apple. 

You may download the source code of this project from here.

I hope that by reading this tutorial you have understood how to use the UIRefreshControl in iOS 6 and if there are any doubts popping in your mind the feel free to ask me by comments or by mail.

Happy iCoding and have a great day.