Your SlideShare is downloading. ×
0
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
iOS Sensors
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

iOS Sensors

7,116

Published on

Demonstrates the usage of all available iOS sensors with source code. Example use-cases are a compass, air level, navigation, acceleration and audio recording and playback.

Demonstrates the usage of all available iOS sensors with source code. Example use-cases are a compass, air level, navigation, acceleration and audio recording and playback.

Published in: Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,116
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
123
Comments
0
Likes
10
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 100iOS SensorsWhere Mobile Begins
  • 2. Roadmap 100RoadmapWhere We’re Going
  • 3. Teaser: What to Expect! 96TeaserWhat to Expect!
  • 4. Teaser: What to Expect! 96TeaserWhat to Expect! Digital Camera
  • 5. Teaser: What to Expect! 96TeaserWhat to Expect! Audio Sampler Digital Camera
  • 6. Teaser: What to Expect! 96TeaserWhat to Expect!Navigation System Audio Sampler Digital Camera
  • 7. Teaser: What to Expect! 96TeaserWhat to Expect! Air LevelNavigation System Audio Sampler Digital Camera
  • 8. Teaser: What to Expect! 96TeaserWhat to Expect! Ball Game Air LevelNavigation System Audio Sampler Digital Camera
  • 9. Teaser: What to Expect! 96TeaserWhat to Expect! Compass Ball Game Air LevelNavigation System Audio Sampler Digital Camera
  • 10. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference
  • 11. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference Speakers Speakers
  • 12. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference Speakers Speakers Microphone Microphone
  • 13. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference Speakers Speakers Microphone Microphone Camera Camera
  • 14. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference Speakers Speakers Microphone Microphone Camera Camera GPS
  • 15. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference Speakers Speakers Microphone Microphone Camera Camera GPSAccelerometer
  • 16. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference Speakers Speakers Microphone Microphone Camera Camera GPSAccelerometer Gyroscope
  • 17. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference Speakers Speakers Microphone Microphone Camera Camera GPSAccelerometer GyroscopeMagnetometer
  • 18. Mobile vs. Desktop: What’s the Difference 92Mobile vs. DesktopWhat’s the Difference Speakers Speakers Microphone Microphone Camera Camera GPSAccelerometer Mobile Sensors GyroscopeMagnetometer
  • 19. Sensors in 12 Device Generations 88Sensors in Device GenerationsGreat Common Denominators With iPodAll 12 Generations - 2007+ Without iPod
  • 20. Sensors in 12 Device Generations 88 Sensors in Device Generations Great Common Denominators With iPod All 12 Generations - 2007+ Without iPod100.00% 75.00% 50.00% 25.00% 0% Speaker Microphone Accelerometer GPS Camera Gyroscope Magnetometer
  • 21. Sensors in 7 Device Generations 84 Sensors in Device Generations Great Common Denominators With iPod Latest 7 Generations - 2010+ Without iPod100.00% 75.00% 50.00% 25.00% 0% Speaker Microphone Accelerometer GPS Camera Gyroscope Magnetometer
  • 22. Sensors in 7 Device Generations 84 Sensors in Device Generations Great Common Denominators With iPod Latest 7 Generations - 2010+ Without iPod100.00% 75.00% 50.00% Majority 25.00% 0% Speaker Microphone Accelerometer GPS Camera Gyroscope Magnetometer
  • 23. Delegate Pattern 80Delegate PatternQuick Look
  • 24. Delegate Pattern 80Delegate PatternQuick Look Delegate
  • 25. Delegate Pattern 80Delegate PatternQuick Look Delegate didArriveAtBar: didDrinkBeerNumber: didUpdateAlcoholLevel: wantsMeToComeHome: didCallCab: didEnterCab: didExitCab:
  • 26. Roadmap 76RoadmapWhere We’re Going
  • 27. Light: Implementing a Camera 72LightImplementing a Camera
  • 28. Light: Implementing a Camera 72 Light Implementing a Camera// setup image picker controllerimagePickerController = [[UIImagePickerController alloc] init];imagePickerController.allowsEditing = NO;imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;imagePickerController.delegate = self;// display[viewController presentModalViewController:imagePickerController animated:YES];// grab photo as soon as it was taken-(void) imagePickerController:(UIImagePickerController *)picker /didFinishPickingMediaWithInfo:(NSDictionary *)info{    // captured image    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];        // dismiss image picker    [viewController dismissModalViewControllerAnimated:YES];}
  • 29. Light: Implementing a Camera 72 Light Implementing a Camera// setup image picker controllerimagePickerController = [[UIImagePickerController alloc] init];imagePickerController.allowsEditing = NO;imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;imagePickerController.delegate = self;// display Camera Demo[viewController presentModalViewController:imagePickerController animated:YES];// grab photo as soon as it was taken-(void) imagePickerController:(UIImagePickerController *)picker /didFinishPickingMediaWithInfo:(NSDictionary *)info{    // captured image    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];        // dismiss image picker    [viewController dismissModalViewControllerAnimated:YES];}
  • 30. Sound: Implementing a Sound Recorder 68SoundImplementing a Sound Recorder
  • 31. Sound: Implementing a Sound Recorder 68 Sound Implementing a Sound Recorder// get audio sessionAVAudioSession *audioSession = [AVAudioSession sharedInstance];[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];[audioSession setActive:YES error:nil];// some settings NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];[settings setValue:[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];[settings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];[settings setValue:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];    tmpRecording = [NSURL fileURLWithPath:[NSTemporaryDirectory() /stringByAppendingPathComponent:@"recording.caf"]];// start recording  audioRecorder = [[AVAudioRecorder alloc] initWithURL:tmpRecording settings:settingserror:nil];[audioRecorder setDelegate:self];[audioRecorder prepareToRecord];[audioRecorder recordForDuration:2.0];    // do when recording is finished- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag{    isRecording = NO;    }
  • 32. Sound: Implementing a Sound Player 64SoundImplementing a Sound Player
  • 33. Sound: Implementing a Sound Player 64 Sound Implementing a Sound Player// get audio sessionAVAudioSession *audioSession = [AVAudioSession sharedInstance];[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];[audioSession setActive:YES error:nil];    tmpRecording = [NSURL fileURLWithPath:[NSTemporaryDirectory() /stringByAppendingPathComponent:@"recording.caf"]];// start playing  AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:tmpRecordingerror:nil];[player setDelegate:self];[player prepareToPlay];[player play];    // do when recording is finished- (void)audioRecorderDidFinishPlaying:(AVAudioRecorder *)recorder successfully:(BOOL)flag{    isPlaying = NO;  }
  • 34. Sound: Implementing a Sound Player 64 Sound Implementing a Sound Player// get audio sessionAVAudioSession *audioSession = [AVAudioSession sharedInstance];[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];[audioSession setActive:YES error:nil];     Sound DemotmpRecording = [NSURL fileURLWithPath:[NSTemporaryDirectory() /stringByAppendingPathComponent:@"recording.caf"]];// start playing  AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:tmpRecordingerror:nil];[player setDelegate:self];[player prepareToPlay];[player play];    // do when recording is finished- (void)audioRecorderDidFinishPlaying:(AVAudioRecorder *)recorder successfully:(BOOL)flag{    isPlaying = NO;  }
  • 35. Location: Implementing a Positioning System 60LocationImplementing a Positioning System
  • 36. Location: Implementing a Positioning System 60 Location Implementing a Positioning System// create location managerlocationManager = [[CLLocationManager alloc] init];locationManager.delegate = self;locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;    // start location update[locationManager startUpdatingLocation];// process position-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ // access position float latitude = newLocation.coordinate.latitude; float longitude = newLocation.coordinate.longitude;    // one position is enough    [locationManager stopUpdatingLocation];}
  • 37. Location: Implementing a Positioning System 60 Location Implementing a Positioning System// create location managerlocationManager = [[CLLocationManager alloc] init];locationManager.delegate = self;locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;     Positioning Demo// start location update[locationManager startUpdatingLocation];// process position-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ // access position float latitude = newLocation.coordinate.latitude; float longitude = newLocation.coordinate.longitude;    // one position is enough    [locationManager stopUpdatingLocation];}
  • 38. Magnetic Field: Implementing a Compass 56Magnetic FieldImplementing a Compass
  • 39. Magnetic Field: Implementing a Compass 56 Magnetic Field Implementing a Compass// setup location managerlocationManager = [[CLLocationManager alloc] init];locationManager.delegate = self;[locationManager startUpdatingHeading];// receive update of heading-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{ // device is pointing ‘heading’ away from north float heading = manager.heading.magneticHeading;    }
  • 40. Magnetic Field: Implementing a Compass 56 Magnetic Field Implementing a Compass// setup location managerlocationManager = [[CLLocationManager alloc] init];locationManager.delegate = self; Compass Demo[locationManager startUpdatingHeading];// receive update of heading-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{ // device is pointing ‘heading’ away from north float heading = manager.heading.magneticHeading;    }
  • 41. Roadmap 52RoadmapWhere We’re Going
  • 42. Accelerometer: May the Force be with you 48AccelerometerMay the Force be with you
  • 43. Accelerometer: May the Force be with you 48AccelerometerMay the Force be with you Force in g-force -1.00.0 0.0
  • 44. Accelerometer: May the Force be with you 48AccelerometerMay the Force be with you Force Rotation in g-force in degrees -1.0 0.00.0 -0.5 0.0 0.5
  • 45. Accelerometer: May the Force be with you 48AccelerometerMay the Force be with you Force Rotation in g-force in degrees Accelerometer Demo -1.0 0.00.0 -0.5 0.0 0.5
  • 46. Accelerometer: May the Force be with you 44AccelerometerMay the Force be with you
  • 47. Accelerometer: May the Force be with you 44 Accelerometer May the Force be with you// enable accelerometer[[UIAccelerometer sharedAccelerometer] setDelegate:self];// receive the acceleration values- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { // move ball ball.x += acceleration.x * kBallSpeed; ball.y += acceleration.y * kBallSpeed; // rotate air level level.rotation = acceleration.y * 90;}
  • 48. Gyroscope: I’m spinnin’ around 40GyroscopeI’m spinnin’ around
  • 49. Gyroscope: I’m spinnin’ around 40GyroscopeI’m spinnin’ aroundRotation Ratein radians per second 0.00.0 0.0
  • 50. Gyroscope: I’m spinnin’ around 40GyroscopeI’m spinnin’ aroundRotation Rate Absolute Rotationin radians per second in radians by adding all rates to reference frame 0.0 0.780.0 0.0 0.0 0.0
  • 51. Gyroscope: I’m spinnin’ around 40GyroscopeI’m spinnin’ aroundRotation Rate Absolute Rotationin radians per second in radians by adding all rates to reference frame Gyroscope Demo 0.0 0.780.0 0.0 0.0 0.0
  • 52. Gyroscope: I’m spinnin’ around 36GyroscopeI’m spinnin’ around
  • 53. Gyroscope: I’m spinnin’ around 36 Gyroscope I’m spinnin’ around// create core motion managermotionManager = [[CMMotionManager alloc] init];motionManager.gyroUpdateInterval = 1.0/60.0;[motionManager startGyroUpdates];// frequently call the update method[self schedule:@selector(update:)];// frequently read the gyro data-(void)update:(ccTime)dt { // absolute rotation rotationX += motionManager.gyroData.rotationRate.x; rotationY += motionManager.gyroData.rotationRate.y; // move ball ball.x += rotationX + kBallSpeed; ball.y += rotationY + kBallSpeed; // rotate air level level.rotation = rotationY * 180/PI;}
  • 54. CoreMotion: Use this! 32CoreMotionUse this!
  • 55. CoreMotion: Use this! 32CoreMotionUse this! + Raw data Accelerometer + Gyroscope
  • 56. CoreMotion: Use this! 32CoreMotionUse this! + Raw data Accelerometer + Gyroscope CoreMotion Framework 6 Degrees of Freedom Inertial System Dead Reckoning
  • 57. CoreMotion: Use this! 28CoreMotionUse this! +
  • 58. CoreMotion: Use this! 28 CoreMotion Use this! +// create core motion managermotionManager = [[CMMotionManager alloc] init];motionManager.motionUpdateInterval = 1.0/60.0;[motionManager startMotionUpdates];// frequently call the update method[self schedule:@selector(update:)];
  • 59. CoreMotion: Use this! 20CoreMotionUse this! +
  • 60. CoreMotion: Use this! 20 CoreMotion Use this! +// frequently read the gyro data-(void)update:(ccTime)dt { // absolute rotation rotationX = motionManager.deviceMotion.attitude.pitch; rotationY = motionManager.deviceMotion.attitude.yaw; rotationZ = motionManager.deviceMotion.attitude.roll; // absolute gravity gravityX = motionManager.deviceMotion.gravity.x; gravityY = motionManager.deviceMotion.gravity.y; gravityZ = motionManager.deviceMotion.gravity.z; // user acceleration accelerationX = motionManager.deviceMotion.userAcceleration.x; accelerationY = motionManager.deviceMotion.userAcceleration.y; accelerationZ = motionManager.deviceMotion.userAcceleration.z;}
  • 61. CoreMotion: Use this! 20 CoreMotion Use this! +// frequently read the gyro data-(void)update:(ccTime)dt { // absolute rotation rotationX = motionManager.deviceMotion.attitude.pitch; rotationY = rotationZ = CoreMotion Demo motionManager.deviceMotion.attitude.yaw; motionManager.deviceMotion.attitude.roll; // absolute gravity gravityX = motionManager.deviceMotion.gravity.x; gravityY = motionManager.deviceMotion.gravity.y; gravityZ = motionManager.deviceMotion.gravity.z; // user acceleration accelerationX = motionManager.deviceMotion.userAcceleration.x; accelerationY = motionManager.deviceMotion.userAcceleration.y; accelerationZ = motionManager.deviceMotion.userAcceleration.z;}
  • 62. Roadmap 16RoadmapWhere We’re Going
  • 63. Summary: What we did not cover 10SummaryWhat we did not cover
  • 64. Summary: What we did not cover 10SummaryWhat we did not cover GPS Accuracy
  • 65. Summary: What we did not cover 10SummaryWhat we did not cover Shaking-Motion Events GPS Accuracy
  • 66. Summary: What we did not cover 10SummaryWhat we did not cover Recording Movies Shaking-Motion Events GPS Accuracy
  • 67. Summary: What we did not cover 10SummaryWhat we did not cover Sensor Availability Recording Movies Shaking-Motion Events GPS Accuracy
  • 68. Summary: What we did not cover 10SummaryWhat we did not cover Sensor Availability Recording Movies Shaking-Motion Events GPS Accuracy http://developer.apple.com/library/ios
  • 69. Summary: What we learned! 5SummaryWhat we learned!
  • 70. Summary: What we learned! 5SummaryWhat we learned! Capturing Images
  • 71. Summary: What we learned! 5 Summary What we learned!Recording & Playing Sound Capturing Images
  • 72. Summary: What we learned! 5 Summary What we learned! Geolocating DeviceRecording & Playing Sound Capturing Images
  • 73. Summary: What we learned! 5 Summary What we learned!Reading Device Position + 6 Degrees of Freedom Geolocating Device Recording & Playing Sound Capturing Images
  • 74. Summary: What we learned! 5 Summary What we learned! Finding Magnetic NorthReading Device Position + 6 Degrees of Freedom Geolocating Device Recording & Playing Sound Capturing Images
  • 75. Thank you: You learned a lot! 0Thank youYou learned a lot!
  • 76. Thank you: You learned a lot! 0 Download! https://github.com/southdesign/SuperBall Me!Read! Thomas Fankhauser tommylefunk@googlemail.com Thank you Hire! You learned a lot! southdesign.de Buy! Beatfreak PianoTabs QuestionPad

×