Sunday, 24 June 2012

Create an Apple Itunes Account to download apps from App Store

Procedure to register:

1. To create Itunes Account click button to "Create New Account" as shown in Snap1.

2. Click "Continue" Button as shown in Snap2.

3. Please refer to Snap3: in second line from top 
"If your Billing Address is not ...... click here" 
You must click on "here" to select Country as India and continue the remaining steps.

4. Tick the checkbox shown in Snap3 to "I have read and agree to these terms and conditions".
5. Fill in your details shown in Snap4. And hit "Continue" button. 

6. Now a window appears showing Snap5. Select payment method as "None". Hit here if Region/ Country is not U.S. and select India and press "Change" button. Now fill in the details below and you are done.

Monday, 18 June 2012

Making the view slide up to make room for the keyboard

In my application i had many UITextFields which covered my whole UIViewController.
When i touched my UITextField which was at bottom to enter data, i came to know that the Virtual Keyboard came in front of it and covered it. So i was in a trouble after some help from StackOverflow i resolved the problem.

Add a UIScrollview - scrollView to your UIView and set delegates for UITextFields & UIScrollview

  - (BOOL)textFieldShouldReturn:(UITextField *)textField
     if (textField == txtFieldName)
         [txtFieldCellNo becomeFirstResponder];
   else if (textField == txtFieldCellNo)
         [txtFieldEmail becomeFirstResponder];
       [textField resignFirstResponder];

return YES;

 - (void)textFieldDidBeginEditing:(UITextField *)textField
     if(textfield == txtFieldName)
       [self animateTextField:txtFieldName up:YES: 80];
     else if(textField == txtFieldCellNo)
       [self animateTextField: txtFieldCellNo up:YES: 100];

     else if(textField == txtFieldEmail)
       [self animateTextField: txtFieldEmail up:YES: 120];


- (void)textFieldDidEndEditing:(UITextField *)textField
     if(textfield == txtFieldName)
       [self animateTextField:txtFieldName up:NO: 80];
     else if(textField == txtFieldCellNo)
       [self animateTextField: txtFieldCellNo up:NO: 100];

     else if(textField == txtFieldEmail)
       [self animateTextField: txtFieldEmail up:NO: 120];


- (void) animateTextField: (UITextField*) textField up: (BOOL) up: (int) distance
    const int movementDistance = distance;
    const float movementDuration = 0.3f;
    int movement = (up ? -movementDistance : movementDistance);
    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.scrollView.frame = CGRectOffset(self.scrollView.frame,0, movement);
    [UIView commitAnimations];

Here i have changed the movementDistance by 80 for txtFieldName, 100 for txtFieldCellNo and 120 for txtFieldEmail. This means my scrollview will scroll screen by 80, 100 and 120 pixels towards top.

You must adjust/change movementDistance to a value required for your UITextField.

Check Wifi & Internet Connectivity in an iPhone APP

I faced a problem in my Application that i would like t discuss here :
If wifi is ON but there is no or low internet connectivity, how to resolve it.

Below is the sample code :

    bool success = false;
    const char *host_name = [@"" cStringUsingEncoding:NSASCIIStringEncoding];

    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName (NULL, host_name);
    SCNetworkReachabilityFlags flags;
    success = SCNetworkReachabilityGetFlags(reachability, &flags);
    bool isAvailable = success && (flags & kSCNetworkFlagsReachable) && !(flags & kSCNetworkFlagsConnectionRequired);

    if (isAvailable)
        NSLog(@"Host is reachable: %d", flags);
        // Perform Action if Wifi is reachable and Internet Connectivity is present
        NSLog(@"Host is unreachable");
        // Perform Action if Wifi is reachable and Internet Connectivity is not present

When  ApplicationStatus method is called we check that "" is reachable or not.
SCNetworkReachabilityFlags returns flags which helps us to understand the Status of internet connectivity.
If isAvailable variable returns "true" then Host is Reachable means Wifi is reachable and Internet Connectivity is present else there is NO Internet Connectivity.

Problem in storing data with Core Data & retrieving it using SQLite

Last week i was working on an application in which i stored my data using CoreData.
Afterwards i was told to retrieve data using SQLite queries.
I thought it is a simple job since CoreData internally stores whole data into a sqlite file.
So i fired my complex queries on database, but i failed. So i tried simple queries thinking of  my queries must be wrong. But no luck, i tried whole day implementing many codes. I checked my Table name, column name and the were correct. I tried everything but was not successful.
Finally my senior (Nilesh Jinde) asked me to open my database into SQLieManger & i was totally surprised, CoreData changed every table name of my database with a name prepending a "z", so my table name Contacts changed to ZContacts and so changed my column names in similar manner.
And finally i came to know where i was going wrong thanks to Nilesh Jinde.

I will advice you all, while working with databases do use a SQLiteManager, it really helps us in exploring database, fire queries so we can implement them in our Objective C code.