Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 581: Mobile App Development

Similar presentations


Presentation on theme: "CSC 581: Mobile App Development"— Presentation transcript:

1 CSC 581: Mobile App Development
Spring 2018 Examples & advanced topics dice shaker motion sensor counter swipe gestures tap gestures countdown timer scheduledTimer random quotations reading from a local file HTTP requests

2 Dice shaker suppose we wanted to simulate the roll of two dice
could utilize buttons that change images when clicked (similar to slot machine) or, could have two images that are changed when a separate button is clicked

3 Motion sensor many apps use the motion sensor to initiate actions
e.g., shake the phone to clear the fields, restart the game, or roll the dice Swift provides various UIResponders to handle touch events motion events press events shaking the phone is a motion event want to process when the motion is done double check to verify UIEventSubtype is .shakeMotion

4 App example

5 Counter app suppose we wanted to have a counter app
right swipe increments the count; left swipe decrements double tap resets the counter to 0 touch gestures can similarly be handled with UIResponders in the code but, can be more simply handled via the storyboard drag a Swipe Gesture Recognizer onto the storyboard this adds an icon to the View Controller Tab Bar edit its attributes to make it left/right/up/down add an IBAction from the icon to specify the action drag a Tap Gesture Recognizer onto the storyboard edit its attributes to specify number of taps

6 App example

7 Countdown timer suppose we wanted to simulate a countdown timer
the user enters a duration in minutes & seconds at the click of a button, the time remaining counts down until 0:00 Swift provides a Timer class for such tasks the scheduledTimer method can schedule a method to be executed in the future, and repeatedly (if desired) Timer.scheduledTimer(timeInterval: DURATION_IN_SEC, target: self,                      selector: #selector(METHOD_TO_BE_EXECUTED),                      userInfo: nil, repeats: TRUE_IF_REPEATED) this class still has ties to Objective-C, so the selector method must have the as part of its header

8 App example

9 App example (cont.) suppose we wanted to add color to the display
@objc func updateTime() { var min = Int(minLabel.text!)! var sec = Int(secLabel.text!)! // CODE FOR UPDATING min & sec if min == 0 { if sec == 0 { self.view.backgroundColor = .red } else if sec <= 10 { self.view.backgroundColor = .orange else if sec <= 30 { self.view.backgroundColor = .yellow else { self.view.backgroundColor = .green // CODE FOR UPDATING THE LABELS suppose we wanted to add color to the display 30<sec : green 10<sec<30 : yellow 0<sec<10 : orange 0=sec : red add the code on the right

10 Random quotes suppose we wanted to develop an app for displaying random quotes we have already seen how to read from a file added to the project Bundle could start with a file of quotes, one per line add it to the project Bundle, then read it in when the app loads will need to be able to split it into its components, separated by newLines finally, select and display a random quote when the user clicks on a button

11 App example

12 Another approach maintaining & updating the list of quotes is work!
there exist Web sites that store and display thousands of quotes better solution would be to have the app request a quote directly from a site in order for the app to send requests to a Web server: must be able to specify a URL must be able to specify a request for data at that URL that request may have additional header information or, it may have queries attached to it finally, must be able to dispatch the request, wait for the response, and return the data when received

13 App example Concepts HTTP Requests URLSession dataTask downloadTask
uploadTask AlamoFire* API Really Web API Different URLs in Swift URL URLRequest URLComponents Asynchronous Calls DispatchGroup

14 App example (cont.)


Download ppt "CSC 581: Mobile App Development"

Similar presentations


Ads by Google