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

时间:2011-11-29 01:42:00

标签: iphone ios protocols asihttprequest

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

首先必须要说的是我试图传播下载和解析数据的负载的原因..如果我在子视图上执行此操作需要2-3秒才能完成第二个xml表格并获取所有相关的值..如果我在这个主视图上执行它,人们没有看到任何负载等,然后当回到子视图时,它应该看起来几乎是即时的。我不知道这是多么正确,但我认为这是一件好事,可以让应用程序感觉更加快速。

所以我将asihttprequest方法设置为与其他减去缓存的方法相同。

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

然后我解析了另外许多xml数据,检查第二个xml工作表中所有内容的选定valueID。这样,当用户选择第二个单元格时,我将刚刚解析过的所有数据传递给第二个视图,使其看起来好像加载的速度更快。

这是一个流程图,它将解释我想要做的更好的事情 enter image description here

这就是解析器代码在主视图中的样子,它是在模拟器中工作但不在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之外没有区别我从第二个视图设置的协议..也许我应该在重新加载表格之前设置值...我不确定但是希望有人可以帮助我解决这个问题并发现问题我看不到。

3 个答案:

答案 0 :(得分:3)

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

如果您的iMac正在使用DCHP,则可能是因为您最初设置该值后地址已更改。

答案 1 :(得分:0)

您确定网址上的案例是否正确?模拟器在区分大小的情况下比实际设备更宽容。

答案 2 :(得分:0)

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

相关问题