dimanche 30 novembre 2014

Jailbroken iPhone breaking some code

I have an iPhone 6 that I just recently jailbroke that I've been using for development. Recently, I've encountered some weird problems with development where the iPhone behaves differently in the simulator.


Here's the code that I'm running. It's part of a method to convert an HTML color code to a UIColor:



+ (UIColor*) colorWithHex:(NSString *)hex
{
NSLog(@"HEX: %@", hex);

if(hex.length == 3)
{
//FFF
NSString* char1 = [hex substringWithRange:NSMakeRange(0, 1)];
NSString* char2 = [hex substringWithRange:NSMakeRange(1, 1)];
NSString* char3 = [hex substringWithRange:NSMakeRange(2, 1)];

return [UIColor colorWithRed:[self hexValue:[NSString stringWithFormat:@"%@%@", char1, char1]] green:[self hexValue:[NSString stringWithFormat:@"%@%@", char2, char2]] blue:[self hexValue:[NSString stringWithFormat:@"%@%@", char3, char3]] alpha:1];
}
else if(hex.length == 4)
{
//#FFF
NSString* char1 = [hex substringWithRange:NSMakeRange(1, 1)];
NSString* char2 = [hex substringWithRange:NSMakeRange(2, 1)];
NSString* char3 = [hex substringWithRange:NSMakeRange(3, 1)];

return [UIColor colorWithRed:[self hexValue:[NSString stringWithFormat:@"%@%@", char1, char1]] green:[self hexValue:[NSString stringWithFormat:@"%@%@", char2, char2]] blue:[self hexValue:[NSString stringWithFormat:@"%@%@", char3, char3]] alpha:1];
}
else if(hex.length == 6)
{
//FFFFFF
return [UIColor colorWithRed:[self hexValue:[hex substringWithRange:NSMakeRange(0, 2)]] green:[self hexValue:[hex substringWithRange:NSMakeRange(2, 2)]] blue:[self hexValue:[hex substringWithRange:NSMakeRange(4, 2)]] alpha:1];
}
else if(hex.length == 7)
{
//#FFFFFF
return [UIColor colorWithRed:[self hexValue:[hex substringWithRange:NSMakeRange(1, 2)]] green:[self hexValue:[hex substringWithRange:NSMakeRange(3, 2)]] blue:[self hexValue:[hex substringWithRange:NSMakeRange(5, 2)]] alpha:1];
}

return nil;
}




There's a couple problems here:


1. NSLogs


The NSLog (first line) simply doesn't run on my jailbroken phone. Run that in the simulator and it's fine.


2. The return value


If I run this:



NSLog(@"%@", [UIColor colorWithHex:@"ffffff"]);


This is what I get:


Simulator:



UIDeviceRGBColorSpace 1 1 1 1



iPhone 6:



UIDeviceRGBColorSpace 0.0588235 1 1 1





I have discovered that this code runs properly on my iPhone if I use the 7 character hex as opposed to the 6 character, e.g. #ffffff instead of ffffff, but that should be irrelevant. Furthermore, the NSLog is still not firing, so that's a problem. I don't know what else could be broken.


The weirdest part is that I started developing this app on my jailbroken iPhone, but only today did it start doing this weird stuff.


Has anyone else encountered these problems and/or have any ideas on how to fix it (without resetting the phone back to vanilla iOS)?




Aucun commentaire:

Enregistrer un commentaire