[英]Works on iOS Simulator but not on iOS device?
EDIT: It works but it takes amazingly long to complete. 编辑:它可以工作,但是要花很长时间才能完成。 Is this normal, or is there a way to optimize it? 这是正常现象,还是有优化方法?
Thanks 谢谢
I am using DDUnitConverter in my project to convert currencies. 我在项目中使用DDUnitConverter转换货币。
Everything works perfectly fine on the iOS Simulator but hangs when I try to convert the currencies on my iOS Device (iPhone 4 iOSv5.1). 一切在iOS模拟器上都可以正常运行,但是当我尝试在iOS设备(iPhone 4 iOSv5.1)上转换货币时挂起。 I looked around to find a fix to this issue but could not find anything. 我四处寻找解决此问题的方法,但找不到任何东西。 Here is the code that I use to exchange the currencies. 这是我用来兑换货币的代码。 The code within the DDUnitConverter is available here: https://github.com/davedelong/DDUnitConverter/downloads DDUnitConverter中的代码可在此处获取: https : //github.com/davedelong/DDUnitConverter/downloads
if ([Number.text isEqualToString:@""] || [picklable.text isEqualToString:@"no selection"] || [picklable2.text isEqualToString:@"no selection"]) {
return;
}
if ([Number.text isEqualToString:@"0"]) {
Result.text = @"0";
return;
}
int fromType;
int toType;
fromType = [list indexOfObject:picklable.text];
toType = [list indexOfObject:picklable2.text];
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * from = [[f numberFromString:Number.text] retain];
[f release];
NSNumber *to = [[[DDUnitConverter currencyUnitConverter] convertNumber:from fromUnit:fromType toUnit:toType] retain];
float toto = [to floatValue];
Result.text = [NSString stringWithFormat:@"%.4f %@", toto, picklable2.text];
if ((toto == 0 || toto == [Number.text floatValue]) && picklable.text != picklable2.text ) {
Result.text = @"No Internet Connection or Previous Data";
}
[from release];
[to release];
[Result flashScrollIndicators];
Hopefully someone can help me out, Thanks 希望有人可以帮助我,谢谢
Anything taking amazingly long to do should be dispatched. 任何需要花费很长时间的事情都应该派遣出去。 Like this: 像这样:
dispatch_async(dispatch_get_global_queue(), ^(void) {
[self doReallyAmazinglyComplicatedProcessing];
});
Your code seems OK to me, but you are using DDUnitConverter. 您的代码对我来说似乎还可以,但是您正在使用DDUnitConverter。 I've never used it, but I suppose it needs internet connection to load data from the internet. 我从未使用过它,但我想它需要Internet连接才能从Internet加载数据。 If the server take long time to answer, your app could hang on connection. 如果服务器需要很长时间来回答,您的应用程序可能会挂起连接。
You can try to connect to the server asynchronously using dispatch_async
, this lets your app download data in background. 您可以尝试使用dispatch_async
异步连接到服务器,这使您的应用程序可以在后台下载数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.