RSS Feed

AFNetworking : How to post data (NSData) on server.

Posted on

Few of my friends are facing issue in uploading JSON data on server. I am writing this post for those developer who are new in AFNetworking and unable to upload JSON data on there web server.

1. Create your parameter dictionary as : 
 NSDictionary *jsonDic = [NSDictionary dictionaryWithObjectsAndKeys

 value,         @”key”,

 value,         @”key”,

 value,         @”key”, // etc


2. Convert this dictionary into data : 

NSError *error = nil;

NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:NSJSONWritingPrettyPrinted error:&error];

3. Now follow this to upload data on server :

// Create request body 

    NSMutableData *body = [NSMutableData data];

// Append of the body with your data

    [body appendData:jsonData];

        [request setHTTPBody:body];

// Set request method POST

     [request setHTTPMethod:@”POST”];

// Set request Headers

    [request setValue:@”application/json” forHTTPHeaderField:@”Accept”];

    [request setValue:@”application/json” forHTTPHeaderField:@”content-type”];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    [httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

 // Success

  NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];

              NSDictionary *responseDict = [responseString JSONValue];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

// Failure

        NSLog(@”Error: %@”, error);


      [operation start];


Cheers !!


iOS 6 : How to fix rotation for different UIViewController Class

iOS seems awkward for rotation of iPhone/iPad app screen. Sometimes you need to rotate only single view controller class without rotating any other screen. In XCode if you check App Target (support interface orientations) there are four options are given :
1. Portrait 2. Upside down 3. Landscape left 4. Landscape right.

If you select only 1 and 2, you app will work only in portrait mode. Your rotation code will not affect on iPhone screen. Same for Landscape.

Lets consider my app in which i have 2 screens. Both are inherited from UIViewController class. My first screen (ViewController1) should run only in Portrait mode and my second screen (ViewController1) may work in all orientation (i.e portrait and landscape). Follow these step for fix the such case in your app :

1. In your app delegate make sure you are not using [self.window addSubview:RootController.view];
You should use : [self.window setRootViewController:RootController];

2. Inside App Target select all orientation

3. In your class ViewController1.m write this code : // This class will work only in Portrait.
– (BOOL)shouldAutorotate {

return NO;
– (NSUInteger)supportedInterfaceOrientations
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

4. In your class ViewController2.m write this code : // This class will work in all orientations.
– (BOOL)shouldAutorotate{

return YES;

return UIInterfaceOrientationMaskAll;
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

if ([self.navigationController.visibleViewController isKindOfClass:[ViewController2 class]])
return (YES);
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

Now run the app. It works like charms !!

Mac : How to fix MAMP when MySql is not working

Posted on

Hey Friends, Today i was trying to use MAMP to do some local PHP development on Lion OSx. But when i start the MAMP, it is not showing green signal for MySql “Error: Could not connect to MySQL server!”. May be it was already running somewhere. So we need to kill running MySql. Here’s a fix:

1. Quit MAMP
2. Open the terminal and type: killall -9 mysqld
3. Restart MAMP

It works… !!

How to generate Promotional Codes for your iOS app.

Posted on

Sometimes you need to share your paid iOS apps with your family and friends in free of cost. Apple has given an option to create free promo codes for your paid apps. So you can distribute this in your circle. Follow below steps to produce max 50 promotional codes for any iOS app.

1. Goto (login in your developer account).
2. Select “Manage Your Application” option.
3. Select your iOS app. Then select “View Detail” (below the icon of your app).
4. Select Blue button “Promo Codes”.
5. Enter number of codes that your required. This will create/download a text file in your download folder or path given by you.

NOTE : You can create max 50 promo codes for current version of your app. For next version you can again create 50.
User downloaded the app via promo code, can’t give feedback/rating on iTunes.
Each promo code can be used only one time.
Promo code will expire in 2 months.
Don’t forget to share your app’s promo code with me 🙂

!! Enjoy !!

Creating ‘Pulse’ style scrolling – Horizontally scrolling UITableView as a subview of UITableViewCell

A nice tutorial:

Creating ‘Pulse’ style scrolling – Horizontally scrolling UITableView as a subview of UITableViewCell.

Error 403 while getFollowers : Twitter iPhone MGTwitterEngine

I was trying to access the followers list from my twitter account by using MGTwitterEngine. But it is giving error. Here is all step what i have done to fixed it.

1. In MGTwitterEngine.m change #define TWITTER_DOMAIN @”” To #define TWITTER_DOMAIN @”″

and  #define USE_LIBXML 0 to #define USE_LIBXML 1 (Most of the people are not doing this and getting no response)

2. In your working class.h add #import “MGTwitterEngine.h” and add its delegate <MGTwitterEngineDelegate>

3. In your working class.m add these methods:

#pragma mark TwitterEngineDelegate
– (void) requestSucceeded: (NSString *) requestIdentifier {
NSLog(@”Request %@ succeeded”, requestIdentifier);
– (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
NSLog(@”Request %@ failed with error: %@”, requestIdentifier, error);
– (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier {

– (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier {

NSLog(@”Recieved Object: %@”, dictionary);
– (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier {

NSLog(@”Direct Messages Received: %@”, messages);
// This method will call when you received all your followers. I have used one NSMutableArray “friendsList” to store all followers information. You can modify this according to your need.
– (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier {

NSLog(@”User Info Received: %@”, userInfo);

friendsList = [[NSMutableArray alloc]init];

for (NSDictionary *u in userInfo ) {

NSDictionary *followersDic = [[NSDictionary alloc]initWithDictionary:u];
[friendsList addObject:followersDic];
[followersDic release];
[self.tableView reloadData];

This is all what i have added in my class and then calling this method: [[GetAppDelegate() facebook] requestWithGraphPath:@”me/friends” andDelegate:self]; And it return all my followers list.

I hope this code will help to those who have scratching his head from some couple of hours 😉

!! Enjoy !!

libz.1.2.3.dylib not found in iOS5, XCode 4.2

Posted on

It seems that libz.1.2.3.dylib is not included in iOS5 sdk. Here is simple method to fix this:

1. Open your project in XCode 4.2

2. Remove libz.1.2.3.dylib from framework

3. Add new framework libz.1.2.5

4. Run you app

It works fine. At least for me 😉


!! Enjoy !!