Skip to content

Commit

Permalink
Updated isSlowDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
myell0w committed Oct 19, 2011
1 parent f75c78d commit 03d8ccf
Showing 1 changed file with 79 additions and 68 deletions.
147 changes: 79 additions & 68 deletions Categories/UIDevice/UIDeviceHelper.m
Expand Up @@ -33,67 +33,67 @@
@implementation UIDevice (Helper) @implementation UIDevice (Helper)


+ (NSString *)debugInfo { + (NSString *)debugInfo {
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSString *appShortVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; NSString *appShortVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
#ifndef APPSTORE #ifndef APPSTORE
// adds this special string for better bug mail filtering // adds this special string for better bug mail filtering
appVersion = [NSString stringWithFormat:@"%@ AdHoc", appVersion]; appVersion = [NSString stringWithFormat:@"%@ AdHoc", appVersion];
#endif #endif
NSString *iphoneOSVersion = [[UIDevice currentDevice] systemVersion]; NSString *iphoneOSVersion = [[UIDevice currentDevice] systemVersion];
NSString *deviceType = [[UIDevice currentDevice] platform]; NSString *deviceType = [[UIDevice currentDevice] platform];
if ([[UIDevice currentDevice] isJailbroken]) { if ([[UIDevice currentDevice] isJailbroken]) {
deviceType = [NSString stringWithFormat:@"%@ JB", deviceType]; deviceType = [NSString stringWithFormat:@"%@ JB", deviceType];
} }
NSString *deviceUUID = [[UIDevice currentDevice] uniqueIdentifier]; NSString *deviceUUID = [[UIDevice currentDevice] uniqueIdentifier];
NSString *deviceLang = [[NSLocale preferredLanguages] objectAtIndex:0]; NSString *deviceLang = [[NSLocale preferredLanguages] objectAtIndex:0];
return [NSString stringWithFormat:@"%@ %@ %@\niOS: %@\nDevice: %@\nUUID: %@\nLang: %@", appName, appVersion, (appShortVersion ? appShortVersion : @""), iphoneOSVersion, deviceType, deviceUUID, deviceLang]; return [NSString stringWithFormat:@"%@ %@ %@\niOS: %@\nDevice: %@\nUUID: %@\nLang: %@", appName, appVersion, (appShortVersion ? appShortVersion : @""), iphoneOSVersion, deviceType, deviceUUID, deviceLang];
} }


// http://blog.zachwaugh.com/post/309927273/programmatically-retrieving-ip-address-of-iphone // http://blog.zachwaugh.com/post/309927273/programmatically-retrieving-ip-address-of-iphone
+ (NSString *)ipAddress { + (NSString *)ipAddress {
NSString *address = @"error"; NSString *address = @"error";
struct ifaddrs *interfaces = NULL; struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL; struct ifaddrs *temp_addr = NULL;
int success = 0; int success = 0;


// retrieve the current interfaces - returns 0 on success // retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces); success = getifaddrs(&interfaces);
if (success == 0) if (success == 0)
{
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL)
{ {
if(temp_addr->ifa_addr->sa_family == AF_INET) // Loop through linked list of interfaces
{ temp_addr = interfaces;
// Check if interface is en0 which is the wifi connection on the iPhone while(temp_addr != NULL)
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
{ {
// Get NSString from C String if(temp_addr->ifa_addr->sa_family == AF_INET)
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]; {
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
{
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}

temp_addr = temp_addr->ifa_next;
} }
}

temp_addr = temp_addr->ifa_next;
} }
}

// Free memory
// Free memory freeifaddrs(interfaces);
freeifaddrs(interfaces);

return address;
return address;
} }


- (double)availableMemory { - (double)availableMemory {
vm_statistics_data_t vmStats; vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT; mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount); kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);

if(kernReturn != KERN_SUCCESS) { if(kernReturn != KERN_SUCCESS) {
return NSNotFound; return NSNotFound;
} }

return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0; return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
} }


Expand All @@ -107,39 +107,50 @@ - (double)availableMemory {


// http://stackoverflow.com/questions/1108859/detect-the-specific-iphone-ipod-touch-model // http://stackoverflow.com/questions/1108859/detect-the-specific-iphone-ipod-touch-model
- (NSString *)platform { - (NSString *)platform {
size_t size; size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0); sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size); char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0); sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding]; NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine); free(machine);
return platform; return platform;
} }


- (BOOL)isSlowDevice { - (BOOL)isSlowDevice {
// determine if we should load images while scrolling static BOOL isCrappyDevice = YES;
NSString *hardwareModel = [[UIDevice currentDevice] platform];

static dispatch_once_t onceToken;
// slow devices: 1st Gen iPod, iPhone, 3G iPhone dispatch_once(&onceToken, ^{
BOOL isSlowDevice = [hardwareModel isEqualToString:@"iPhone1,1"] || [hardwareModel isEqualToString:@"iPhone1,2"] || [hardwareModel isEqualToString:@"iPod1,1"]; NSString *iPodTouchModel = @"iPod touch";
return isSlowDevice; NSString *iPhoneModel = @"iPhone";
NSString *iPhone3GModel = @"iPhone 3G";
NSString *iPhone3GSModel = @"iPhone 3GS";
NSString *iPadModel = @"iPad";
NSString *model = [self model];

isCrappyDevice = ([model isEqualToString:iPodTouchModel] || [model isEqualToString:iPhoneModel] ||
[model isEqualToString:iPhone3GModel] || [model isEqualToString:iPhone3GSModel] ||
[model isEqualToString:iPadModel]);
});

return isCrappyDevice;
} }




- (BOOL)isJailbroken { - (BOOL)isJailbroken {
BOOL jailbroken = NO; BOOL jailbroken = NO;
NSString *cydiaPath = @"/Applications/Cydia.app"; NSString *cydiaPath = @"/Applications/Cydia.app";
NSString *aptPath = @"/private/var/lib/apt/"; NSString *aptPath = @"/private/var/lib/apt/";

if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath]) { if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath]) {
jailbroken = YES; jailbroken = YES;
} }

if ([[NSFileManager defaultManager] fileExistsAtPath:aptPath]) { if ([[NSFileManager defaultManager] fileExistsAtPath:aptPath]) {
jailbroken = YES; jailbroken = YES;
} }

return jailbroken; return jailbroken;
} }


@end @end

0 comments on commit 03d8ccf

Please sign in to comment.