iPhone App 发布到应用商店时的浮点计算. [英] iPhone App floating point calculations when released to the app store.
问题描述
我上周发布了我的第一个单独的 iPhone 应用程序,它可以计算12V 船用和船用电池使用情况.我在模拟器和我的 iPhone 上对其进行了大量测试,当我感觉一切正常时,我将应用程序存档并将其发布给 Apple.当用户开始使用该应用程序时,他们注意到计算未按预期进行.下面的代码是 NSManagedObject 模型上的一种方法,在调试时释放时会产生不同的输出.
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.
下面应该总结了相关 Discharge 项目的总数 - 但如果没有 BBDischarge 项目,那么它应该返回零.相反,当没有项目时(因此 for 循环不会触发),它返回一个数字,该数字是家庭的直接乘积(一个 NSNumber).如果我把domesticAH设置为100,下面的dischargeAH返回8,如果设置homealAH为1000,则返回83(浮点数显示时四舍五入).再次强调,在模拟器上运行或直接放在我的 iPhone 4s 上时,下面的工作正常,只有通过应用商店发布后才会出错.
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];
}
如您所见,self.domesticAH 在任何地方都没有出现在该方法中,而且由于我无法在模拟器中重新创建它,所以我很难追踪到它.
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.
几个问题:
- 我可以调试应用的实时版本吗?将 XCode 附加到我正在运行的 App Store 下载的应用实例?
- 有没有一种方法可以模拟从存档中安装 - 有没有人推荐临时分发来执行此操作?我还没有使用 ad hoc 呢.
- 还有其他想法为什么会出现这种情况?
推荐答案
与其说是回答,不如说是提示.但是,正如我在评论中已经说过的:您可以检查 Release 和 Debug 版本之间的不同行为.
Is more a hint than an answer.. but, as I already said in comments: you can check the different behavior between Release and Debug version.
过去曾见过这种不同的行为".由优化级别"设置给出.Debug 版本设置为 None [-O0],而 Release 版本设置为 Fastest, Smallest [-Os].
This different "behavior" has been seen in the past. Is given by "Optmization Level" setting. Debug version is set to None [-O0], while the Release version is set to Fastest, Smallest [-Os].
An example here .. here another ..
这篇关于iPhone App 发布到应用商店时的浮点计算.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!