Курсы по мобильной разработке под ios. 4 лекция....
DESCRIPTION
TRANSCRIPT
Возможности телефона
Разработка под iOS
Лекция 4
Глеб Тарасов
Интернет
Reachabilityhttp://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
Есть ли интернет?
Reachability *r = [Reachability reachabilityForInternetConnection];
if (r.status != NotReachable){ NSLog(@"Есть интернет");}
WiFi или 3G
Reachability *r = [Reachability reachabilityForLocalWiFi];if (r.status != NotReachable){ NSLog(@"Есть wifi");}
Акселерометр,гироскоп
Ориентация
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsPortrait(orientation)) NSLog(@"portrait");else NSLog(@"landscape");
typedef enum { UIInterfaceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight} UIInterfaceOrientation;
- (void)viewDidLoad{ [super viewDidLoad]; [[UIAccelerometer sharedAccelerometer] setDelegate:self]; [[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.01];}
@interface MyViewController : UIViewController<UIAccelerometerDelegate>
#pragma mark - UIAccelerometerDelegate
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{ NSLog(@"%g %g %g", acceleration.x, acceleration.y, acceleration.z);}
Акселерометр
Когда телефон лежит на столе:x = 0y = 0z = -1
ускорение +1.0g вдоль этой оси
1.0 по оси
Фильтр нижних частот
http://developer.apple.com/library/ios/#samplecode/AccelerometerGraph/Introduction/Intro.html
http://ru.wikipedia.org/wiki/Фильтр_нижних_частот
Гироскоп
- (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); }
Геолокация
manager = [[CLLocationManager alloc] init];manager.delegate = self;manager.desiredAccuracy = kCLLocationAccuracyHundredMeters;[manager startUpdatingLocation];
@interface Locator : NSObject<CLLocationManagerDelegate>
- (void)locationManager:(CLLocationManager *)m) didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { CLLocationCoordinate2D coord = newLocation.coordinate; NSLog(@"%g %g", coord.latitude, coord.longitude);}
Координаты
Компас
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { NSLog(@"%g", newHeading.magneticHeading);}
locationManager = [[CLLocationManager alloc] init]; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager setDelegate:self]; [locationManager startUpdatingHeading];
Работа с микрофоном
http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html
SpeakHere
Воспроизведение аудио
AVAudioPlayer
NSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"mp3"];NSURL *url = [NSURL fileURLWithPath:path];AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];[player play];
- (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; } }}
- (void) viewDidAppear:(BOOL)animated{ [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder];}
Воспроизведение видео
NSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"mp4"];NSURL *url = [NSURL fileURLWithPath:path];
MPMoviePlayerViewController *c = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentModalViewController:c animated:YES];
MPMoviePlayerViewController
Фото и видео
Видео с камеры
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 *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissModalViewControllerAnimated:YES];}
Фото из альбомов
UIImagePickerController *c = [[UIImagePickerController alloc] init];c.delegate = self;c.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL]; }
Что писать?
Top 25 paid
19 игр
2 книги
1 мессенджер
3 утилиты
Top 25 free
17 игр
3 утилиты
3 развлекательныхпрограммы
1 мессенджер
1 соц. сеть
Education
Entertainment
Photo & Video
Navigation
Games
Варианты приложений
Задачи
Решение задач (вроде diofant.ru)
Задания ЕГЭ
ПониматикаДетские развивающие приложения
Найди спрятанные объекты
Соедини линии по числам и получи объект
Комиксы
Раскраска
Сервисы
ТВ-программа