Permalink
Browse files

Updated isSlowDevice

  • Loading branch information...
1 parent f75c78d commit 03d8ccfa8b502fccf91aaa09d171f0b343cc4059 @myell0w myell0w committed Oct 19, 2011
Showing with 79 additions and 68 deletions.
  1. +79 −68 Categories/UIDevice/UIDeviceHelper.m
@@ -33,67 +33,67 @@
@implementation UIDevice (Helper)
+ (NSString *)debugInfo {
- NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
- NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
- NSString *appShortVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
+ NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
+ NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
+ NSString *appShortVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
#ifndef APPSTORE
- // adds this special string for better bug mail filtering
- appVersion = [NSString stringWithFormat:@"%@ AdHoc", appVersion];
+ // adds this special string for better bug mail filtering
+ appVersion = [NSString stringWithFormat:@"%@ AdHoc", appVersion];
#endif
- NSString *iphoneOSVersion = [[UIDevice currentDevice] systemVersion];
- NSString *deviceType = [[UIDevice currentDevice] platform];
- if ([[UIDevice currentDevice] isJailbroken]) {
- deviceType = [NSString stringWithFormat:@"%@ JB", deviceType];
- }
- NSString *deviceUUID = [[UIDevice currentDevice] uniqueIdentifier];
- NSString *deviceLang = [[NSLocale preferredLanguages] objectAtIndex:0];
- return [NSString stringWithFormat:@"%@ %@ %@\niOS: %@\nDevice: %@\nUUID: %@\nLang: %@", appName, appVersion, (appShortVersion ? appShortVersion : @""), iphoneOSVersion, deviceType, deviceUUID, deviceLang];
+ NSString *iphoneOSVersion = [[UIDevice currentDevice] systemVersion];
+ NSString *deviceType = [[UIDevice currentDevice] platform];
+ if ([[UIDevice currentDevice] isJailbroken]) {
+ deviceType = [NSString stringWithFormat:@"%@ JB", deviceType];
+ }
+ NSString *deviceUUID = [[UIDevice currentDevice] uniqueIdentifier];
+ NSString *deviceLang = [[NSLocale preferredLanguages] objectAtIndex:0];
+ 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
+ (NSString *)ipAddress {
- NSString *address = @"error";
- struct ifaddrs *interfaces = NULL;
- struct ifaddrs *temp_addr = NULL;
- int success = 0;
-
- // retrieve the current interfaces - returns 0 on success
- success = getifaddrs(&interfaces);
- if (success == 0)
- {
- // Loop through linked list of interfaces
- temp_addr = interfaces;
- while(temp_addr != NULL)
+ NSString *address = @"error";
+ struct ifaddrs *interfaces = NULL;
+ struct ifaddrs *temp_addr = NULL;
+ int success = 0;
+
+ // retrieve the current interfaces - returns 0 on success
+ success = getifaddrs(&interfaces);
+ if (success == 0)
{
- if(temp_addr->ifa_addr->sa_family == AF_INET)
- {
- // Check if interface is en0 which is the wifi connection on the iPhone
- if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
+ // Loop through linked list of interfaces
+ temp_addr = interfaces;
+ while(temp_addr != NULL)
{
- // Get NSString from C String
- address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
+ if(temp_addr->ifa_addr->sa_family == AF_INET)
+ {
+ // 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
- freeifaddrs(interfaces);
-
- return address;
+
+ // Free memory
+ freeifaddrs(interfaces);
+
+ return address;
}
- (double)availableMemory {
vm_statistics_data_t vmStats;
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);
-
+
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
-
+
return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
}
@@ -107,39 +107,50 @@ - (double)availableMemory {
// http://stackoverflow.com/questions/1108859/detect-the-specific-iphone-ipod-touch-model
- (NSString *)platform {
- size_t size;
- sysctlbyname("hw.machine", NULL, &size, NULL, 0);
- char *machine = malloc(size);
- sysctlbyname("hw.machine", machine, &size, NULL, 0);
- NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
- free(machine);
- return platform;
+ size_t size;
+ sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+ char *machine = malloc(size);
+ sysctlbyname("hw.machine", machine, &size, NULL, 0);
+ NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
+ free(machine);
+ return platform;
}
- (BOOL)isSlowDevice {
- // determine if we should load images while scrolling
- NSString *hardwareModel = [[UIDevice currentDevice] platform];
-
- // slow devices: 1st Gen iPod, iPhone, 3G iPhone
- BOOL isSlowDevice = [hardwareModel isEqualToString:@"iPhone1,1"] || [hardwareModel isEqualToString:@"iPhone1,2"] || [hardwareModel isEqualToString:@"iPod1,1"];
- return isSlowDevice;
+ static BOOL isCrappyDevice = YES;
+
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ NSString *iPodTouchModel = @"iPod touch";
+ 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 jailbroken = NO;
- NSString *cydiaPath = @"/Applications/Cydia.app";
- NSString *aptPath = @"/private/var/lib/apt/";
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath]) {
- jailbroken = YES;
- }
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:aptPath]) {
- jailbroken = YES;
- }
-
- return jailbroken;
+ BOOL jailbroken = NO;
+ NSString *cydiaPath = @"/Applications/Cydia.app";
+ NSString *aptPath = @"/private/var/lib/apt/";
+
+ if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath]) {
+ jailbroken = YES;
+ }
+
+ if ([[NSFileManager defaultManager] fileExistsAtPath:aptPath]) {
+ jailbroken = YES;
+ }
+
+ return jailbroken;
}
@end

0 comments on commit 03d8ccf

Please sign in to comment.