UIDevice+VLC.m 2.73 KB
Newer Older
1
/*****************************************************************************
Felix Paul Kühne's avatar
Felix Paul Kühne committed
2
 * UIDevice+VLC
3 4
 * VLC for iOS
 *****************************************************************************
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9 10 11
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
12

Felix Paul Kühne's avatar
Felix Paul Kühne committed
13
#import "UIDevice+VLC.h"
14 15
#import <sys/sysctl.h> // for sysctlbyname

Felix Paul Kühne's avatar
Felix Paul Kühne committed
16
@implementation UIDevice (VLC)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

- (int)speedCategory
{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);

    char *answer = malloc(size);
    sysctlbyname("hw.machine", answer, &size, NULL, 0);

    NSString *currentMachine = @(answer);
    free(answer);

    if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
        // iPhone 3GS, iPhone 4, first gen. iPad, 3rd and 4th generation iPod touch
        APLog(@"this is a cat one device");
        return 1;
    } else if ([currentMachine hasPrefix:@"iPhone4"] || [currentMachine hasPrefix:@"iPad3,1"] || [currentMachine hasPrefix:@"iPad3,2"] || [currentMachine hasPrefix:@"iPad3,3"] || [currentMachine hasPrefix:@"iPod4"] || [currentMachine hasPrefix:@"iPad2"] || [currentMachine hasPrefix:@"iPod5"]) {
        // iPhone 4S, iPad 2 and 3, iPod 4 and 5
        APLog(@"this is a cat two device");
        return 2;
37 38
    } else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
        // iPhone 5 + 5S, iPad 4, iPad Air, iPad mini 2G
39 40
        APLog(@"this is a cat three device");
        return 3;
41 42 43 44
    } else {
        // iPhone 6, 2014 iPads
        APLog(@"this is a cat four device");
        return 4;
45 46 47
    }
}

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
- (NSNumber *)freeDiskspace
{
    NSNumber *totalSpace;
    NSNumber *totalFreeSpace;
    NSError *error = nil;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];

    if (!error) {
        totalSpace = [dictionary objectForKey: NSFileSystemSize];
        totalFreeSpace = [dictionary objectForKey:NSFileSystemFreeSize];
        APLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", (([totalSpace unsignedLongLongValue]/1024ll)/1024ll), (([totalFreeSpace unsignedLongLongValue]/1024ll)/1024ll));
    } else
        APLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %i", [error domain], [error code]);

    return totalFreeSpace;
}

66
@end