iPhone – Walkthrough - PowerPoint PPT Presentation

About This Presentation
Title:

iPhone – Walkthrough

Description:

iPhone Walkthrough By: Hector M Lugo-Cordero, MS Saad A Khan, MS EEL 6788 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * SDK Demo ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 20
Provided by: csUcfEdu3
Learn more at: http://www.cs.ucf.edu
Category:

less

Transcript and Presenter's Notes

Title: iPhone – Walkthrough


1
XCode
  • Replaced Project Builder
  • Organizes files
  • Includes an editor
  • Multiple testing targets
  • Useful for iPhone, MAC
  • Red link (app not build)

2
Interface Builder
  • Works in collaboration with XCode
  • Good for developing the App View
  • Need to add keywords to the code
  • IBOutlet translates to nothing
  • IBAction translates to void
  • Organized by category of usage

3
SDK Demo
4
Using the sensors
  • Camera
  • Microphone
  • Proximity
  • Accelerometer
  • Magnetometer
  • GPS
  • Making calls
  • Sending messages

5
Sensors on devices
6
Camera
  • Use UIImagePickerController
  • Implement UIImagePickerControllerDelegate
  • UIImagePickerController picker
    UIImagePickerController alloc init
  • picker.delegate pickerDelegate //can be self
  • picker.sourceType UIImagePickerControllerSourceT
    ypeCamera
  • Implement the following method in delegate
    (called after picture is taken)
  • - (void)imagePickerController(UIImagePickerContro
    ller )picker didFinishPickingImage(UIImage
    )image editingInfo(NSDictionary )editingInfo

7
Microphone
  • Core Audio library (AVAudioRecorder)
  • NSURL url NSURL fileURLWithPath_at_"/dev/null"
  • NSDictionary settings NSDictionary
    dictionaryWithObjectsAndKeys NSNumber
    numberWithFloat 44100.0, AVSampleRateKey,
    NSNumber numberWithInt kAudioFormatAppleLossless
    , AVFormatIDKey, NSNumber numberWithInt 1,
    AVNumberOfChannelsKey, NSNumber numberWithInt
    AVAudioQualityMax, AVEncoderAudioQualityKey,
    nil
  • NSError error
  • recorder AVAudioRecorder alloc
    initWithURLurl settingssettings errorerror
  • if (recorder)
  • recorder prepareToRecord
  • recorder.meteringEnabled YES
  • recorder record
  • else NSLog(error description)

8
Proximity
  • Turn them on
  • UIDevice device UIDevice currentDevice
  • device.proximityMonitoringEnabled YES
  • BOOL state device.proximityState
  • Set notifications
  • NSNotificationCenter defaultCenter
    addObserver self
  • selector _at_selector(proximityChanged)
  • name _at_"UIDeviceProximityStateDidChangeNotificatio
    n"
  • object device
  • - (void) proximityChanged (NSNotification )note
  • UIDevice device note object
  • NSLog(_at_"In proximity i",
    device.proximityState)

9
Accelerometer
  • Range is -0.5, 0.5
  • Declare a class
  • Start accelerometer
  • Take measurements

10
Accelerometer (cont.)
  • _at_interface AccelController UIViewControllerltUIAcc
    elerometerDelegategt
  • UIAccelerometer accelerometer
  • _at_end
  • //start
  • - (void)viewDidLoad
  • accelerometer UIAccelerometer
    sharedAccelerometer
  • accelerometer.updateInterval 0.1
  • accelerometer.delegate self
  • super viewDidLoad

11
Accelerometer (cont.)
  • - (void)accelerometer(UIAccelerometer )meter
  • didAccelerate(UIAcceleration
    )acceleration
  • float x acceleration.x
  • float y acceleration.y
  • float z acceleration.z
  • float angle atan2(y, x)
  • ...

12
Magnetometer
  • Core location, but available only for 3GS
  • LocationManager CLLocationManager alloc
    init
  • locationManager.delegate self
  • if( locationManager.locationServicesEnabled
  • locationManager.headingAvailable)
  • locationManager startUpdatingLocation
  • locationManager startUpdatingHeading
  • else
  • ...

13
Magnetometer (Delegate)
  • - (void)locationManager(CLLocationManager )
    manager
  • didUpdateHeading(CLHeading ) newHeading
  • if (newHeading.headingAccuracy gt 0)
  • CLLocationDirection theHeading
  • newHeading.magneticHeading
  • ...
  • //to show calibration panel
  • -(BOOL)locationManagerShouldDisplayHeadingCalibrat
    ion
  • (CLLocationManager )manager
  • return YES

14
GPS
  • Core location
  • locationManager CLLocationManager alloc
    init
  • locationManager.delegate self
  • if( locationManager.locationServicesEnabled )
  • locationManager startUpdatingLocation
  • else
  • ...
  • locationManager.desiredAccuracy
    kCLLocationAccuracyKilometer

15
GPS (Delegate methods)
  • - (void)locationManager(CLLocationManager
    )manager didUpdateToLocation (CLLocation
    )newLocation fromLocation(CLLocation
    )oldLocation
  • if( newLocation ! oldLocation )
  • - (void)locationManager(CLLocationManager
    )manager didFailWithError (NSError )error

16
Making calls, Emails, and SMS
  • Calls, emails, and SMS are treated like URL
    services (UIApplication.sharedApplication)
  • UIApplication sharedApplication openURL
  • NSURL URLWithString_at_"tel//123-456-7890"
  • UIApplication sharedApplication openURLNSURL
    URLWithString_at_"mailtoemailAdress?subjecttestMai
    lbodyits test mail."
  • UIApplication sharedApplication openURLNSURL
    URLWithString_at_"sms111"

17
App Examples
  • Battery monitor
  • LocateMe
  • WhichWayIsUp
  • Accerlerometer

18
References
  • http//developer.apple.com/iphone
  • http//www.learningiphoneprogramming.com/
  • http//mobiforge.com/developing/story/deploying-ip
    hone-apps-real-devices
  • http//www.wikipedia.org

19
Questions
Write a Comment
User Comments (0)
About PowerShow.com