Friday, August 16, 2013

Calling .NET REST web service from iOS using AFNetworking. – Part 2

Previously I talked about calling a .NET REST full web service method that returns a string. Now I’m going to talk about a GET method, which returns an object. 

I’m going to pass the user name and going get the user details as a UserDC object. Lets see how to do that.

This how your web service interface method look like.


This is how your service method looks like.



In iOS this is how you should call it. Hear I have written my method using blocks so after calling the web service it will notify the caller.

Wednesday, August 14, 2013

Calling .NET REST web service from iOS using AFNetworking. – Part 1


Today I’m going to talk about how to call a .NET REST web service. Actually, when I stared to develop iphone applications, I had to work with .NET REST web services. At that time I had to face lot of difficulties when calling web services. It was very hard to find a better solution by searching the web at that time. So I thought to tell you how your .Net web service should be and how to call it from iOS. In my next post I’m going to talk about how to upload an image from iOS to .NET REST web service.

Here I’m using AFNetworking to call web service. You can download it from here.

In this example I’m calling a GET method in .NET web service, which returns a string as a result. This method accept the user name, and it returns “#VALID#” if the user is in the main database, if not service will return “#INVALID#”.

This is how your service interface class should look like.



This is how your service.svc file should look like.



In the iOS this is how you should call it. Here I have written my method using blocks so after calling the web service it will notify the caller. 

Wednesday, August 7, 2013

How to Make Custom Buttons without making different sizes of background images.


In this post I’m going to tell you a very easy way to create custom buttons throughout your project. Hereafter you don’t have to apply different sizes of images to different sizes of buttons. You need two background images, one is for the normal state of the button and other is to highlight state of the button. Now I’m going to tell you step by step how to do it. You can use this Photoshop plugin to make your iPhone Images. 



You can download the sample code from here.

1.Create a background image for the normal state with the size 36x36 for your button in .png format for the previous versions of iPhones and create the same image with the size 72x72 for the new iPhone 5. 

2.Create a background image for the highlightstate with the size 36x36 for your button in .png format for the previous versions of iPhones and create the same image with the size 72x72 for the new iPhone 5. 

3.Add those images to your project.

4.In the code sample I have written a base control, which can be inherited by all the UIView Controllers in your project. So you can just call a method in the base controller, which will apply the background image to your buttons.



5. Now you can call this method setActionButtonStyle to apply the background image to your buttons anywhere in your code. 



iOS saving data to user defaults and getting data from user defaults.

Today I’m going to talk about a method to save application specific or user specific data in iOS, which is called “user defaults”. We can do this by using NSUserDefaults class. You can save objects of following types.

NSString, NSNumber, NSDate, NSData, NSArray, NSDictionary

For more information see the apple documentation from here.

The data saved in the user defaults is available until you delete the application.

You can use user defaults to save user specific or application specific stetting’s such as last state of the application, user color theme, user session and etc.

I’m going to give a small example about how to save data to user defaults and how to read data from user defaults. I’m going to save my application current user details (user first name, last name, image url, and user id) to user defaults.

Save current user details to user defaults .



Get user details from user defaults.



If you want to save any other type of data such as UIImage you have to convert it into NSData and save it.

iOS Creating a GUID


This is a simple way to crate a GUID in iOS. You can add this method to your utility class of your project.

Tuesday, August 6, 2013

How to improve the iOS table view image loading performance – Method 2 (AFNetworking)

Previously, I talked about a method using GDC. Today, I’m going to talk about another simple method using the AFNetworking. You can download the AFNetworking from this link 

If you are using a your own custom cell, import "UIImageView+AFNetworking.h" herder file to your custom cell. Or if you are not using a custom cell, import that herder file to your table view.

Here, we call setImageWithURL method, which returns an image view. This method accepts NSURL, so we need to convert our string URL to NSURL. Also I have added a placeholder image. So this placeholder image will load until the real image loads.

How to improve the iOS table view image loading performance – Method 1


Today I’m going to show you an easy way to improve the performance of table view with images. Normally, when you get images from the Internet and show it get stuck when scrolling. 

We can use dispatch_async to overcome this problem. Then the ios GDC (Grand Central Dispatch) will look after that. The ios will assign the image loading to a background thread while your table will load in the main thread.



Here I’m assigning the background thread to get the UIImage from my method GetImageById, by sending the member id. But to display the image in the table view we have to send that image to the main thread. That is why I’m assigning the loaded image in the dispatch_get_main_queue()block.