Do a factory reset to MAC OS X 10.9 Mavericks

Hi,

This post will explain all the steps that need to be taken in order to do a factory reset to your MAC. I have followed these steps on my MAC OSX 10.9 Mavericks and everything works fine after that.

Steps to be followed are given below :

  1. Turn off your MAC : The first step you need to do is to SHUT DOWN your mac machine.
  2. Hold down option key and power button for a few seconds. This will turn on your mac but it will not directly boot to the desktop. Instead, it will show two hard disks; One is your actual hard drive which stores all the data. The other is a recovery hard drive. See screen clip below.Make sure you first select the WiFi network below. Then, click on Recovery HD and click on the Upward arrow under it.
    figure-2-100029918-large
  3. Now Mac will reboot. Once you have clicked on the upward arrow, the mac will reboot. Once it has rebooted, it will show the MAC OS X Utilities. See screen clip below.
    DiskUtil_OSXUTIL
  4. Here, select Disk Utility and click on Continue. Once this screen appears, click on Disk Utility and then click Continue. You will now be directed to another window where you can erase or re-partition the hard drive. In our case, we need to erase the hard disk completely.
  5. In the Disk Utility window, select Macintosh HD in the left-side pane, then select the “Erase” tab in the right-side pane, then select Macintosh HD Extended (journaled) in the drop down and finally click on erase. I have attached a sample screen clip below to depict the process.

    Click on “Erase” again to confirm. Once it is finished, you can see that the hard drive is completely erased by looking at the free space given at the bottom of disk utility window.
  6. Now close the disk utility window. It will now show the Mac OS X Utilities window again. Here, select Reinstall Mac OS X and click on Continue. Click Continue again in the next two windows. Now as your mac is connected to WiFi, it will download the OS from the Apple for re-installation. Select I Agree. Then in the next window, you will have to select the drive in which you want to install the OS. Here, select Macintosh HD and click on Install and then click on Continue.
    Now the Mac OS will start downloading and this process will take quite some time depending on your internet speed. With my 4MBps internet, it took around 4 hours to download. So be patient. ;-)
  7. Once the download is complete, the Mac will automatically reboot and directly move to the installation screen where it shows the installation progress. Even this process takes some time. Generally around 15 minutes to half an hour.
  8. After the installation has succeeded, click on Restart. The Mac will anyhow automatically restart after a few seconds. So no problem even if you don’t hit the restart button :-)
  9. Success : Once the system restarts, we have a fresh OS installed which can now be setup again as per our wish. You will now see the screen where you need to select the country and then keyboard layout and stuff. So basically, if you see this screen, it means you now have a brand new OS installed afresh.
  10. Continue with the setup of your mac until you see the desktop. Once you see the desktop, your Mac is now fully cleaned and reset and ready to run.

You can also refer to this excellent video which shows the steps live.

Hope this helps!!

Posted in Mac OS X | Tagged , , , , , , , , , , , , , | Leave a comment

[Resolved] – Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed.

Hi,

So I was working on two laptops today and had to copy few files from one laptop to the other. As I always do, I tried to access the second laptop using the Run command \\hostname\shared_folder. It asked for credentials of the other laptop and then suddenly this weird error message popped up.

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed

For some time, I couldn’t understand it but then however, I suddenly realized that I had earlier used the same command to connect to this second laptop and so this connection was already established in the first laptop. However, I recently changed the credentials for the second laptop.

Now what exactly happened was, my first laptop was trying to connect to the second laptop using 2 sets of credentials; One were the earlier credentials, and other were the ones I entered now. Hence the error message.

Resolution:

The way to solve this problem is pretty simple actually. Use the net use command from command prompt to see all the shared network resources to which a connection has already been established.
If you see the shared resource in the list, you will need to reset the connection to that resource. Simplest way to do that is to delete that connection.
The command to delete the connection is

net use \\servername\shared_folder /delete

In my case, I used

net use \\hostname\shared_folder_name /delete

If in case, you do not have many shared resources, an even more simpler way is to just delete all the connections. The command to do that is

net use * /delete

When you press ENTER, you will be asked for confirmation. Just enter Y and press enter again. Now the connection has been deleted. This enforces your machine to take a new set of credentials when connecting to the shared resource next time.

**P.S. : In most cases, you can use the IP address of the Server on which the shared drive exists.

For example:

\\49.XX.XX.XX\shared_folder

This works most of the times. Didn’t work for me though! Still trying to find out why.

Hope this helps!

Posted in General | Tagged , , , , | Leave a comment

Parsing JSON response from Web service to NSDictionary in iOS – Objective C

Hi,

This post will show how to parse the JSON response received from a web service into an NSDictionary object. For the purpose of this post, I’ll use a sample web service hosted by jsontest.com that returns the MD5 hash of the entered sample text.

The url of the sample web service is http://md5.jsontest.com/?text=AmoghNatu

The output when a request is made to the above URL is as shown below.

