简体   繁体   English

在iOS模拟器上可以使用,但在iOS设备上不能使用吗?

[英]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.

相关问题 iOS应用程序可在模拟器上运行,但不能在设备上运行 - IOS application works on the simulator but not on the device iOS应用程序在模拟器中以后台模式工作,但在设备中不工作吗? - iOS app works in background mode in simulator but not in device? iOS 10.3文本语音转换可在模拟器上运行,但不能在设备上运行 - iOS 10.3 text to speech works on simulator but not on device 应用程序在设备上崩溃但在模拟器 iOS 上工作 - App crash on device but works on simulator iOS 在iOS设备上找不到文件,但在Simulator中可以使用 - File not found on iOS device, but works in Simulator iOS应用可在模拟器上运行,但不能在真实设备上运行 - iOS app works on simulator but not on real device 适用于iOS模拟器,但不适用于iPhone - Works on iOS Simulator but not on iPhone AVAudioPlayer:MP3文件无法在设备上播放,但适用于模拟器(iOS 6) - AVAudioPlayer: MP3 file not playing on device, but works in Simulator (iOS 6) iOS Core Audio渲染回调只能在模拟器上使用,而不能在设备上使用 - iOS Core Audio render callback works on simulator, not on device iOS - 设备上的3.5“布局而不是4”布局 - 在模拟器上正常工作 - iOS - 3.5“ layout instead of 4” layout on device - works fine on simulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM