- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
大家好,到目前为止,我已经用 ASIHTTPRequest 做了很多工作,并在我的 iOS 应用程序中多次使用它,但是在我的应用程序的一个区域中,我添加了另一个 asihttprequest 方法,它无法正常工作。
首先必须要说的是,我试图分散下载和解析数据的负载的原因。如果我在 subview 上执行此操作,则需要 2-3 秒才能完成第二个 xml工作表并取出所有相关值.. 如果我在这个主视图上这样做,人们看不到任何负载等,那么当返回到 subview 时,它应该看起来几乎是即时的。我不知道这有多正确,但我认为这样做可以让应用感觉更快速。
所以我将它的 asihttprequest 方法设置为与其他可以工作但不使用缓存的方法相同。
发生的事情是我从主视图中选择一个表格单元格加载第二个 View 并将一堆信息解析到表格 View 。用户然后选择一个值,该值被传递回主视图并显示。
然后我解析另一批 xml 数据,根据第二个 xml 工作表中的所有内容检查所选的 valueID。因此,当用户选择第二个单元格时,我将所有刚刚解析的数据传递给第二个 View ,使其看起来加载速度更快。
这是一个流程图,可以更好地解释我想做的事情
这是解析器代码在主视图中的样子,它在模拟器中工作但在 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/
我使用 iOS 4.2 和 Xcode 3.2.5 创建了一个通用二进制文件。我正在尝试对应用程序进行一些自动化测试,由于 iPad 和 iPhone 版本之间的界面略有不同,因此我有单独的 UIAu
这是一个概念性的问题。如果有人能澄清背后的故事,那就太好了。 我了解模拟器和模拟器之间的区别。 模拟器:模仿设备环境(硬件、网络功能等)。与设备相比,我们更有可能得到非常接近的结果。 模拟器:使用正在
是否有任何现成的解决方案可以模拟或模拟 LDAP 服务器功能? 或者是否可以在 ubuntu 上安装 ldap 服务器(仅适用于 localhost)? 如果它不是来自 localhost 的 jsu
我正在将我的应用程序修复为通用二进制文件。模拟器上的测试似乎默认使用 iPad。对于诸如检查方向和小型 UI 更新之类的小修正,我能找到的获取 iPhone 版本的唯一方法是插入我的 iPhone 并
Emulator: emulator: WARNING: Could not connect to proxy at ::1:8080: Unknown error ! - Android 将 And
我的应用程序在 ios 4.3 模拟器中运行良好,但在 ios 5 模拟器中运行不佳。我的 iPhone 上有 ios 5,我的应用程序确实可以在 iPhone 上运行。 该应用在所有这三种环境中都可
我在 azure 上制作了移动应用程序,并将其快速启动为 xamarian.forms,并且(在未能发布下载的表 api 应用程序并决定在浏览器中编辑它之后)下载了他们提供的客户端应用程序。然后,当我
Emulator: emulator: ERROR: x86 emulation currently requires hardware acceleration! Emulator: Process
我试图在 iOS 10.3 模拟器上将任意文件从我的应用程序的沙箱保存到 iCloud Drive。 iCloud Drive 已启用并且我已登录。如果我在模拟器上打开 iCloud Drive 应用
有谁知道一个小型、快速、支持 DOM 层的 javascript 模拟器?在 C/C++ 中? 问题:我需要在爬虫应用程序中对 javascript 的基本支持,并且想知道除了以下选项之外是否还有其他
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我是 Xcode 开发新手。我在基于 Lion 的 Mac 上安装了 Xcode 4.3.1,并取消设置 ~/Library 上的隐藏标志。 我在这里读到了有关 iPhone/iPad 模拟器的信息
我已在 VisualStudio 2015 AZURE SDK 2.9、C# 中创建辅助角色 我在每个方法的开头添加了断点: public override void Run() {
全部。我已经安装了 Azure SDK 1.7。解决方案中的所有程序集都是使用“任何 CPU”设置进行编译的。但是当我在我的计算机上的 Azure 模拟器中启动解决方案时,其中之一失败了。该错误非常奇
有没有独立的 WAP 模拟器来模拟诺基亚 6600 和索尼爱立信 MIDP 手机的 waop 网站? 我正在创建一个 WAP 门户,我不想每次都将所有文件上传到网络上,然后将其加载到 Opera Mi
我已经安装了 Tizen 的 Visual Studio Code 扩展,并且(看起来)进展顺利。 但是,当我启动 Tizen 模拟器管理器时,我没有安装任何平台,并且当我尝试安装平台时,没有可用的平
我目前正在我的 jquery mobile/phonegap 应用程序中处理表单。在此表单中,我有两个选择列表。它们在我的桌面浏览器(firefox、safari、chrome)中都能正常工作。 奇怪
我尝试制作一个分辨率为 480x480 像素的模拟器。但是模拟器永远不会完成启动。它卡在 Android Logo 页面上。分辨率有限制吗? 最佳答案 模拟器 is not smart about s
我不知道如何在虚拟设备上启用快照功能。该选项是灰色的,创建或编辑虚拟设备时没有设置。我使用的是最新版本的 SDK 工具修订版 22.6.3 这是我的窗口的样子:Create new Android V
我正在尝试使用具有特定屏幕分辨率的模拟器,但是当我将屏幕参数设置为我需要的参数时,键盘消失了。这样我就没有后退按钮,主页按钮..任何想法如何解决这个问题?这是我在 AVD 管理器中设置的:屏幕分辨率:
我是一名优秀的程序员,十分优秀!