RSS Feed

Tag Archives: iphone

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

                         nil];

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 !!

Advertisements

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
Orientaitons

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;
}
-(NSUInteger)supportedInterfaceOrientations{

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

if ([self.navigationController.visibleViewController isKindOfClass:[ViewController2 class]])
return (YES);
else
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 itunesconnect.apple.com (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 !!