ASIHTTPRequest 在模拟器上工作,但在 iPhone 上不工作

发布于 2024-12-18 14:44:04 字数 4129 浏览 0 评论 0原文

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

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

因此,我将其设置为 asihttprequest 方法,其设置与其他不使用缓存的方法相同。

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

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

这是一个流程图,将解释我想要做得更好的事情 在此处输入图像描述

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

这是我从子视图调用的协议,并将需要传递的所有值传递给主视图 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 委托方法。

- (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 上测试时唯一被解雇的其他代表,向我发送一条警报,表示连接已超时。

- (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];
}

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

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

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}

如果您需要更多我的代码让我知道..但我在这里有点茫然,就像我说的,除了我从我正在设置的协议初始化它之外,我对其他视图执行此 ASIHTTPRequest 的方式没有什么区别从第二个角度来看..也许我应该在我之前设置这些值重新加载表格或其他东西...我不确定,但希望有人可以帮助我解决这个问题并发现我看不到的问题。

Hey guys I have done lots of work with ASIHTTPRequest so far and use it several times in my ios application, however in one area of my app where I have added another asihttprequest method its not working properly.

First of all it must be said that the reason I'm trying to spread the load of downloading and parsing the data.. If I do this on the subview it takes a good 2-3 second to go through the second xml sheet and get all of the related values out.. where as If I do it on this mainview where people are not seeing anything load etc then when the go back to the subview it should look almost instant. I don't know how correct this is but I figure its a okay thing to do to make the app feel abit snappier.

So I am setting it the asihttprequest methods identically as the other ones that work minus caching.

What happens is I select a table cell from the main view that loads the second view and parses a bunch of info to the tableview. the User then selects a value which is passed back to the main view and displayed.

I then parse another lot of xml data checking the selected valueID against everything in the second xml sheet. so that when the user selects the second cell I pass all the data that was just parsed over to the second view to make it look as though its loaded alot faster.

Heres a flow chart of that will explain what I'm trying to do abit better
enter image description here

This is what the parser code looks like in the main view which is the one thats working in the emulator but not on the iphone.

This is my protocol that I call from the subview and pass all the values I need to over and fire off the request to the mainviews 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

    }

This then fires the ASIHTTPRequest delegate methods.

- (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];

}

When I run this through debug with break points while testing on the iphone this is where the app falls over.. but On the emulator it has no problems.

This next method never gets called when testing on the iphone but workds sweet on the emulator.

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

        [self startTheParsingProcess:capturedResponseData];
}

This is the only other delegate that is fired when testing on the iphone, sends me an alret saying the connection has timed out.

- (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];
}

I don't think you need to see all the parser delegates as I don't think they are the issue as this is where the app falls over...

here is what gets printed to the log...

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}

If you need more of my code let me know.. but I'm at abit of a loss here as like I say there is no difference to how Im doing this ASIHTTPRequest to other views other than I'm initializing it from the protocol that I'm setting up from the second view.. maybe I should set the values before I reload the table or something... I'm not sure though hopefully someone can help me out with this one and spot the issue I cannot see.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝眸 2024-12-25 14:44:04

您可以在 iPhone 上使用 Safari 查看“http://127.0.0.1:8888/codeData/”吗?很可能 iPhone 连接到的任何网络都无法使用该服务器。

如果您的 iMac 使用 DCHP,则自您最初设置该值以来,该地址可能已更改。

Can you view 'http://127.0.0.1:8888/codeData/' with Safari on the iPhone? Chances are that server isn't available from whatever networks the iPhone is connected to.

If your iMac is using DCHP it is possible that the address has changed since you originally set the value.

拍不死你 2024-12-25 14:44:04

您确定 URL 上的大小写正确吗?模拟器在区分大小写方面比实际设备更宽容。

Are you sure you have the case correct on the URL? The simulator is much more forgiving on case-sensitivity than the actual device.

墨落画卷 2024-12-25 14:44:04

不要盲目飞行,而是使用像 Charles 这样的 HTTP 代理来确保您的请求确实被触发并产生您想要的结果预计。

Do not fly blind but use an HTTP Proxy like Charles for making sure your requests are actually fired and result into what you expect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文