Tuesday, December 25, 2012

Core Data or SQLITE what to choose ?


While I was new to the ios technology I always used to avoid sqlite because many of the syntax does not made any sense to me, so I switched to core data which was beautifully designed by apple and had various flavors to it, it was far most the easy way by which I could interact with my applications local database.

I have worked on several projects where I thought that core data is better and apps where I thought sqlite is better, but there was a question in my mind which recently got clear and that was when to distinguish the use of these two technologies.

The answer to this is quite simple if your application has a relational model of database i.e if it has primary keys, foreign keys etc then in that case sqlite has the upper hand and if your application has a non - relational structure then in that case use core data.

If the app database is relational then too you may use core data but the handling becomes quite complicated because you are responsible for handling the business logic (record fetching or adding) for the database end where this is not the case with sqlite. To be more specific I am speaking of complicated nested queries and joins.

The hassle in sqlite is that you have to manually write the database interaction code while this is not the case with core data maximum of the database interaction code is done by itself, allowing you to focus on your task.

In sqlite before storing the database the data needs to be converted to native type c type and same is the case when you are fetching the data from sqlite. In core data this is avoided because it will give you fresh objects to bite on since it follows more oop approach.

There are many classes in core data which helps you to interact with the database and get the results where in sqlite there are c based methods which help you to achieve the same.

Summary: Both are good technologies but it depends which one you want to pick upon your database model.

I hope this post has helped you in choosing the best technology for your app, and if you have any queries then mail me or post it as a comment.

Happy iCoding

Friday, November 9, 2012

Solution : Could not Instantiate class named NSLayoutConstraint


Finally I got a project which I can build now with Xcode 4.5 and their was a very interesting bug that I came across.

The Bug Scenario: I made an app and as per the client request I wanted to make the application compatible with the previous versions of the iphone i.e. from iphone 4.3 to iphone 6.1.

So I made a very simple login view and ran it by selecting the iOS 6 simlator and was very much happy to see the login view running fine. Now what I did is selected the iPhone simulator 4.3 version and then ran the application keeping my fingers crossed that it will run fine and will have no issues.

But ALAS!!! I was wrong when I ran my application in iOS 4.3 the application crashed with a love letter in the console which said “ Could not Instantiate class named NSLayoutConstraint” well at first glance I did’nt know what that meant but after going through some developer forms I figured it out that it had to do with some settings of the XIB file.

So lets have a look at  those settings that I am talking about with these settings in place you can easily run your application with Xcode 4.5 from any deployment version you select in the xcode upto the latest version of the iOS without the NSLayoutConstraint crash.

To resolve this crash all i had to do is deselect an option from the Xcode 4.5

- Select the XIB file from your bundle, this will open the xib file.

- From the Utilities section (the one to your right)




- Select the file inspector sub section.






- In the interface-builder document their is a check mark for Use AutoLayout  in the Interface builder Document section which is by default selected when you create your views in XIB using Xcode 4.5.




- If you want to give your application support from any previous version of iOS to the latest version then kindly un-check this option from the interface builder settings.





Now when you run your application it should run fine with all the versions of iOS .

Hope this helps you in saving some time in development.

Happy iCoding and Have a nice day.

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.
Workaround:
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.

Simulator

·         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.