<<  Apple 2014 Apple 2012  >>
LAMAD
LAMAD
The Platform and SDK
The Platform and SDK
iOS
iOS
Market share
Market share
iOS: Advantages and disadvantages
iOS: Advantages and disadvantages
Technology
Technology
Installing development kit
Installing development kit
Apple developer program
Apple developer program
iOS development
iOS development
iOS debugging
iOS debugging
App Store / Marketplace summary
App Store / Marketplace summary
Objective C
Objective C
Messages
Messages
Cocoa API
Cocoa API
Memory allocation
Memory allocation
C++ vs
C++ vs
Hello world example
Hello world example
Hello World
Hello World
New Project
New Project
New Project
New Project
Create interface
Create interface
Creating main screen
Creating main screen
Delete default screen
Delete default screen
Add items to screen
Add items to screen
Create a class for the screen
Create a class for the screen
Connect your class to the storyboard
Connect your class to the storyboard
Add an action to the button
Add an action to the button
Add an action to the button
Add an action to the button
Source files
Source files
Prepare application
Prepare application
Run the application
Run the application
Run the application on phone
Run the application on phone
Maps and location
Maps and location
Include CoreLocation and MapKit
Include CoreLocation and MapKit
Adding a Map View
Adding a Map View
Displaying location on the map
Displaying location on the map
Show a pin on the map
Show a pin on the map
Show a pin on the map
Show a pin on the map
Show a pin on the map
Show a pin on the map
Handling location
Handling location
Handling location
Handling location
Handling location
Handling location
Handling location
Handling location
Handling location
Handling location

: Apple 2013. : radum. : Apple 2013.ppt. zip-: 3806 .

Apple 2013

Apple 2013.ppt
1 LAMAD

LAMAD

iOS 25.03.2013

2 The Platform and SDK

The Platform and SDK

3 iOS

iOS

iPad

iPhone

iPad Mini

4 Market share

Market share

Second mobile OS in usage First mobile OS in revenue First mobile OS in internet traffic

Market Share 2012

5 iOS: Advantages and disadvantages

iOS: Advantages and disadvantages

+ Highest revenue for mobile OS + Little fragmentation (just iPhone and iPad) + Runs on high-end devices + Big developer community and excellent support + Many open-source libraries available - Strictly controlled by Apple - Development only possible in Mac OS - Objective C is the main programming language

6 Technology

Technology

Application development in Objective C a language that adds Smalltalk-style messaging to C

Development done in Xcode on Mac OS devices Debugging and running on phone done also in Xcode

7 Installing development kit

Installing development kit

Install Xcode IDE newest version 4.6.1 Installing Xcode automatically installs iOS SDK Xcode is free to download from Mac App store

8 Apple developer program

Apple developer program

Apple developer account is free Apple developer program is not free 99$/year Registration done from https://developer.apple.com/programs/ios/ Registration process takes 3-5 days

9 iOS development

iOS development

10 iOS debugging

iOS debugging

11 App Store / Marketplace summary

App Store / Marketplace summary

iOS

Android

Windows Phone

Approval Process

Yes

No

Yes

Distribution outside the store

No

Yes

No

Fragmentation

Very Little

Yes

Yes

Multiple stores / Marketplaces

No

Yes

No

12 Objective C

Objective C

Objective-C is an object oriented language Follows ANSI C style coding with methods from Smalltalk Flexible because almost everything is done at runtime: Dynamic Binding Dynamic Typing Dynamic Linking It is used for both iOS and Mac OS development Source files: .m, header files: .h Has protocols, which work like interfaces in Java they specify a number of methods a class must implement

13 Messages

Messages

Almost every object manipulation is done by sending objects a message Two words within a set of brackets, the object identifier and the message to send: [self.mainLabel setText:[self.mainTextInput text]]; Dot syntax: self.mainLabel.text = self.mainTextInput.text; Equivalent to C++ or Javas: this.mainLabel.setText( this.mainTextInput.text() ); Static methods start with +, instance methods with -: +(id)defaultController vs. -(void)initLocationManager

14 Cocoa API

