iOS App Components CS 4720 Mobile Application Development CS 4720 - - PowerPoint PPT Presentation

ios app components
SMART_READER_LITE
LIVE PREVIEW

iOS App Components CS 4720 Mobile Application Development CS 4720 - - PowerPoint PPT Presentation

iOS App Components CS 4720 Mobile Application Development CS 4720 iOS Architecture CS 4720 2 Building Blocks UIApplication The main entry point for your app Each app has exactly one instance of this class Provides the


slide-1
SLIDE 1

CS 4720

iOS App Components

CS 4720 – Mobile Application Development

slide-2
SLIDE 2

CS 4720

iOS Architecture

2

slide-3
SLIDE 3

CS 4720

Building Blocks

  • UIApplication

– The main entry point for your app – Each app has exactly one instance of this class – Provides the main interface back to the OS – Handles all incoming info from the OS (such as touch event, memory warnings, incoming phone call, etc.) – Passes these messages off to…

3

slide-4
SLIDE 4

CS 4720

Building Blocks

  • UIApplicationDelegate

– Manages the running of your app – Handles “major” events, like app swtiching, app initialization, etc.

4

slide-5
SLIDE 5

CS 4720

AppDelegate.swift

5

import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow?

slide-6
SLIDE 6

CS 4720

AppDelegate.swift

6

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { return true }

slide-7
SLIDE 7

CS 4720

Other Components

  • UIDocument: allows for internal app

documents and data stores

  • ViewController: manages all views

(scenes) for the app

  • UIWindow: the one window of the iOS device

(only have more if external display)

  • View Objects: all the widgets in a scene

7

slide-8
SLIDE 8

CS 4720

The Main App Loop

8

slide-9
SLIDE 9

CS 4720

The Main App Loop

  • The OS receives input and passes it to the

UIApplication

  • Which passes it to the

UIApplicationDelegate

  • Which passes it to the UIWindow
  • Which passes it to the currently seen

ViewController

9

slide-10
SLIDE 10

CS 4720

The Main App Loop

  • Other events are passed to the “First

Responder” object that is available

  • Everything that can accept and respond to an

event is a responder object

  • The first responder object is the top-level

designated object in a view to handle events

10

slide-11
SLIDE 11

CS 4720

App States

11

slide-12
SLIDE 12

CS 4720

AppStates

  • applicationWillEnterForeground – starting to

move to active state

  • applicationDidBecomeActive – called right

before view displayed

  • applicationWillResignActive – first call before

going into background

  • applicationDidEnterBackground – now is in

background

  • applicatinoWillTerminate – will end

12

slide-13
SLIDE 13

CS 4720

On Launch

  • application comes in with

didFinishLaunchingWithOptions

  • Check dictionary launchOptions for info on

why was launched (somewhat like looking at the Intent)

  • Any app not responding in 5 seconds is killed
  • Start initialization
  • UIKit grabs first storyboard and

ViewController

13

slide-14
SLIDE 14

CS 4720

Inside the View

14

slide-15
SLIDE 15

CS 4720

Using Segues

  • Instead of Intents like Android, we’ll use

Segues to pass data between Scenes / ViewControllers

15

slide-16
SLIDE 16

CS 4720

MVC in iOS

  • We again see Model-View-Controller as part of

the foundation for a mobile system

  • Because of the nature of Objective-C and

NeXTSTEP, MVC is one of the primary design patterns for both iOS and OS X

16

slide-17
SLIDE 17

CS 4720

MVC in iOS

17

slide-18
SLIDE 18

CS 4720

MVC in iOS

18

slide-19
SLIDE 19

CS 4720

MVC in iOS

  • Model: The base classes you write to hold data

– Could subclass NSObject/Object – Could connect to a database or other data source – Could be a simple class you write

19

slide-20
SLIDE 20

CS 4720

MVC in iOS

  • View: Any rectangular drawable object on the

screen

– Various Stack, Table, and Collection Views – Image, Text, Picker Views – Map and WebKit View – Scene Kit View (for 3D scenes) – Manages drawing its area on the screen – Can contain other views (or be contained) – Responds to touch and other events

20

slide-21
SLIDE 21

CS 4720

MVC in iOS

  • Controller: The ViewController class

– Each ViewController manages a hierarchy of Views – The view property of the class contains the root – Views are access lazily; that is, they are only loaded when needed – Updates the contents of the views, usually in response to changes to the underlying data – Responds to user interactions with views – Resizes views and manages the layout of the

  • verall interface

21

slide-22
SLIDE 22

CS 4720

Building up in MVC

  • Start by considering your data

– Where does it come from? – How will you store it? – What sort of access do you need from it?

22

slide-23
SLIDE 23

CS 4720

Building up in MVC

  • Storyboard your idea

– Just as with Android, layout each screen – What views make up each screen?

  • Text?
  • A Table?
  • An Image?

– What happens when you touch or swipe on each view? Or on the screen?

23

slide-24
SLIDE 24

CS 4720

Building up in MVC

  • Create the appropriate Controller type
  • Add Views to the Controller to get the layout

the way you want it

  • Start with dummy data
  • Run in the simulator often!
  • Check and adjust your constraints to get

everything on screen

  • Test rotation!

24

slide-25
SLIDE 25

CS 4720

Building up in MVC

  • In your Storyboard, link the various Views back

to the code using ctrl-click/drag

  • Do the same for buttons and other controls
  • Load data as needed to refresh the view (often

happens automatically)

  • Add in code to handle user events, like touches

and swipes

  • Add Navigation Controllers to allow for

switching between scenes

25