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

Post on 19-Jan-2016

214 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Mobile Apps Programming

Chin-Sung Lin

Eleanor Roosevelt High School

Mobile Apps Programming

• Mobile Platforms

• Mobile Programming Tools

• Objective-C Language

• Objects and Classes

• iPhone Apps Development Architecture

• iPhone Apps Tutorials

• Mobile Apps Development Process

Mobile Platforms

Mobile Platforms

3 Major Mobile Platforms

• iOS Platform

• Windows Phone Platform

• Android Platform

81.3% 4.1% 13.4%Q3 2013

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

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.

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

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

Mobile Programming Tools

Mobile Developer Programs

Registered 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/

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

Xcode 5 IDE

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

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.

Xcode 5 Instruments

Objective-C Language Basics

Objective-C Language Basics

• 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.

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

Objective-C Language Basics

Data 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

Objective-C Language Basics

Data 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

Objective-C Language Basics

Arithmetic Operators

• - (unary): negates the value of a variable or expression

• +: addition

• -: subtraction

• *: multiplication

• /: division

• %: modulo

Objective-C Language Basics

Logic 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.

Objective-C Language Basics

Compound 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

Objective-C Language Basics

Comparison 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

Objective-C Language Basics

Flow 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.

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.

Objects and Classes

Objects and Classes

Objects

• 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.

Objects and Classes

Classes

• 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.

Objects and Classes

Creating 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.

Objects and Classes

Creating 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

Objects and Classes

Creating 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.

Objects and Classes

Creating 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

Objects and Classes

Creating 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.

Objects and Classes

Creating 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.

Objects and Classes

Creating 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

Objects and Classes

Creating 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).

Objects and Classes

Creating New Classes – Declaring Class Implementation

Two 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;

}

Objects and Classes

Creating New Classes – Declaring Class Implementation

- (int) addVariables; {

return firstVar + secondVar; }

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

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

iPhone Apps Development Architecture

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.

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.

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.

Model-View-Controller

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.

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.

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.

iPhone Apps Tutorials

iPhone AppELRO Movie Channel

ELRO Movie Channel

iPhone AppQuadratic Calculator

Quadratic Calculator

iPhone AppMultimedia Player

Multimedia Player

iPhone AppFlappy Bird Game App

Multimedia Player

Mobile Apps Development Process

Start from your……

• needs,

• problems,

• dreams,

or, start from other people’s

• needs,

• problems,

• dreams.

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.

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.

Q & A

top related