judaco / iPhone

0 stars 0 forks source link

iPhone - Class 15 #11

Open judaco opened 7 years ago

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

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AVKit/AVKit.h>

@interface ViewController ()

@end

@implementation ViewController
{
    AVPlayerViewController * moviePlayer;
    BOOL isPlaying;
    __weak IBOutlet UIButton *btnPlay;
}
- (IBAction)handlePlay:(id)sender {
    if (isPlaying) {
        [self removeVideo];
    }else{
        moviePlayer = [[AVPlayerViewController alloc] init];
        [btnPlay setTitle:@"Stop" forState:UIControlStateNormal];
        NSURL * url = [[NSBundle mainBundle] URLForResource:@"myVideo" withExtension:@"mov"];
        moviePlayer.view.frame = CGRectMake((self.view.frame.size.width - 300) / 2, 100, 300, 300);
        [self.view addSubview:moviePlayer.view];
        moviePlayer.player = [AVPlayer playerWithURL:url];
        [moviePlayer.player play];
        isPlaying = YES;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:NSSelectorFromString (@"videoHasFinishedPlaying:") name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    }
}
-(void)videoHasFinishedPlaying:(NSNotification*)notification{
    [self removeVideo];
}
-(void)removeVideo{
    if (moviePlayer != nil) {
        [moviePlayer.player pause];
        [moviePlayer.view removeFromSuperview];
        moviePlayer = nil;
        isPlaying = NO;
        [btnPlay setTitle:@"Play" forState:UIControlStateNormal];
        [[NSNotificationCenter defaultCenter] removeObserver:self];//like broadcast in Android - getting updated from my main system (windows, apple)
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    isPlaying = NO;
}

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

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

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray<NSURL*> * urls = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSSystemDomainMask];
    //NSCachesDirectory
    if (urls.count == 1) {
        NSLog(@"%@", urls[0]);
    }else{
        NSLog(@"error");
    }
    NSString * temp = NSTemporaryDirectory();
    NSLog(@"temp: %@", temp);

   NSString * someText = @"Juda sta qui";
   NSString * destination = [NSString stringWithFormat:@"%@MyFile1.txt", temp];
//    NSError * error;
//    [someText writeToFile:destination atomically:YES encoding:NSUTF8StringEncoding error:&error];
//    
//    NSString * someTextFromFile = [NSString stringWithContentsOfFile:destination encoding:NSUTF8StringEncoding error:&error];
//    NSLog(@"%@", someTextFromFile);

//    NSArray * names = [NSArray arrayWithObjects:@"juda", @"shalev", nil];
//    [names writeToFile:destination atomically:YES];

    NSArray<NSString*> * names = [NSArray arrayWithContentsOfFile:destination];
    if (names != nil) {
        NSLog(@"not nil");
    }else{
        NSLog(@"is nil");
    }
//    for (NSString * name in names) {
//       NSLog(@"%@", name);
 //  }
}

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

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

#import "ViewController.h"
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //Lesson for NSDate
    NSDate * date = [[NSCalendar currentCalendar] dateWithEra:1 year:2017 month:6 day:7 hour:20 minute:38 second:0 nanosecond:0];
    NSDate * now = [NSDate date];
    NSLog(@"%@", [now description]);

    NSDate * newDate = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitHour value:7 toDate:now options:NSCalendarMatchNextTime];
    NSLog(@"%@", [newDate description]);

    NSDateComponents * components = [[NSCalendar currentCalendar] componentsInTimeZone:[NSTimeZone localTimeZone] fromDate:now];
    NSLog(@"%lu", components.hour);

    NSDateComponents * compo = [[NSDateComponents alloc] init];
    compo.year = 2017;
    compo.month = 6;
    compo.day = 7;
    compo.hour = 20;
    compo.minute = 48;

    NSDate * dateFromCompo = [[NSCalendar currentCalendar] dateFromComponents:compo];
    NSLog(@"%@", [dateFromCompo description]);
}

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

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

#import "ViewController.h"
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    EKEventStore * eventStore = [[EKEventStore alloc] init];
    EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];//static method

    switch (status) {
            case EKAuthorizationStatusAuthorized:

            break;
            case EKAuthorizationStatusRestricted:
            NSLog(@"access restricted");
            break;
            case EKAuthorizationStatusDenied:
            NSLog(@"access denied");
            break;
            case EKAuthorizationStatusNotDetermined:
            [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError * _Nullable error) {
                if (granted) {
                    <#statements#>
                }
            }];
            break;

        default:
            break;
    }
}

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

@end
judaco commented 7 years ago

to complete