Курсы по мобильной разработке под iOS. 4 лекция. Возможности телефона

1,571
-1

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,571
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Курсы по мобильной разработке под iOS. 4 лекция. Возможности телефона

  1. 1. Разработка под iOS Лекция 4Возможности телефона Глеб Тарасов
  2. 2. Интернет
  3. 3. Reachabilityhttp://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
  4. 4. Есть ли интернет?Reachability *r = [Reachability reachabilityForInternetConnection];if (r.status != NotReachable){ NSLog(@"Есть интернет");}
  5. 5. WiFi или 3GReachability *r = [Reachability reachabilityForLocalWiFi];if (r.status != NotReachable){ NSLog(@"Есть wifi");}
  6. 6. Акселерометр, гироскоп
  7. 7. ОриентацияUIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;if (UIInterfaceOrientationIsPortrait(orientation)) NSLog(@"portrait");else NSLog(@"landscape");typedef enum { UIInterfaceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight} UIInterfaceOrientation;
  8. 8. Акселерометр@interface MyViewController : UIViewController<UIAccelerometerDelegate>- (void)viewDidLoad{ [super viewDidLoad]; [[UIAccelerometer sharedAccelerometer] setDelegate:self]; [[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.01];}#pragma mark - UIAccelerometerDelegate- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{ NSLog(@"%g %g %g", acceleration.x, acceleration.y, acceleration.z);}
  9. 9. 1.0 по осиускорение +1.0g вдоль этой осиКогда телефон лежит на столе: x=0 y=0 z = -1
  10. 10. Фильтр нижних частотhttp://ru.wikipedia.org/wiki/Фильтр_нижних_частотhttp://developer.apple.com/library/ios/#samplecode/AccelerometerGraph/Introduction/Intro.html
  11. 11. Гироскоп
  12. 12. - (void)viewDidLoad{ [super viewDidLoad];) motionManager = [[CMMotionManager alloc] init]; timer = [NSTimer scheduledTimerWithTimeInterval:1/30.0 target:self selector:@selector(doGyroUpdate) userInfo:nil repeats:YES];}- (void)doGyroUpdate{ CMRotationRate rate = motionManager.gyroData.rotationRate;) NSLog(@"%g %g %g", rate.x, rate.y, rate.z);}
  13. 13. Геолокация
  14. 14. Координаты@interface Locator : NSObject<CLLocationManagerDelegate>manager = [[CLLocationManager alloc] init];manager.delegate = self;manager.desiredAccuracy = kCLLocationAccuracyHundredMeters;[manager startUpdatingLocation];- (void)locationManager:(CLLocationManager *)m) didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ CLLocationCoordinate2D coord = newLocation.coordinate; NSLog(@"%g %g", coord.latitude, coord.longitude);}
  15. 15. КомпасlocationManager = [[CLLocationManager alloc] init];locationManager.desiredAccuracy = kCLLocationAccuracyBest;[locationManager setDelegate:self];[locationManager startUpdatingHeading];- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{ NSLog(@"%g", newHeading.magneticHeading);}
  16. 16. Работа с микрофоном
  17. 17. SpeakHerehttp://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html
  18. 18. Воспроизведение аудио
  19. 19. AVAudioPlayerNSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"mp3"];NSURL *url = [NSURL fileURLWithPath:path];AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];[player play];
  20. 20. - (void) viewDidAppear:(BOOL)animated{ [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder];}- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent{ if (receivedEvent.type == UIEventTypeRemoteControl) { switch (receivedEvent.subtype) { case UIEventSubtypeRemoteControlTogglePlayPause: [self playPause]; break; case UIEventSubtypeRemoteControlPreviousTrack: [self rewind]; break; case UIEventSubtypeRemoteControlNextTrack: [self forward]; break; default: break; } }}
  21. 21. Воспроизведение видео
  22. 22. MPMoviePlayerViewControllerNSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"mp4"];NSURL *url = [NSURL fileURLWithPath:path];MPMoviePlayerViewController *c = [[MPMoviePlayerViewController alloc] initWithContentURL:url];[self presentModalViewController:c animated:YES];
  23. 23. Фото и видео
  24. 24. Видео с камерыUIImagePickerController *c = [[UIImagePickerController alloc] init];c.delegate = self;c.sourceType = UIImagePickerControllerSourceTypeCamera;c.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];[self presentModalViewController:c animated:YES];- (void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info{ UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; [picker dismissModalViewControllerAnimated:YES];}
  25. 25. Фото из альбомов UIImagePickerController *c = [[UIImagePickerController alloc] init]; c.delegate = self; c.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;- (void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info{ NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];}
  26. 26. Что писать?
  27. 27. Top 25 paid Top 25 free19 игр 1 мессенджер 17 игр 1 мессенджер2 книги 3 утилиты 3 развлекательных программы 1 соц. сеть 3 утилиты
  28. 28. Education
  29. 29. Entertainment
  30. 30. Photo & Video
  31. 31. Navigation
  32. 32. Games
  33. 33. Варианты приложений
  34. 34. ЗадачиРешение задач (вроде diofant.ru) Задания ЕГЭ
  35. 35. Пониматика Детские развивающие приложения Найди спрятанные объектыСоедини линии по числам и получи объект Комиксы Раскраска
  36. 36. СервисыТВ-программа

×