In this recipe, we will discuss using native iOS APIs to connect and consume REST services.
For this recipe, we will work on the ForecastApp
we created in the previous recipe, Consuming REST services. Open the project in Xamarin Studio.
Perform the following steps:
Comment out the code in the
ViewDidLoad
method and add the following code:this.btnForecast.TouchUpInside += (sender, e) => { NSUrlRequest request = new NSUrlRequest(new NSUrl("http://api.ometfn.net/0.1/forecast/eu12/46.5,6.32/now.json")); NSUrlConnection connection = new NSUrlConnection(request, new ConnectionDelegate((response) => { JsonValue jsonObj = JsonValue.Parse(response); JsonArray tempArray = (JsonArray)jsonObj["temp"]; double temp = (double)tempArray[0]; JsonArray windSpeedArray = (JsonArray)jsonObj["wind_10m_ground_speed"]; double windSpeed = (double)windSpeedArray[0]; this.lblOutput.Text = string.Format("Temperature: { 0}\ nWind...