I released my first solo iPhone app last week that calculates 12V Marine and Boat Battery usage. I had tested it vigorously on the simulator and on my iPhone, and when I was comfortable all was well, I archived the app and released it to Apple. When users started using the app, they noted a calculation was not working as expected. The below code, which is a method on a NSManagedObject model, was producing a DIFFERENT output when released to when in debug.
The below should sum up the total of the related Discharge items - but if there are no BBDischarge items, then it should return zero. Instead, when there are no items (thus the for loop doesn't fire) it returns a figure that is the direct product of the domesticAH (an NSNumber). If I set the domesticAH to 100, the below dischargeAH returns 8, if set the domesticAH to 1000, it returns 83 (the float is rounded when it is displayed). Again, I stress the below works fine when running on the simulator, or put directly onto my iPhone 4s, only once released through the app store does it screw up.
//Other dynamics hidden for simplicity
@dynamic domesticAH;
@dynamic voltage;
@dynamic profileDischarge;
-(NSNumber*) dischargeAmpH
{
float totalWattsPD;
//Calculate the watts per day so we can accurately calculate the percentage of each item line
for(BBDischarge* currentDischarge in self.profileDischarge)
{
float totalWatt = [currentDischarge.wattage floatValue] ;
float totalMinsPD = [currentDischarge.minutesPD floatValue]/60;
float totaltimesUsed = [currentDischarge.timesUsed floatValue];
float numberInOperation = [currentDischarge.number floatValue];
totalWattsPD = totalWattsPD + ((totalWatt * totalMinsPD) * (totaltimesUsed * numberInOperation));
}
int voltage = ([self.voltage integerValue] + 1) * 12;
float totalAmpsPD = totalWattsPD / voltage;
return [NSNumber numberWithFloat:totalAmpsPD];
}
As you can see, self.domesticAH is not featured in the method anywhere, and as I can't recreate this in the simulator, I am having a hard time tracking this down.
A few questions:
- Can I debug the live version of my app? Attach XCode to my running, App Store downloaded instance of my app?
- Is there a way I can simulate an install from the archive - would anyone recommend ad hoc distribution to do this? I havent used ad hoc yet.
- Any other ideas why this might be behaving in this way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…