Iphone Programming
Total Page:16
File Type:pdf, Size:1020Kb
Mobile Applications and Services FALL 2013 - iOS basics Navid Nikaein Mobile Communication Department This work is licensed under a CC attribution Share-Alike 3.0 Unported license. What do you need? . Mac OS X 10.5 or above . Notions on OO programming (Objective C) . iOS SDK (Free, registration required) . iOS Dev License (Optional) Student Program: Free Individual Program: $99 Enterprise Program: $399 . An iPhone/iPod Touch/iPad (Optional) ©Navid Nikaein 2013 2 iOS Smart Mobile Devices . iOS 7 . Multi Touch Display (1.136x640) . Storage 8-64 GB . Processor M7 /A7 64 bits, A6, A5 . Graphics Power VR . Memory 1GB DDR2 . Connectivity Secondary USB 2.0 Applications GSM/GPRS/EDGE/UMTS/HSDPA/LTE Wifi 802.11 b/g/n BT Assisted GPS . Double Camera: 8 MP & 1.2MP Primary . HD Audio/VIDEO Applications . Power 3.8 V . Weight 112g ©Navid Nikaein 2013 3 Platform Components . iOS SDK / Tools . Language . Frameworks . Design Strategies ©Navid Nikaein 2013 4 Platform Component - iOS SDK . Tools: .m, .h .nib Xcode Text editor, Debugger & Compiler Interface Builder (UI) storyborad .xib Creates user interface (xml) Instruments (profiler ) Optimize the application Dash Code Create web applications for Safari iOS Simulator (Code-Build-Debug) Dtrace, NSZombies, Guard Mallloc Reference Library ©Navid Nikaein 2013 5 Xcode ©Navid Nikaein 2013 6 App Development Process . Who are your audience ? . What is the purpose of your app? . What problem your app trying to solve? . What content your app incorporate? ©Navid Nikaein 2013 7 Next step . After you have a concept for your app, designing a good user interface is the next step to creating a successful app Storyboard, views ,… Define the interaction Implementing the behaviours ©Navid Nikaein 2013 8 Platform Component - iOS Language . Objective-C / C Extension to (superset of) standard ANSI C with Smalltalk-style messaging designed to give C full OO programming capabilities Primary language for Apple’s Cocoa API C & GCC can be used for low-level programming ©Navid Nikaein 2013 9 A big Picture ©Navid Nikaein 2013 10 Platform Component - iOS Frameworks Name Prefixes Name Prefixes Accelerate.framework cblas, vDSP EventKitUI.framework EK AddressBook.framework AB ExternalAccessory.framework EA AddressBookUI.framework AB Foundation.framework NS AssetsLibrary.framework AL GameKit.framework GK AudioToolbox.framework AU,Audio iAd.framework AD AudioUnit.framework AU ImageIO.framework CG AVFoundation.framework AV IOKit.framework N/A CFNetwork.framework CF MapKit.framework MK CoreAudio.framework Audio MediaPlayer.framework MP CoreData.framework NS MessageUI.framework MF CoreFoundation.framework CF MobileCoreServices.framework UT CoreGraphics.framework CG OpenAL.framework AL CoreLocation.framework CL OpenGLES.framework EAGL, GL CoreMedia.framework CM QuartzCore.framework CA CoreMotion.framework CM QuickLook.framework QL CoreTelephony.framework CT Security.framework CSSM, Sec CoreText.framework CT StoreKit.framework SK CoreVideo.framework CV SystemConfiguration.framework SC EventKit.framework EK UIKit.framework UI ©Navid Nikaein 2013 11 iOS Frameworks: New Name Prefixes Account.framework AC CoreBluetooth.framework CB CoreImage.framework CI Core.MIDI.framework MIDI GLKit.framework GLK GSS.framework gss Twiter.framework TW See appendix B of iOS Technology Overview ©Navid Nikaein 2013 12 frameworks ©Navid Nikaein 2013 13 iOS Design Patterns and Techniques . Model-view-controller design pattern that governs the overall structure of your app . Delegation Transfer information and data from one object to another . Target-Action Translates user interactions with buttons and controls into code that your app can execute . Block-Objects Implement callbacks and asynchronous code . Sandboxing Protect the system and other apps ©Navid Nikaein 2013 14 Platform Component - iOS Design Strategy . Cocoa version of Model-View-Controller (MVC) Assigns objects in an application one of three roles: model, view, or controller Defines the way objects communicate with each other Separate and allow generic view and models Controllers acts as a glue between view and model . MVC allows reusability and flexibility to your application How your model is presented/viewed to the user (UI logic) knows how to draw itself and Encapsulate, manipulate, and process can respond to user actions the data specific to an application ©Navid Nikaein 2013 15 MVC . All about managing the communication between objects ©Navid Nikaein 2013 16 MVCs working together ©Navid Nikaein 2013 17 MVC . Model = manipulate and process data / algorithm / networking Not aware of controller and view To-one and to-many relationship with other model objects Communicate generically using broadcast channel Key-value observing (listen to changes) Notification (NSNotificationCenter) Communication example User actions in the view layer that create or modify data are communicated through a controller object and result in the creation or updating of a model object. When a model object changes (for example, new data is received over a network connection), it notifies a controller object, which updates the appropriate view objects ©Navid Nikaein 2013 18 MVC . View = Display / Event capture / Visual interaction Not aware of controller and model Know how to draw itself and user can interact with it Generic and provides consistency between applications Communicate generically using Target – Action Delegate (Will, did, should) Communication example View objects learn about changes in model data through the application’s controller objects User-initiated changes—for example, text entered in a text field— through controller objects to an application’s model objects. ©Navid Nikaein 2013 19 MVC . Controller = coordination / delegation / dirty job Know about view and model objects Manage views, datas, and application logic and lifecycle App –specific code Communication: A controller object interprets user actions made in view objects and communicates new or changed data to the model layer. When model objects change, a controller object communicates that new model data to the view objects so that they can display it. ©Navid Nikaein 2013 20 Application Object and Delegation . Application template comes with a few existing source code files that set up the app environment. UIApplicationMain function creates the app object to work with iOS create a run loop to deliver events to your app coordinates other high-level app behaviors Called by main.m . UIApplicationMain creates two components Application object: an instance of UIApplication App Delegate Window: creates and keep track of the window where your app’s content is drawn Lifecycle: provides a place to respond to state transitions within the app: ©Navid Nikaein 2013 21 Target-Action . Action Piece of code that’s linked to some kind of event that can occur in your app creating and implementing a method with an IBAction return type and a sender parameter - (IBAction)restoreDefaults:(id)sender; Sender points to the object that triggers the action . Outlet provide a way to reference objects from your interface @property (weak, nonatomic) IBOutlet UITextField *textField; . Control Event provide a way for your code to receive messages from the user interface Touch and drag events Editing events Value-changed events . Navigation controller Manage the transition between the views Navigation stack is LIFO, and the first item is always root view controller ©Navid Nikaein 2013 22 Sandbox . Fine-grained controls that limit the app’s access Hone of the app . App and its preferences and data are placed in sandbox at the install time ©Navid Nikaein 2013 23 Core Objects of an App Image View Text View Button ©Navid Nikaein 2013 24 App States . Not running app has not been launched or was running but was terminated by the system . Inactive running in the foreground but is currently not receiving events . Active running in the foreground and is receiving events . Background Background and executing code Before being suspended Background directly . Suspended Background and not executing code ©Navid Nikaein 2013 25 State Transitions . application:willFinishLaunchingWithOptions first chance to execute code at launch time. application:didFinishLaunchingWithOptions perform any final initialization before your app is displayed to the user. applicationDidBecomeActive Lets your app know that it is about to become the foreground app. Use this method for any last minute preparation. applicationWillResignActive Lets you know that your app is transitioning away from being the foreground app. Use this method to put your app into a quiescent state. applicationDidEnterBackground: Lets you know that your app is now running in the background and may be suspended at any time. applicationWillEnterForeground Lets you know that your app is moving out of the background and back into the foreground, but that it is not yet active. applicationWillTerminate Lets you know that your app is being terminated. This method is not called if your app is suspended. ©Navid Nikaein 2013 26 App Launch Cycle ©Navid Nikaein 2013 27 iOS Architecture . iOS can be viewed as a set of layers HW ©Navid Nikaein 2013 28 iOS Features . Media Graphics . Cocoa touch Audio UIkit Camera & photo lib Multitouch gestures iPod media lib Storyborad Document , printing . Core services iOS simulator . Networking Services Inter-app messaging Store Kit (in-app) Messaging Push notification In-app SMS Game Kit Cut, copy, paste iAd Gyro +