600 likes | 959 Views
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
E N D
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 • iPhone App – Music Library • iPhone App – Elro Student App • iPhone App – Super Mario Bros. Maze Game • iPhone App – Light Balls Game
MobilePlatforms 3 Major Mobile Platforms • iOS Platform • Windows Phone Platform • Android Platform 81.3% 4.1% 13.4% Q3 2013
MobilePlatforms 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 MobilePlatform • 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, iPadMini, and second-generation Apple TV. • iOS7 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
MobileDeveloper 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 • Xcodeis 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 Simulator Simulator • Simulates various features of a real iOSdevice. 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.
Objective-CLanguage • 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-CLanguage Basics • Data Types • Data Types – Signed and Unsigned • Arithmetic Operators • Logic Operators • Compound Assignment Operators • Comparison Operators • Flow Control Statements • Looping Statements
Objective-CLanguage 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-CLanguage 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-CLanguage Basics Arithmetic Operators • - (unary): negates the value of a variable or expression • +: addition • -: subtraction • *: multiplication • /: division • %: modulo
Objective-CLanguage 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-CLanguage 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-CLanguage 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-CLanguage 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-CLanguage Basics Looping 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.
Objectsand Classes Objects • Objects are based on the objects in the real world. • Objectsare self-contained modules of functionality that can be easily used, and reused as the building blocks for a software application. • Objectsconsist of data variables and functions (called methods) that can be accessed and called on the object to perform tasks.
Objectsand Classes Classes • Objects of the same kind are said to be members of the same Class. All members of a Classare able to perform the same methods and have matching sets of instance variables. They also share a common definition. • A Classdefines what an Object will look like when it is created. • A Classdefines what the Methods will do and what Instance Variables will be.
Objectsand Classes Creating New Classes • First need to declare it using an interfaceand 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 definitionis signaled using the @implementation directive.
Objectsand Classes Creating New Classes – Declaration • A new class MyClassNameis declared and is a subclass of the MyParentClassNameclass. @interface MyClassName : MyParentClassName { // attribute declarations: (instance variables) } // method declarations @end
Objectsand 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.
Objectsand Classes Creating New Classes – Declaring Instance Variables • Two new instance variables of class MyClassName are declared between the braces. @interface MyClassName : MyParentClassName { intfirstVar; intsecondVar; } // method declarations @end
Objectsand 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 methodsoperate at the level of the classsuch as creating a new instance of a class. • Instance methods operate only on the instance of the class.
Objectsand 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 methoddoes 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.
Objectsand 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 { intfirstVar; intsecondVar; } - (void) setMyClass: (int) x andNext: (int) y; - (int) addVariables; - (void) displayVarSum; @end
Objectsand 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).
Objectsand 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; }
Objectsand 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
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 iOSprogramming. • 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, Viewand 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.
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: UIApplicationdelegates the applicationDidFinishLaunchingWithOptions: method to us so that we can write code to perform specific tasks when the app first loads.