{
   "md5": "1e559716c8590f85d81abf7abff073aa",
   "original": "AmoghNatu"
}

In the sample project, I’ll display the MD5 text in an alert box.

For parsing the response JSON, we use the NSJSONSerialization class’s JSONObjectWithData method. When a request is posted to the web service, the response is initially stored in an NSData object. This NSData object is passed to JSONObjectWithData method as parameter along with json reading options and an error object, in case there is an error while parsing the JSON.

Let’s have a look at the code.

- (NSDictionary *)parseJsonResponse:(NSString *)urlString
{
    NSError *error;
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"GET"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse: nil error:&error];
    if (!data)
    {
        NSLog(@"Download Error: %@", error.localizedDescription);
        UIAlertView *alert =
        [[UIAlertView alloc]initWithTitle:@"Error"
                                  message:[NSString stringWithFormat:@"Error : %@",error.localizedDescription]
                                 delegate:self
                        cancelButtonTitle:@"Ok"
                        otherButtonTitles:nil];
        [alert show];
        return nil;
    }
    
    // Parsing the JSON data received from web service into an NSDictionary object
    NSDictionary *JSON =
    [NSJSONSerialization JSONObjectWithData: data
                                    options: NSJSONReadingMutableContainers
                                      error: &error];
    return JSON;
}

The method parseJsonResponse is a sample method that I have written that makes a request to the web service and gets the response in JSON. This JSON is then parsed into an NSDictionary object.

I have uploaded a sample application. The same can be downloaded here. Check that if required.

Hope this helps!

Posted in iOS, Objective-C | Tagged , , , , , , , , , , , , , , , , , | Leave a comment

Enable scrolling to View to allow multiple elements #iOS

Hi,

In this post, I’ll show how to enable scrolling in a particular view in iOS. That is, say if you have many elements to be added in a view and that won’t fit in one screen of the phone. In that case there will be a need for adding scrolling to the view.

By default, a view will have a fixed height (the height of the screen). But most of the times, there are way too many UI elements like textboxes, labels, etc. that need to be added to the view.

So in order to do that, we need to follow the below 5 steps :

  1. Remove Auto-layout for the view controller of the view that needs to have scrolling
  2. Set the “Size” attribute of the View to “Freeform
  3. Increase the height of the view to required dimensions
  4. Add a scroll view to the view
  5. !important Enable scrolling to scrollview and set the dimensions of it

The above steps are shown below through screen shots:

  1. Remove Auto-layout for the view controller of the view that needs to have scrollingFirst select the View controller by clicking on it in the storyboard, then uncheck the check box on the right.

    Un-Check auto layout

  2. Set the “Size” attribute of the View to “Freeform”In the Attributes inspector, under the Simulated Metrics section, change the value of Size attribute to Freeform

    change size

  3. Increase the height of the view to required dimensionsIt is important to note that BEFORE the size is chanegd to Freeform, the dimensions of the view will be disabled as shown below

    Disabled dimensions

    After the size is changed to “Freeform”, we can see that the dimensions are enabled to change as shown below.

    Enabled Dimensions

    Increase the value of the Height element as required and hit enter. This will make the view to the changed size. A sample is shown below.

    Increased Height

  4. Add a scroll view to the viewFrom the objecct library, drag and drop a scroll view on to the view. By default, it will occupy the entire space of the view. Re size it as required.

    Added ScrollView

  5. Enable scrolling to scrollview and set the dimensions of itThis step is very important and needs to be done in order to enable scrolling for the view. We have to add an outlet for the scroll view and synthesize the same in the implementation. This is to give ourselves a reference to the scrollview for programatically enabling scrolling and setting it’s dimensions. The steps are shown below.

    Add outlet

    Synthesize Property

    Now, enable the scrolling and set the dimensions. Sample code shown below:

    enable scrolling

Now, all the required steps are done. Only thing that needs to be done is add the elements to the screen and run it. For the purpose of this post, I’m randomly dragging some elements on to the view and running the app.

Now, run the app and verify that scrolling has been enabled.

Running app with scrolling
Scrolling working!

I have put the above sample project for download here. You can download the zip file by clicking on File–>Download. Please let me know if there are any changes or improvements that can be done here.

Hope this helps!

Posted in General, iOS, Mobile Application Development | Tagged , , , , , , , , , , | 4 Comments

Consuming SOAP web services from iOS (Objective-C)

Hi,

In this post, I’ll show you how to consume a SOAP web service (asmx web service) from iOS. It’s pretty easy to start off with.

There are many links that talk about the use of many frameworks like ASIHttp framework, JSON Framework, wsdl2objc tool, etc. But for the purpose of this post, I would like to keep it simple (KISS! ;-)) Those frameworks are basically used for consuming web service methods that are more complex and those that return JSON response or things like that.

More on those later. For now, let’s concentrate on consuming a very basic ASMX web service hosted by w3schools.org, Temperature conversion web service.

