views:

191

answers:

2

Hey there,

I've got an app that's been in the app store for a while and functions perfectly on OS 3.1 - 3.13. However, when tested on 4.0b2 I noticed that it crashes in the same place every time, but only on the device, never on the simulator. I'm using a 3GS to test.

On loadView I initialize an NSNumberFormatter object which is declared and retained in the interface so I have access to it everywhere. In my method I call it several times to convert string values into nsnumbers to be stored in a mutable dictionary.

Here's an example:

[myDictionary setObject:[myStyleFormatter numberFromString:@"1"] forKey:@"hours"];
[myDictionary setObject:[myStyleFormatter numberFromString:@"30"] forKey:@"minutes"];
[myDictionary setObject:[myStyleFormatter numberFromString:@"10"] forKey:@"seconds"];

For some reason it crashes as soon as it tries to set hours. The error is "attempt to insert nil value (key: hours)"

Have I been doing something wrong all along? Has the api changed for 4.0b2?

Thanks,

Howie

A: 

My app crashed on 4.0 OS and I was not sure about the bug.

I contacted iPhone-Lancers and they give me quick fix and identified that below was the cause of the same.

exec_bad_access in Operation.m here: [self performSelectorOnMainThread:@selector(notifyDelega te withObject:error waitUntilDone:NO];

I found them on http://iphone-lancers.com/upgrade-your-iphone-app-to-sdk-4-gm-seed-ios-4.html

iPhoneOS4
+1  A: 

I had the same problem. I tracked it down to a NSNumberFormatter statement that did not like spaces (or commas) every 3 digits in the numbers. Which is one of the reasons for having a number formatter.

NSNumber *number = [currencyFormatter numberFromString:mstring];

It is fairly standard code in many examples on the internet, so I suspect a lot will find the problem.

Anyway, I fixed it by getting rid of the spaces

NSArray *sArray = [mstring componentsSeparatedByString:@" "];
[mstring setString:@" "]; //space at beginning is OK, would prefer nil
for (NSString *sElement in sArray) {
    [mstring appendString:sElement];
}

Then the currencyFormatter line worked.

BUT, in another area of my code, that same currencyFormatter statement worked with no problem. I tried changing code in the area to cause the problem, but I could not.

So, very curious!!!