Project Description
This individual assignment will familiarize you with opening URL sessions and using JSON. You will create a basic weather app that will take a city request from World Weather Online and display its information for the user.
Basic Requirements
You will implement a view that does the following in your project:
- A city text field that prompts the user to enter the name of a city. City names can include spaces, and the program should automatically convert those spaces to "+" signs.
- A state text field that prompts the user to enter the name of a state. The state can either by the state's full name (which can include spaces that should be converted to "+" signs) or the state's postal code.
- A button that submits this request to World Weather Online.
Once the website responds to the request, you determine whether the request is valid or invalid. If the request is invalid, a message will notify the user that the app could not display data for the requested city's current weather conditions.
If the request is valid, display the following pieces of information for the requested city:
- The temperature in Celsius and Farenheit
- A weather icon showing curent weather conditions
- The percentage of cloud cover
- The percentage of humidity
- The pressure in millibars
- The amount of precipitation in millimeters
- The wind speed in kmph and mph as well as the direction in direction and degrees
The user can request a different city's data at any time. Note that you are
not validating "correct" city or state information for the user's request. World Weather Online's backend will be the one trying to match the user's request to an existing city and state. You only need to display the information World Weather Online returns to you.
Getting Started
You will start by creating a new project,
yourid_assignment7, as a Single View iOS application. You will need to implement the following features:
- A Storyboard implementation in Interface Builder with necessary constraints for displaying interface and returned data.
- An interface for the user to enter city and state data implemented in the Xcode editor.
- A WeatherData class and WeatherDataProtocol to provide access to Weather Online's information. Details about the API can be found here. This class provides three methods:
- responseDataHandler presents valid data in the view controller. You will need to analyze the returned JSON file and extract all necessary information to display. In order to display the current weather icon, which is returned as an http (rather than https) url, you'll need to add the potential addresses to a "white list" so iOS's App Transport will not reject the request due to its clear text transmission. You will need to add the following code to your Info.plist:
Note that you are not allowing arbitrary loads (this allows all unencrypted transmissions and opens the user's devices to vulnerabilities). You are only allowing clear text transmissions from http://www.worldweatheronline.net.
- responseError presents error messages in the view controller if the data submitted was not valid. This should be presented any time the app is unable to query Weather Online or cannot parse its returned JSON file.
- getData takes a user's URL request and retrieves the associated JSON file. In order to access the API to do this, you will create a URL path that includes the address, the user key, which is required to access the website's API, and a request for JSON formatting. This URL path will look like this:
https://api.worldweatheronline.com/premium/v1/weather.ashx?key=71f187bbe97b495988c165458182610&format=json
This key value assumes you are using my api key, but you can get your own api key by signing up with the site. While the free trial is only 90 days, it should be sufficient for testing purposes (and will ensure you do not max out your queries for the day you're testing).
You will add "&q=" to this string in order to query the database for the requested city and state (based on the user's requst). In full, a requested URL might look something like this:
https://api.worldweatheronline.com/premium/v1/weather.ashx?key=71f187bbe97b495988c165458182610&format=json&q=austin,tx
The initial view will look something like this:
After a valid request is made, the screen will look something like this:
After an invalid request is made, the screen will look something like this:
Extra Credit
To receive extra credit, you must first complete the required features. Include a README file explaining which extra features you included, so the grader can check for them.
View for hourly elements (5 points)
Allow the user to open a new view that displays the current city's hourly elements. There are a number of hourly elements returned with each call to a city, and you do not need to display them all. Choose at least six elements to disply. The user should be able to return to the main screen and enter a different city whenever they wish. This view should also display errors if the user encounters them.
What to turn in
You will submit a zip of the project folder, yourid_assignment7, that contains the file folder with code, and yourid_assignment7.xcodeproj via Canvas. Include a README file with extra credit details to receive extra credit.