Cocoa API

A collection of libraries developed by Apple to aid GUI development Has a set of predefined classes and types such as NSNumber, NSString, NSDate (NS stands for NeXT-sun) Includes a root class NSObject where keywords like alloc, retain, and release come from Apple Human Interface Guidelines: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html

15 Memory allocation

Memory allocation

Objects are created dynamically using alloc keyword Objects are automatically deallocated in latest Objective-C through automatic reference counting (ARC) ARC keeps an internal count of how many times an Object is 'needed' System makes sure that objects that are needed are not deleted, and when an object is not needed it is deleted

16 C++ vs

C++ vs

Objective-C

C++

Objective C

Adds OOP, metaprogramming and generic programming to C

Only adds OOP to C

Comes with a std library

Has no standard library; is dependant on other libraries

Has numerous uses

Mostly used for application building

Large and complex code for OOP

Simpler way of handling classes and objects

17 Hello world example

Hello world example

18 Hello World

Hello World

Task: Change a labels text using a button and an input box. Create a new empty project:

19 New Project

New Project

Name the project and check Use Core Data and User Automatic Reference Counting

20 New Project

New Project

Create the project and also create local git repository for source control

21 Create interface

Create interface

Create a new storyboard file Empty storyboard will be created

22 Creating main screen

Creating main screen

Click on the storyboard Create a navigation controller from the storyboard designer by drag and drop

23 Delete default screen

Delete default screen

Delete the default Table View Controller and add your own View Controller by drag and drop Right click from the navigation controller to View Controller and choose root view controller relationship

24 Add items to screen

Add items to screen

Add items to screen by using drag and drop: label, button and text edit

Attention! Disable Use Autolayout from View Controller properties if you want application to work in iOS 5 and earlier

25 Create a class for the screen

Create a class for the screen

The class should subclass UiViewController

26 Connect your class to the storyboard

Connect your class to the storyboard

Make the View Controller in the storyboard to be you class

Open Assistant editor

Drag and drop interface objects to you class h file to create connections

27 Add an action to the button

Add an action to the button

Right click on the button Choose Touch Up Inside and drag and drop to the h file Name the method that will be executed when button is touched

28 Add an action to the button

Add an action to the button

Name the method that will be executed when button is touched

29 Source files

Source files

Header file will look like this: #import <UIKit/UIKit.h> @interface MainViewController : UIViewController @property (strong, nonatomic) IBOutlet UIButton *mainButton; @property (strong, nonatomic) IBOutlet UITextField *mainTextInput; @property (strong, nonatomic) IBOutlet UILabel *mainLabel; - (IBAction)changeLabel:(id)sender; @end

Change label text: - (IBAction)changeLabel:(id)sender { // Change the text [self.mainLabel setText:[self.mainTextInput text]]; }

30 Prepare application

Prepare application

Go to the auto-generated AppDelegate file and include your own Ui class

Delete the gray bold text from didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }

31 Run the application

Run the application

Go to project properties and set your storyboard as Main Storyboard

Press run in simulator

32 Run the application on phone

Run the application on phone

Open the organizer

Log in with your developer id You need to be enroller in developer program Connect the phone to the computer Add the device to your provisioning portal

33 Maps and location

Maps and location

34 Include CoreLocation and MapKit

Include CoreLocation and MapKit

Go to your project properties, libraries and press to add CoreLocation and MapKit for location and map support By default, they are not added to your project

35 Adding a Map View

Adding a Map View

Add a Map View to you main screen from the designer

36 Displaying location on the map

Displaying location on the map

Check Shows User Location from Map View properties Run the application

37 Show a pin on the map

Show a pin on the map

Create a class which implements MKAnnotation protocol

.h file: #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interface UEFPin : NSObject <MKAnnotation> @property (nonatomic, assign) CLLocationCoordinate2D coordinate; @property (nonatomic, strong) NSString *title; @property (nonatomic, strong) NSString *subtitle; -(id)initWithCoordinate:(CLLocationCoordinate2D)location andTitle:(NSString*)aTitle; @end .m File: #import "UEFPin.h" @implementation UEFPin @synthesize title, subtitle, coordinate; -(id)initWithCoordinate:(CLLocationCoordinate2D)location andTitle:(NSString*)aTitle { self = [super init]; if(self) { self.coordinate = location; self.title = aTitle; } return self; } @end

