judaco / iPhone

0 stars 0 forks source link

iPhone - Class 16 #12

Open judaco opened 7 years ago

judaco commented 7 years ago
//
//  ViewController.m
//  Contacts
//
//  Created by hackeru on 11/06/2017.
//  Copyright © 2017 juda. All rights reserved.
//

#import "ViewController.h"
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#import <Contacts/Contacts.h>
#import <ContactsUI/ContactsUI.h>

@interface ViewController () <CNContactPickerDelegate>

@end

@implementation ViewController
{
    CNContactPickerViewController * contactPicker;
    UIButton * button;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 300, 30);
    button.center = self.view.center;
    [button setTitle:@"pick a contact" forState:UIControlStateNormal];
    [button addTarget:self action:NSSelectorFromString(@"btnShowContacts:") forControlEvents:UIControlEventTouchUpInside];
    contactPicker = [[CNContactPickerViewController alloc] init];
    contactPicker.delegate = self;
}
-(void)btnShowContacts:(UIButton*)sender{
    [self presentViewController:contactPicker animated:YES completion:nil];
}
-(void)contactPickerDidCancel:(CNContactPickerViewController *)picker{
    NSLog(@"user cancelled");
}
////-(void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact{
////    NSLog(@"%@", contact.familyName);
//}
//-(void)contactPicker:(CNContactPickerViewController *)picker didSelectContacts:(NSArray<CNContact *> *)contacts{
//    for(CNContact * contact in contacts){
//        NSLog(@"%@", contact.givenName);
//    }
//}
-(void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperty:(CNContactProperty *)contactProperty{
    NSLog(@"did select property %@ %@", contactProperty.key, contactProperty.value);
    if([contactProperty.value isKindOfClass:[CNPhoneNumber class]]){
        CNPhoneNumber * phoneNumber = (CNPhoneNumber*)contactProperty.value;
        NSLog(@"phone number %@", phoneNumber.stringValue);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
judaco commented 7 years ago
//
//  ViewController.m
//  Core Motion
//
//  Created by hackeru on 11/06/2017.
//  Copyright © 2017 juda. All rights reserved.
//

#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>

@interface ViewController ()

@end

@implementation ViewController
{
    CMMotionManager * motionManager;
    double max;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //Gyroscope
     motionManager = [[CMMotionManager alloc] init];
    if (motionManager.accelerometerAvailable) {
            [motionManager startAccelerometerUpdatesToQueue:[[NSOperation alloc] init] withHandler:^(CMAccelerometerData * _Nullable data, NSError * _Nullable error) {

                if (data.acceleration.z > max) {
                    max = data.acceleration.z;
                    NSLog(@"%f", data.acceleration.z);
                }
                NSLog(@"%f %f %f", data.acceleration.x, data.acceleration.y, data.acceleration.z);
            }];
    }
    if (motionManager.gyroAvailable) {

    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end