Friday, October 4, 2013

Windows Azure Push Notification HUB Overview

What is Push Notifications?
Push notifications update the smartphone and tablet users instantly when an event occurred. On apple iOS devices the push notification interrupt the user with a dialog box if he is currently using the application or it will appear at the notification area if the app is in background, similarly in windows store application it will be a toast where modeless window appears with a sound. Some real world examples for push notifications are

·   Facebook app will notify when you have a new message, friend request, comment to a post etc,
·         Gmail app will notify when you have new email.

Basically there are two methods of implementing push notification for mobiles. You can user ordinary PNS or you can use notification HUB. There are lots of advantages of using notification HUB over PNS. First I’m going to discuss about the ordinary PNS.

How Push Notifications Work

Push notifications are delivered through platform-specific infrastructures called Platform Notification Systems (PNS). This is platform dependent. If developer wants to send a push notification to iOS device he has to contact APNS (Apple Push Notification Service) to send the notification, if that same notification is needed to send to windows app the develop has to contact WNS (Windows Notification Service) to send the same notification again, similarly if the developer want to send that notification to Android he has to contact GCM (Google Cloud Message) to the message. So the developer has to implement separate interfaces to each platform.  

Drawbacks of Push Notifications.
Push notifications are the most wanted features in the current mobile app market. But form the developer side lot of dirty work needed to be done to send push notifications. There are three main disadvantages of PNS.

1.   Platform Dependency
As I mentioned earlier the developer must code multiple interfaces for each platform in order to send push notifications. And also the developer needs code high-level details such as format for each platform. This will end up will unmanageable code.   

2.   Poor Scalability
If you are using PNS the device tokens must be refresh each and every time app is lunched to in order to maintain the device token alive. When the no of devices increase it will incur high traffic as well as the maintenance cost of the infrastructure.

Most of the PNS does not support broadcasting, so developer has to send the notifications to each and every device separately, if the devices are in millions the PNS will not be able to send the notification on time, the last device may get the notification after 20 minutes.

3.   Routing
In most cases the push notification is needed to send for special target groups. Then the developer has to write coding to maintain a registry that associates groups with the device token. Later this will become maintain overhead to the developers.



Why Windows Azure Notification Hubs.
As a solution to upper mention problems, we can use push notification Hub. Notification hub is like a USB hub; you can just plug any kind of USB device (pen drive, Hard Disk, Mouse and etc) and do the work. Likewise after registering with the HUB the developer only need to write single code to send notification to devices in any platform. The Hub will tack care about all the dirty work.


1.   Platform independent
Notification HUB provide common interface to send notifications to all major mobile platforms including Apple, Windows and Android. Through the API provided to the HUB the developer can send platform specific or platform independent messages.

2.   Routing
In notification HUB each devices token is consists at least one tag. This is normally app specific identifier such as user name, groupID and etc. This can be used to send notifications to groups instantly. For an example from the back end we can assign the groupId as a tag to the group member’s device token. The push notification can simply send by mentioning the groupID as the tag. Then all the members in the group will receive the push notification instantly.

3.   High Scalability
Notification HUB is capable of handling millions of devices without any modification in the app back-end






Reference - Microsoft MSDN, Windows Azure Notification Hubs Overview

Thursday, September 12, 2013

Upload image to .NET REST web service from iOS using AFNetworking

Previously I talked about calling a .NET REST full web service method that returns a object, now I’m going to talk about a how to upload a image using .NET REST web service. 

Here also I’m using AFNetworking. You can download it from here.

In this example I’m sending image as an NSInputStream. I’m sending the file name and the folder name, which the image should save in the server by adding as header fields to request object.

This how your web service interface method look like.



This is how your service method looks like


Here I can directly get the image data from the stream. I’m getting the image name and the folder name by calling this method from the incoming request.

WebOperationContext.Current.IncomingRequest.Headers.Get("folderName");

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.


As I told you earlier I’m converting the image to NSImputStream and assign it to the request operation object. And I have added folder name and the file name as request to herder fields. 

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.