Разработка под iOS



          Лекция 4

Возможности телефона



                           Глеб Тарасов
Интернет
Reachability
http://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;
Акселерометр

@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);
}
1.0 по оси

ускорение +1.0g вдоль этой оси




Когда телефон лежит на столе:
            x=0
            y=0
           z = -1
Фильтр нижних
              частот
http://ru.wikipedia.org/wiki/Фильтр_нижних_частот


http://developer.apple.com/library/ios/#samplecode/
AccelerometerGraph/Introduction/Intro.html
Гироскоп
- (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);
}
Геолокация
Координаты
@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);
}
Компас
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager setDelegate:self];
[locationManager startUpdatingHeading];



- (void)locationManager:(CLLocationManager *)manager
       didUpdateHeading:(CLHeading *)newHeading
{
    NSLog(@"%g", newHeading.magneticHeading);
}
Работа с микрофоном
SpeakHere
http://developer.apple.com/library/ios/#samplecode/
SpeakHere/Introduction/Intro.html
Воспроизведение аудио
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) 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;
        }
    }
}
Воспроизведение видео
MPMoviePlayerViewController
NSString *path = [[NSBundle mainBundle] pathForResource:@"file"
                                                 ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];

MPMoviePlayerViewController *c
    = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[self presentModalViewController:c animated:YES];
Фото и видео
Видео с камеры
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                Top 25 free
19 игр 1 мессенджер   17 игр 1 мессенджер
2 книги   3 утилиты       3 развлекательных
                              программы
                      1 соц. сеть   3 утилиты
Education
Entertainment
Photo & Video
Navigation
Games
Варианты приложений
Задачи


Решение задач (вроде diofant.ru)



         Задания ЕГЭ
Пониматика
     Детские развивающие приложения


       Найди спрятанные объекты

Соедини линии по числам и получи объект

               Комиксы

               Раскраска
Сервисы



ТВ-программа

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