mobile apps programming

58
Mobile Apps Programming Chin-Sung Lin Eleanor Roosevelt High School

Upload: ting

Post on 24-Feb-2016

105 views

Category:

Documents


1 download

DESCRIPTION

Mobile Apps Programming. Chin-Sung Lin Eleanor Roosevelt High School. Mobile Apps Programming. Mobile Platforms Mobile Programming Tools Objective-C Language iPhone Apps Development Architecture iPhone App – Elro Movie Channel iPhone App – Quadratic Calculator - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Mobile  Apps  Programming

Mobile Apps ProgrammingChin-Sung LinEleanor Roosevelt High School

Page 2: Mobile  Apps  Programming

Mobile Apps Programming• Mobile Platforms• Mobile Programming Tools• Objective-C Language• iPhone Apps Development Architecture • iPhone App – Elro Movie Channel• iPhone App – Quadratic Calculator• iPhone App – Music Library• iPhone App – Elro Student App• iPhone App – Super Mario Bros. Maze Game• iPhone App – Light Balls Game

Page 3: Mobile  Apps  Programming

Mobile Platforms

Page 4: Mobile  Apps  Programming

Mobile Platforms

3 Major Mobile Platforms • iOS Platform• Windows Phone Platform• Android Platform

81.3% 4.1% 13.4%Q3 2013

Page 5: Mobile  Apps  Programming

Mobile Platforms

Mobile Platform Architecture

• Application – the layer users interact with.

• Core Libraries – the layer provides device

functionality the developers use to create apps.

• Operating System – the layer translates

programs into machine language.

• Hardware – the layer is the physical device.

Application

Core Libraries

Operating System

Hardware

Page 6: Mobile  Apps  Programming

iOS 7 Mobile Platform• iOS 7 is the 7th major release of the iOS mobile

operating system. It was released on 09/18/2013.• Support iPhone, iPod Touch, iPad, iPad Mini, and

second-generation Apple TV.• iOS 7 includes a redesigned user interface and

numerous functionality changes. • As of 12/2013, iOS 7 has been installed on 78% of

supported devices.• As of 10/2013, Apple's App Store contained more than

1 million iOS applications, 475,000 of which were optimised for iPad. These apps have collectively been downloaded more than 60 billion times.

Page 7: Mobile  Apps  Programming

Mobile Device Features• Internet access• Touch screen• GPS (Global Positioning System –

satellite-based system to determine a location)

• Local storage• Camera• Media playback• Phone• Bluetooth for device communication

Page 8: Mobile  Apps  Programming

Mobile Device Limitations• Screen size• No physical keyboard or trackball – a finger

or stylus is the primary interface to the device

• Memory• Storage• Battery Life• Cell network• Sometimes flaky networks

Page 9: Mobile  Apps  Programming

Mobile Programming Tools

Page 10: Mobile  Apps  Programming

Mobile Developer ProgramsRegistered Apple Developer• Free to access Apple developer tools and resources for creating iOS

and Mac apps, including Xcode, WWDC videos, sample code, and more.

• Web Address: https://developer.apple.com/register/index.action

iOS Developer Program• Test your apps on devices and distribute your apps on the App Store• $99 / year• Web Address: https://developer.apple.com/programs/ios/

Page 11: Mobile  Apps  Programming

Xcode 5 & iOS 7 SDk• Xcode is an integrated development environment (IDE) containing a

suite of software development tools developed by Apple for developing software for OS X and iOS.

• Xcode provides an interface to the compiler, editor, interface builder, debugger, simulator and code profiling tools.

• Available for free from the App Store

Page 12: Mobile  Apps  Programming

Xcode 5 IDE

Page 13: Mobile  Apps  Programming

Xcode 5 SimulatorSimulator• Simulates various features of a real iOS device.

Limitations• Making Phone calls• Accessing the Accelerometer/Gyroscope• Sending and Receiving SMS messages• Installing applications from the App Store• Accessibility to the Camera• Use of the Microphone• Several Core OpenGL ES Features