As you can see, this web service exposes two methods: Convert a given temperature from Celsius to Fahrenheit and vice versa. In this post, let’s consume the first one (Celsius to Fahrenheit method).

The steps to follow for consuming the service from XCODE are given below:

  1. Create the request SOAP Envelope message as string
  2. Create a request to the URL
  3. Add required request header elements
  4. Initiate the request
  5. Implement connection delegate methods
  6. Parse the response.

For creating the soap request envelope message, open the method definition in the browser and copy-paste the request string as shown in the page. A sample is shown below:

soap Message

Note the format specifier in the middle of the soap message. That is to take the value entered by the user from the text field.

Celsius

Next step is to create a request to the URL of the web service. Sample code is shown below:

Request

Next, add the required header elements to the request object. You can find out what header elements are required in the message by looking at the sample request objects shown in the webpage of the service’s method. Sample code shown below:

Headers

Finally, set the body of the request by converting the soapMessage to bytes (shown in the last step above).

Next step is to implement the NSURLConnection delegate methods in the application. These methods are used to implement functionality at different stages of the request. A sample of the methods is shown below:

Connection Methods

The code of the connection methods is given below:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [self.webResponseData  setLength:0];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [self.webResponseData  appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"Some error in your Connection. Please try again.");
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"Received %d Bytes", [webResponseData length]);
    NSString *theXML = [[NSString alloc] initWithBytes:
                        [webResponseData mutableBytes] length:[webResponseData length] encoding:NSUTF8StringEncoding];
    
    NSLog(@"%@",theXML);
    
    //now parsing the xml
    
    NSData *myData = [theXML dataUsingEncoding:NSUTF8StringEncoding];
    
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:myData];
    
    //setting delegate of XML parser to self
    xmlParser.delegate = self;
    
    // Run the parser
    @try{
        BOOL parsingResult = [xmlParser parse];
        NSLog(@"parsing result = %hhd",parsingResult);
    }
    @catch (NSException* exception)
    {
        UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Server Error" message:[exception reason] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        return;
    }
}

In the last method, you can see that we have written some code to parse the response received from the web service.
Now, to enable our application to parse the response XML, we need to indicate that our app implements the NSXmlParserDelegate interface.

For this purpose, specify the same in the interface file as shown below:

interface

Now, the next step is to implement the NSXmlParserDelegate methods. It has 3 methods:

  1. didStartElement
  2. foundCharacters
  3. didEndElement

The code of the above methods is given below:


//Implement the NSXmlParserDelegate methods
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI qualifiedName:
(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    currentElement = elementName;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if ([currentElement isEqualToString:@"CelsiusToFahrenheitResult"]) {
        self.resultLabel.text = string;
    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    NSLog(@"Parsed Element : %@", currentElement);
}


The foundCharacters method is called when an XML tag is encountered that has some characters between the start and end tag. In our case, the response is wrapped between the CelsiusToFahrenheitResult tag. The characters that are found between the start and end tag are stored in the NSString variable string. Hence the code. The result string found is assigned to the result label on the screen.

When you put all the required pieces of the code together and run the app, you get this result.

result

When the user enters the celsius value in the text box and presses the button, the web service is called and the resultant xml response is parsed and the resulting value is displayed on to the screen.

I have attached the complete sample application source code here. Do have a look. You can download a zip copy of the same there from the bottom right of the page.

Hope this helps!

Posted in .NET, iOS | Tagged , , , , , , , , , , , | Leave a comment

Invoke a POST method with XML Request message in C#

Hi,

To invoke a POST method located at a particular URL with an XML request message, we need to follow the below steps:

  1. Create a request to the url
  2. Put required request headers
  3. Convert the request XML message to a stream (or bytes)
  4. Write the stream of bytes (our request xml) to the request stream
  5. Get the response and read the response as a string

This looks much easier when seen in code. :-) Keep reading…..

So, the code for the above steps looks something like this:

namespace HttpPostRequestDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            string xmlMessage = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" +
            "construct your xml request message as required by that method along with parameters";
            string url = "http://XXXX.YYYY/ZZZZ/ABCD.aspx";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);


            byte[] requestInFormOfBytes = System.Text.Encoding.ASCII.GetBytes(xmlMessage);
            request.Method = "POST";
            request.ContentType = "text/xml;charset=utf-8";
            request.ContentLength = requestInFormOfBytes.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(requestBytes, 0, requestInFormOfBytes.Length);
            requestStream.Close();


            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader respStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);
            string receivedResponse = respStream.ReadToEnd();

            Console.WriteLine(receivedResponse);
            respStream.Close();
            response.Close();
        }
    }
}

If the xmlMessage is formed correctly, then you should be getting the expected response from the web method located at the URL.

Hope this helps!

Posted in .NET, ASP.NET, C# | Tagged , , , , , , , | Leave a comment

QR code for my blog

Hi there!

Check out the new QR code for my blog!

qr code
Posted in General | Leave a comment