RSS : Articles / Comments

Most useful terminal commands

12:10 AM, Posted by ruchira, No Comment

Below is a list of mostly helpful terminal commands you'd need to get on with your work. I'm planning to keep adding entries to this list later.

Print environment variable

  • echo $
  • E.g: echo $PATH would print the PATH variable value

Mac Show current Xcode location

  • xcode-select --print-path

Print current path (working directory)

  • pwd

Perform Load testing (Using Apache AB)

You can easily perform a simple load test using Apache AB. Macs come with apache AB installed. You can directly run from the terminal.
  • ab -n -c
  • E.g: ab -n 100 -c 5

kSoap2 printing request dump

10:51 AM, Posted by ruchira, No Comment


kSoap2 is a library for SOAP which is used in Androids.

Here's a neat little trick, if you want to see the actual XML sent received.

1. Set httpTransport.debug=true; before making the call

2. Read values from the httpTransport object afterwards

String s1 = httpTransport.requestDump;
String s2 = httpTransport.responseDump;

Have fun !!!

iOS Split Video into frames

2:35 AM, Posted by ruchira, 4 Comments

Dear all,

You may have encountered scenarios where you would like to split a video into several frames at different time intervals.
This post is for you if you intend to do the splitting at device level.
I presume that you have some reasonable experience with Objective C and XCode such as adding a framework and adding a file.

There are several steps to do to get this going.

  • 1. Build an XCode project and add a video file to project. I've worked with .mp4 files. Should work with other standard formats.

  • 2. Add AssetsLibrary framework and AVFoundation frameworks to your project

  • 3. Create a AVAsset object with your video. You need to pass the location of the video as a NSURL object.
  • I added the video(myvid.mp4) as an asset to my project. Therefore, I will use the following method to create the asset object.

    AVAsset *asset=[AVAsset assetWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myvid" ofType:@"mp4"]]];

    NOTE: If you need to record the video in your app and then load that video, you can pass the correct file path for building the NSURL object.

  • 4. Create CMTime objects indicating the times which you need to take frames at
    • CMTime t1= CMTimeMake(1, 1);
    • CMTime t2= CMTimeMake(2, 1);
    • CMTime t3= CMTimeMake(3, 1);

    I've created three CMTime structs to take frames at t=1,t=2,t=3 seconds.
    NOTE: CMTimeMake takes two arguments. The second is the timescale. Use value=1 for seconds. The first parameter is the amount of time in the required timescale.

  • 5. Next create an array with the time objects. Since CMTime are structs, you need to wrap them around NSValue objects. You can do that as below.
    • NSValue *v1= [NSValue valueWithCMTime:t1];
    • NSValue *v2= [NSValue valueWithCMTime:t2];
    • NSValue *v3= [NSValue valueWithCMTime:t3];

    NSArray *array=[NSArray arrayWithObjects:v1,v2,v3,nil];

  • 6. Next, you need to create an AVAssetImageGenerator to do the actual work. You can pass the asset object you created before as follows.
    AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];

  • 7. Next, you need to call generateCGImagesAsynchronouslyForTimes method of the generator object to actually start making the frames. It accepts an array. You need to pass the array you created above.

    [generator generateCGImagesAsynchronouslyForTimes:timesArray completionHandler:^(CMTime requestedTime, CGImageRef image, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error) {

    //This gets fired when a image is made. So, for our scenario, this method will fire 3 times(we requested 3 frames)

    UIImage *generatedImage=[UIImage imageWithCGImage:image];

This is the fundamental of creating images. Your app's logic will determine what you do with the images. Generally it's a good idea to save the images in the file system such that you could access them from anywhere in the app.

If you need any extra help, please feel free to comment. If you need a working copy of a Proof of concept which I created, please drop me a mail. I will be willing to email you the code.

iOS 7 UISearchBar Issue

2:34 AM, Posted by ruchira, One Comment

Dear all,

Transition into iOS 7 introduces a lot of adjustments. One such adjustment is the UISearchBar.

If you try to set the UISearchBar to the NavigationBar inside a UIViewController, then it will not work correctly in iOS 7.

The workaround for that is to use a UISearchDisplayController. Here are the steps.

1. Create your UISearchBar

UISearchBar *newSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

2. Create a UISearchDisplayController and initialise with the UISearchBar & your ViewController

UISearchDisplayController *searchDisplayController=[[UISearchDisplayController alloc] initWithSearchBar:newSearchBar contentsController:self];

3. Set the datasource & delegates of the UISearchDisplayController

searchDisplayController.delegate=self;//The delegate of UISearchDisplayController
searchDisplayController.searchResultsDataSource=self;//The data source for the search results tableView

4. Now, enable search bar display in the navigation bar


5. Now, in your ViewController, implement the datasource & delegate protocols

#pragma mark - UISearDisplayController delegate methods
-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {

tableView.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0];
tableView.frame=CGRectZero;//This must be set to prevent the result tables being shown


#pragma mark - UITableView data source methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 0;//To make an empty table

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 0;

Hope this works for you.

Crittercism "is this an employee-facing app" meaning

11:00 AM, Posted by ruchira, 4 Comments

Hi all,
Crittercism is very useful in many of our developments.
If you have tried to make a new app with Crittercism, they ask you a question "Is this an employee facing app". Apparently, there seems to be no definition and I couldn't figure it out even with the help of my teammates. So, I asked Crittercism myself and here is their explanation.

"The question is asked to find out whether your application will be published in the App Stores for anyone to download (B2C) or whether they will be used internally within your organization or company by employees only (B2E)."

Hope this helps you too :)

Android Multi format TextView

2:58 AM, Posted by ruchira, One Comment

Hey Androids !!!

This is going to be my very first post on Android development.
You may know that I've written many posts on Dot Net, Java & iPhone. From today onwards, I will add Android to that list :)

So, if you're in a situation that you need to have a single label(TextView) with multiple formats, then this will be the post for you. It becomes very simple when you know a bit of html.

Here is a list of tags supported by Android TextView before you get started.
Have a look at this before you start.

Suppose you have a TextView named multiFormatView

TextView multiFormatView;

The first step is to build your HTML string.

String htmlString = "<b>This is bold</b>"+"And this is not.";

Now there is only one line of code. Just set the text to the TextView using.


That's it.

So, it will print 

This is bold.And this is not.

You can juggle around with each of the tags supported to see how you can get your job done.
Happy coding my friends


XCode importing a file to whole project

1:59 AM, Posted by ruchira, No Comment


Sometimes you may encounter situations where you have a file which is used frequently throughout the XCode project. This may be a configurations file which is used in 80% of your code files. Importing this in each file is a certain possibility(and the very normal way with no issues), but if you are lazy and just want to add it in one place, this is the post for you.

If you analyze the project, there is a file named <project-name>.pch. There is a block of code which has the following.

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>

NOTE: As you can see, UIKit is already added and so is the Foundation framework. That is why you can use classes such as "UIView" or "NSArray" without any additional imports in your code file. That's just an extra bit of info for the curious !!!.

So, likewise, we can add our commonly used file into that block as well in the following manner.

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import "MyConfigFileName.h"

Once you add this, you can use "MyConfigFile" within your project without additionally importing it in each file.

NOTE: Remember, this is not the place to import each and every file for convenience. Only do it if the file is needed to be imported across a wide number of places in the project. Otherwise it'll just bring more trouble.

Happy coding :)