Page 14: Mobile  Apps  Programming

Xcode 5 Instruments• A performance, analysis, and testing tool for dynamically tracing and

profiling OS X and iOS code. • A flexible and powerful tool that lets you track one or more processes

and examine the collected data. • Helps you understand the behavior of both user apps and the

operating system.• Monitor your applications for memory leaks, which can cause

unexpected results.• Gain a deeper understanding of the execution behavior of your

applications.

Page 15: Mobile  Apps  Programming

Xcode 5 Instruments

Page 16: Mobile  Apps  Programming

Objective-C Language

Page 17: Mobile  Apps  Programming

Objective-C Language• An Object Oriented Programming (OOP) language.• Objective-C builds on top of C, and is a superset of C.• Objective-C is the primary programming language used for

programming iOS devices.

Page 18: Mobile  Apps  Programming

Objective-C Language Basics• Data Types• Data Types – Signed and Unsigned• Arithmetic Operators• Logic Operators• Compound Assignment Operators• Comparison Operators• Flow Control Statements • Looping Statements

Page 19: Mobile  Apps  Programming

Objective-C Language BasicsData Types• int: integer, 4 bytes• unsigned int: unsigned integer, 4 bytes• float: floating point number, 4 bytes• double: double precision, 8 bytes• char: character, 1 byte• string: string, depends on number of characters• bool: Boolean

Page 20: Mobile  Apps  Programming

Objective-C Language BasicsData Types – Signed and Unsigned• int – -2,147,483,647 up to 2,147,483,647• signed – default of all variable types• unsigned– maximum number 4,294,967,294

Page 21: Mobile  Apps  Programming

Objective-C Language BasicsArithmetic Operators• - (unary): negates the value of a variable or expression• +: addition• -: subtraction• *: multiplication• /: division• %: modulo

Page 22: Mobile  Apps  Programming

Objective-C Language BasicsLogic Operators• NOT (!): inverts the current value of a Boolean variable.• AND (&&): return true if both of the two operands evaluated to be true.• OR (||): return true if at least one of the two operands evaluated to be true.• XOR (^): return true if one and only one of the two operands evaluated to

be true.• Ternary/Conditional Operator ([condition] ? [true expression] : [false

expression]): if [condition] is true, the [true expression] will be evaluated; if [condition] is false, the [false expression] will be evaluated.

Page 23: Mobile  Apps  Programming

Objective-C Language BasicsCompound Assignment Operators• x += y: add x to y and place result in x• x -= y: subtract y from x and place result in x• x *= y: multiply x by y and place result in x• x /= y: divide x by y and place result in x• x %= y: perform modulo on x and y and place result in x• x &= y: assign to x the result of logical AND operation on x and y• x |= y: assign to x the result of logical OR operation on x and y• x ^= y: assign to x the result of logical XOR operation on x and y

Page 24: Mobile  Apps  Programming

Objective-C Language BasicsComparison Operators• x == y: return true if x is equal to y• x != y: return true if x is not equal to y• x > y: return true if x is greater than y• x >= y: return true if x is greater than or equal to y• x < y: return true if x is less than y• x <= y: return true if x is less than or equal to y

Page 25: Mobile  Apps  Programming

Objective-C Language BasicsFlow Control Statements with if and else• if (Boolean expression) { statements; }• if (Boolean expression) { statements; } else { statements; } • if (Boolean expression) { statements; } else if { statements; } …………• if (Boolean expression) { statements; } else if { statements; } ………… else { statements; }• Braces ({ }) are required if more than one statement is executed after the if/else.

Page 26: Mobile  Apps  Programming

Objective-C Language BasicsLooping Statements• for loop:

for ([initializer]; [conditional expression]; [loop expression]) {statements;}• while loop:

while ( [conditional expression]) {statements;}

• do... while loop:do{statements;} while ( [conditional expression])