38 Show a pin on the map

Show a pin on the map

In your view controller viewDidAppear create the pin and zoom to it

Create a location

Create a region centered on location

Set self as map delegate

Create the pin Zoom to the region

- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; CLLocationCoordinate2D location; location.latitude = 62.598; location.longitude = 29.745; MKCoordinateRegion region; MKCoordinateSpan span; span.latitudeDelta=0.01; span.longitudeDelta=0.01; region.span=span; region.center=location; [mapView setDelegate:self]; [mapView addAnnotation:[[UEFPin alloc] initWithCoordinate:location andTitle:@"Joensuu Science Park"]]; [mapView setRegion:region animated:TRUE]; [mapView regionThatFits:region]; }

39 Show a pin on the map

Show a pin on the map

Make your view controller implement MKAnnotation protocol and implement viewForAnnotation method

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapPin"]; annView.pinColor = MKPinAnnotationColorGreen; annView.animatesDrop=YES; annView.showsCallout=YES; return annView; }

40 Handling location

Handling location

Create a class which implements CLLocationManagerDelegate protocol and has a CLLocationManager object Header file:

@interface LocationController : NSObject <CLLocationManagerDelegate> // Class members: Location manager and current location container @property (nonatomic, retain) CLLocationManager *locationManager; @property (nonatomic, retain) CLLocation *currentLocation; + (id)defaultController; // Static singleton // Init, start and stop Location Manager - (void) initLocationManager; - (void) startLocationManager:(CLLocationAccuracy)accuracy; - (void) stopLocationManager; @end

41 Handling location

Handling location

#import "LocationController.h" @implementation LocationController @synthesize locationManager, currentLocation; // Autogenerate getters and setters + (id)defaultController {// Static singleton static LocationController *sharedController = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedController = [[self alloc] init]; }); return sharedController; } - (id) init {// This will be called when instantiating object self = [super init]; if (self != nil) { [self initLocationManager]; // Custom init code } return self; } -(void) dealloc { // Called when deleting objects if(self.locationManager != nil) [self.locationManager stopUpdatingLocation]; // Make sure all objects are nil so Automatic Reference Count will delete them [self setLocationManager:nil]; [self setCurrentLocation:nil]; }

42 Handling location

Handling location

- (void) initLocationManager { self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // send loc updates to myself currentLocation = [[CLLocation alloc] initWithLatitude:0 longitude:0]; // start location [self startLocationManager:kCLLocationAccuracyBestForNavigation]; } -(void) startLocationManager:(CLLocationAccuracy)accuracy { if(self.locationManager != nil) { self.locationManager.desiredAccuracy = accuracy; self.locationManager.distanceFilter = 0; self.locationManager.headingFilter = 0; // Start location updates if([CLLocationManager locationServicesEnabled]){ [self.locationManager startUpdatingLocation]; } } } -(void) stopLocationManager { [self.locationManager stopUpdatingLocation]; }

43 Handling location

Handling location

// This is called when location is updated - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSDate* eventDate = newLocation.timestamp; NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; if (abs(howRecent) < 60.0) { //Location timestamp is within the last 60.0 seconds, let's use it! if(newLocation.horizontalAccuracy < kMaxGpsAccuracy){ currentLocation = newLocation;; } } }

44 Handling location

Handling location

// Error handling - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSString *errorString; switch([error code]) { case kCLErrorDenied: //Access denied by user errorString = @"Access to Location Services denied by user; break; case kCLErrorLocationUnknown: //Probably temporary... errorString = @"Location data unavailable; break; default: errorString = @"An unknown error has occurred"; break; } NSLog(@"Error: %@, errorString); } @end // End of class implementation

Apple 2013
http://900igr.net/prezentacija/bez_uroka/apple-mart-2013-240488.html
c

1
900igr.net > > > Apple 2013