gpt4 book ai didi

iphone - ASIHTTPRequest 在模拟器上工作但不在 iphone 上工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:17:51 24 4
gpt4 key购买 nike

大家好,到目前为止,我已经用 ASIHTTPRequest 做了很多工作,并在我的 iOS 应用程序中多次使用它,但是在我的应用程序的一个区域中,我添加了另一个 asihttprequest 方法,它无法正常工作。

首先必须要说的是,我试图分散下载和解析数据的负载的原因。如果我在 subview 上执行此操作,则需要 2-3 秒才能完成第二个 xml工作表并取出所有相关值.. 如果我在这个主视图上这样做,人们看不到任何负载等,那么当返回到 subview 时,它应该看起来几乎是即时的。我不知道这有多正确,但我认为这样做可以让应用感觉更快速。

所以我将它的 asihttprequest 方法设置为与其他可以工作但不使用缓存的方法相同。

发生的事情是我从主视图中选择一个表格单元格加载第二个 View 并将一堆信息解析到表格 View 。用户然后选择一个值,该值被传递回主视图并显示。

然后我解析另一批 xml 数据,根据第二个 xml 工作表中的所有内容检查所选的 valueID。因此,当用户选择第二个单元格时,我将所有刚刚解析的数据传递给第二个 View ,使其看起来加载速度更快。

这是一个流程图,可以更好地解释我想做的事情 enter image description here

这是解析器代码在主视图中的样子,它在模拟器中工作但在 iphone 上不工作。

这是我从 subview 调用的协议(protocol),并将我需要的所有值传递给主视图 ASIHTTPRequest 并触发请求。

    - (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
manufactureSearchObjectString = [[arrayValues valueForKey:@"MANUFACTURER"] objectAtIndex:0];
manufactureIdString = [[arrayValues valueForKey:@"MANUID"] objectAtIndex:0]; //Restricts Models dataset
manufactureResultIndexPath = myIndexPath;
[self.tableView reloadData]; //reloads the tabels so you can see the value in the tableViewCell.
//need some sort of if statment here so that if the back button is pressed modelSearchObjectString is not changed..

if (oldManufactureSearchObjectString != manufactureSearchObjectString) {
modelResultIndexPath = NULL;
modelSearchObjectString = @"empty";
oldManufactureSearchObjectString = [[NSString alloc] initWithFormat:manufactureSearchObjectString];
}
//These two lines below are what execute ASIHTTPRequest and set up my parser etc
dataSetToParse = @"ICMod"; // This sets the if statment inside parserDidEndDocument
[self setRequestString:@"ICMod.xml"]; //Sets the urlstring for XML inside setRequestString

}

然后这会触发 ASIHTTPRequest 委托(delegate)方法。

- (IBAction)setRequestString:(NSString *)string
{
//Set database address
//NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8888/codeData/"]; // imac development
NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8888/codeData/"]; // iphone development

//PHP file name is being set from the parent view
[databaseURL appendString:string];

NSLog(@"%@", databaseURL);

//call ASIHTTP delegates (Used to connect to database)
NSURL *url = [NSURL URLWithString:databaseURL];

//This sets up all other request
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

[request setDelegate:self];
[request startAsynchronous];

}

当我在 iphone 上测试时通过带有断点的调试运行它时,这就是应用程序失败的地方..但在模拟器上它没有问题。

下一个方法在 iphone 上测试时永远不会被调用,但在模拟器上运行良好。

- (void)requestFinished:(ASIHTTPRequest *)request
{
responseString = [request responseString]; //Pass requested text from server over to NSString
capturedResponseData = [responseString dataUsingEncoding:NSUTF8StringEncoding];

[self startTheParsingProcess:capturedResponseData];
}

这是在 iphone 上测试时唯一被触发的其他委托(delegate),向我发送了一个连接已超时的警报。

- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(@"%@", error);
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"A connection failure occurred." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[errorAlert show];
}

我认为您不需要查看所有解析器委托(delegate),因为我认为它们不是问题所在,因为这是应用程序崩溃的地方...

这是打印到日志中的内容...

2011-11-29 14:38:08.348 code[1641:707] http://000.000.000.000:0000/codeData/second.xml
2011-11-29 14:38:18.470 code[1641:707] Error Domain=ASIHTTPRequestErrorDomain Code=2 "The request timed out" UserInfo=0x1e83a0 {NSLocalizedDescription=The request timed out}

如果您需要我的更多代码,请告诉我。但是我在这里有点不知所措,就像我说的那样,除了我从我从第二个 View 设置的协议(protocol)..也许我应该在重新加载表或其他东西之前设置值......我不确定但希望有人可以帮助我解决这个问题并发现我的问题看不到。

最佳答案

您可以在 iPhone 上使用 Safari 查看“http://127.0.0.1:8888/codeData/”吗?无论 iPhone 连接到什么网络,服务器都可能不可用。

如果您的 iMac 使用的是 DCHP,则地址可能在您最初设置值后发生了变化。

关于iphone - ASIHTTPRequest 在模拟器上工作但不在 iphone 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8304818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com