• Braces ({ }) are required if more than one statement is executed after the if/else.

Page 27: Mobile  Apps  Programming

Objects and ClassesObjects• Objects are based on the objects in the real world.

• Objects are self-contained modules of functionality that can be easily used, and reused as the building blocks for a software application.

• Objects consist of data variables and functions (called methods) that can be accessed and called on the object to perform tasks.

Page 28: Mobile  Apps  Programming

Objects and ClassesClasses• Objects of the same kind are said to be members of the same Class. All

members of a Class are able to perform the same methods and have matching sets of instance variables. They also share a common definition.

• A Class defines what an Object will look like when it is created.

• A Class defines what the Methods will do and what Instance Variables will be.

Page 29: Mobile  Apps  Programming

Objects and ClassesCreating New Classes• First need to declare it using an interface and then define it using an

implementation. The declaration (.h) and the definition (.m) are usually written in two separate files.

• Both the declaration and the definition parts use compiler directives. A compiler directive is an instruction to the Objective-C compiler prefixed by the @ sign. The declaration is signaled to the compiler using the @interface directive, while the definition is signaled using the @implementation directive.

Page 30: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Declaration• A new class MyClassName is declared and is a subclass of the

MyParentClassName class.

@interface MyClassName : MyParentClassName

{

// attribute declarations: (instance variables)

}

// method declarations

@end

Page 31: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Declaring Instance Variables• Data Encapsulation: Data should be stored within classes and accessed only

through methods defined in that class.

• Data encapsulated in a class are referred to as instance variables (ivars).

• Instance Variables are declared in the same way any other variables are declared in Objective-C.

Page 32: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Declaring Instance Variables• Two new instance variables of class MyClassName are declared between the

braces. @interface MyClassName : MyParentClassName

{

int firstVar;

int secondVar;

}

// method declarations

@end

Page 33: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Defining Instance Methods• Methods: The methods of a class are code routines that can be called upon

to perform specific tasks within the context of an instance of that class.

• Methods come in two different forms, class methods (preceded by +) and instance methods (preceded by -) .

• Class methods operate at the level of the class such as creating a new instance of a class.

• Instance methods operate only on the instance of the class.

Page 34: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Defining Instance Methods• Data Type of Methods:

– If a method returns a result, the name of the method must be preceded by the data type returned enclosed in parentheses.

– If a method does not return a result, then the method must be declared as void.

• Arguments of Methods: If data (called arguments) needs to be passed through to a method, the method name is followed by a colon, the data type in parentheses, and a name for the argument.

• Methods may accept more than one arguments.

Page 35: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Defining Instance Methods• Three new instance methods of class MyClassName are declared between

the closing brace and @end. @interface MyClassName : MyParentClassName{

int firstVar;int secondVar;

}- (void) setMyClass: (int) x andNext: (int) y;- (int) addVariables;- (void) displayVarSum;@end

Page 36: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Declaring Class Implementation

• Method Implementation: write the code for the methods we have declared

earlier in the @interface section of the class declaration (.h).

• Methods are implemented in the @implementation section of the class

definition (.m).

Page 37: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Declaring Class ImplementationTwo methods of class MyClassName are implemented in the @implementation section of the MyClassName.m file.

#import “MyClassName.h”@implementation MyClassName- (void) setMyClass: (int) x andNext: (int) y;

{firstVar = x;secondVar = y;

}

Page 38: Mobile  Apps  Programming

Objects and ClassesCreating New Classes – Declaring Class Implementation

- (int) addVariables; {

return firstVar + secondVar; }

- (void) displayVariable: (int) x; {

NSLog(@”Variable value = %i and %d” firstVar, secondVar ; }@end

Page 39: Mobile  Apps  Programming

iPhone Apps Development Architecture

Page 40: Mobile  Apps  Programming

Mobile Apps Development Architecture

A few fundamental design patterns that form the development architecture of any apps.

• Model-View-Controller— governs the overall structure of your app.

• Target-Action— translates user interactions with buttons and controls into code that your app can execute.

• Subclassing— creates new classes from an existing class and extends the functionality.

• Delegation— facilitates the transfer information and data from one object to another.

Page 41: Mobile  Apps  Programming

Mobile Apps Development Architecture

Model-View-Controller• Separating user interface from application logic and data handling.

• Model-View-Controller (MVC) methodology increases reusability.

• MVC is the paradigm of iOS programming.

– Model: Hold data, should know nothing of the interface.

– View: code for getting data in/out of a view. Deals with items like buttons, lists, tables, etc.

– Controller: keeps the Model objects and View objects in sync.

• Model, View and Controller are objects.

Page 42: Mobile  Apps  Programming

Mobile Apps Development Architecture

• A view controller object interacts with model through Methods and Properties exposed by the Model object.

• A view controller object interacts with view through Target-Action pattern, together with Outlets and Actions.

Page 43: Mobile  Apps  Programming

Model-View-Controller

Page 44: Mobile  Apps  Programming

Mobile Apps Development Architecture

Target-Action pattern, IBOutlets and IBActions

• A view controller object interacts with view through Target-Action pattern, together with Outlets and Actions.

• Target-Action connects the triggered events in the user interface to the specific methods in the view controller using actions.

• An Action is a method defined within a view controller object that is designed to be called when an event is triggered in a view object.

• The opposite of an Action is the Outlet.

• An Outlet allows a view controller object method to directly access the properties of a view object.

Page 45: Mobile  Apps  Programming

Mobile Apps Development Architecture

Subclassing

• A major feature of an Objective-Oriented Programming environment.

• The new class inherits all the functionality of the parent class combined with the additional new methods and properties.

• Ex: UIViewController is a generic view controller from which we will create a subclass so that we can add our own methods and properties.

Page 46: Mobile  Apps  Programming

Mobile Apps Development Architecture

Delegation

• Allows an object to pass the responsibility for performing one or more tasks onto another object.

• Allows the behavior of an object to be modified without having to go through the process of subclassing it.

• Ex: UIApplication delegates the applicationDidFinishLaunchingWithOptions: method to us so that we can write code to perform specific tasks when the app first loads.

Page 47: Mobile  Apps  Programming

iPhone AppELRO Movie Channel

Page 48: Mobile  Apps  Programming

ELRO Movie Channel

Page 49: Mobile  Apps  Programming

iPhone AppQuadratic Calculator

Page 50: Mobile  Apps  Programming

Quadratic Calculator

Page 51: Mobile  Apps  Programming

iPhone AppMultimedia Player

Page 52: Mobile  Apps  Programming

Multimedia Player

Page 53: Mobile  Apps  Programming

iPhone AppFlappy Bird Game App

Page 54: Mobile  Apps  Programming

Multimedia Player

Page 55: Mobile  Apps  Programming

Mobile Apps Development Process

Start from your……• needs,

• problems,

• dreams,

or, start from other people’s

• needs,

• problems,

• dreams.

Page 56: Mobile  Apps  Programming

Mobile Apps Development Process

Planning Process• Define the purpose and functionality of the mobile apps,

• Sketch the user interface (UI), and identify the required UI components,

• Specify the flow control, and configure the storyboard,

• List the number and types of images, graphics, videos, animations,

audios and sound effects required by the user interface of the apps,

• Identify the programming skill sets required for the apps, and

• Assign action items and set the project schedule.

Page 57: Mobile  Apps  Programming

Mobile Apps Development Process

Implementation Process

• Design the user interface (UI), and photoshop the required UI components.

• Specify the flow control, and configure the storyboard.

• Acquire or create various types of images, graphics, videos, animations, audios and sound effects required by the user interface of the apps.

• Do online research and acquire the programming skill sets required for the apps.

• Create product description and promotion document for the App Store.

• Check project schedule and progress, and identify ricks and issues.

Page 58: Mobile  Apps  Programming

Q & A