Tag: nsurlconnection

带POST的NSURLConnection不起作用

我正在尝试使用POST请求URLparsing参数, 但mypage.php没有收到这个参数…这是我的代码: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://myurl/mypage.php"]]; NSString *params = [[NSString alloc]initWithFormat:@"name=%@&surname=%@&location=%@&email=%@&password=%@&gender=%@&tipo=%@", name, surname, location, email, password, gender, tipo]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]]; NSLog(params); NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (conn) { webData = [[NSMutableData data] retain]; } else { } 和mypage.php if($_POST['name'] != "" && $_POST['email'] != "") //Here the $_POST['name'] and […]

如何快速加载内容加载在后台的图像?

我想要在后台进行图片加载,并让内容首先加载。 我试过下面的代码,但没有工作。 哪里不对? 帮我。 先谢谢你。 – (void)viewDidLoad { [super viewDidLoad]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"site.com/json.php"]]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; } – (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSError *myError = nil; NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError]; self.recipes = [[NSMutableArray alloc] init]; for(NSDictionary *dic in res){ Recipe *recipe = [[Recipe alloc] init]; recipe.name = [dic objectForKey:@"title"]; […]

从iPhone应用程序使用POST发送数据到Web表单

我正尝试使用GET从我的iPhone应用程序发送数据(用户名和密码)到在线表单。 这是我的源代码,但问题是没有数据存储在我的数据库中。 NSString *post =[[NSString alloc] initWithFormat:@"email=%@&password=%@",enterUserName.text,enterPass.text]; NSURL *url=[NSURL URLWithString:@"http://planetimpressions.com/contacts/imagecomm_register.php"]; NSLog(post); NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:url]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; /* when we user https, we need to allow any HTTPS cerificates, […]

iOS Mediaplayer和URLredirect

我试图实现一个MPMedia播放器来播放互联网文件。 到目前为止,我已经设法打开与我主持的video链接的媒体播放器。 当我尝试加载不直接映射到文件的url,而是将其redirect到文件时,问题就开始了。 初始url如下所示:h * tp://www.example.com/ numbers / numbers / numbers 当我把它放在我的浏览器中时,它会自动改变为这样的:h * tp://www.example.com/ numbers .mp4?to = numbers 当我直接使用初始URL时,就像我在直接使用url时一样,播放器出现,并且在不播放video的情况下中断播放。 我已经尝试NSURLConnection获得redirecturl,但我还没有能够得到它的工作,不知何故方法 – 连接:willSendRequest:redirectResponse:不会被调用。 我认为这可能是因为它已经在iOS 5中被删除了,但我不知道任何替代品,而这种问题实际上是没有logging的。 这里是我的代码:(我已经跳过shortUrl初始化,它的工作原理)。 NSLog(@"%@",shortUrl); redirecionando=TRUE; NSURLConnection * conection = [[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:shortUrl] delegate:self]; [conection start]; while(self.redirecting); self.moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:finalurl]; moviePlayerController.view.frame = self.view.bounds; [self presentMoviePlayerViewControllerAnimated:moviePlayerController]; moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen; moviePlayerController.moviePlayer.shouldAutoplay = YES; [moviePlayerController.moviePlayer […]

在收到服务器请求的响应后的一定时间间隔后更改选项卡视图

在具有UITabBarController的应用程序中,我想实现以下scheme: 当用户在“X”标签上时 ,他/她做了一些事情,然后移动到另一个标签。 再次回到'X'标签( 说5分钟后 – >这个很重要,因为我将来可能会改变5分钟到10分钟 ),那么我想显示一些信息,比如你的'Session is expired'。 每当用户返回“X”标签,就需要服务器请求获取响应码。 取决于我想显示popup“会话已过期”。 我想下面的方式来实现: 在每个viewWillAppear:所有视图的方法被加载在'X'选项卡 viewController的UITabBarController我会做服务器请求和检查响应和执行相应的操作。 但是它会涉及到很多我想避免的服务器请求。 我无法用解决scheme来结束。 我怎样才能达到我的要求? 非常感谢你的帮助。

在准备好数据之前,如何防止执行cellForItemAtIndexPath?

我将图像从我的服务器返回到我的应用程序的Base64数据,但我不会问我的服务器的图像,直到我有用户的位置,我只会在用户login后应用程序(显示UICollectionView)。 我的问题是collectionView:cellForItemAtIndexPath:被调用之前,我有数据准备好的单元格。 在我的NSURLConnection从我的服务器接收到完整的响应并且拥有Base64编码的图像数据之前,我可以通过哪些方法来防止这种方法被调用? (这也可能是相关的,我使用UICollectionView作为NSURLConnectionDataDelegate和NSURLConnectionDelegate ,我有一个单独的类( RenderMetadata() )将获取图像。) 编辑:谢谢你所有的创新答案! 我已经想出了一个方法来实现我以后的事情。 我会解释,但我没有分享我的代码,所以我不认为这是一个好主意,甚至提出,因为这只会导致混乱。 基本上我已经添加了一个对象到我的视图控制器在我的故事板,它涉及到我正在使用从我的服务器获取Base64编码的图像string的类。

线程与asynchronous调用

我想知道产生一个线程或使用NSURLConnection类进行asynchronous调用之间的最佳。

下载大文件时应用程序崩溃 – NSFileHandle seekToEndOfFile

我有一个循环,获取一堆文件的URL(10个小的txt文件和700KB左右的大图像文件),并运行“getFile”为每个文件创build一个NSUrlConnection。 当应用程序在[file writeData:data]之前到达[file seekToEndOfFile]时,它将崩溃: *** Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle seekToEndOfFile]: No such process' *** First throw call stack: 奇怪的是,如果我通过代码(即慢慢允许每个连接去回来),然后所有文件下载罚款。 如果我只是让应用程序做它的事情崩溃。 这里是连接的代码: -(void)getFile { NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:fullURL]]; NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; [conn start]; } – (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSString *fileName = […]

NSURLConnection挂在第二个电话

我正在构build一个iPhone应用程序,用于汇总来自多个不同数据源的数据,并将它们一起显示在一个表中。 对于每个数据源,我创build了一个类( WeatherProvider , TwitterProvider ),用于处理连接到数据源,下载数据并将其存储在一个对象中。 我有另一个类ConnectionManager ,它实例化和调用两个提供程序类中的每一个,并将结果合并到一个单独的NSArray显示在表中。 当我运行程序调用WeatherProvider或只是TwitterProvider,它完美的作品。 我可以一次又一次地调用这些对象,使它们保持最新,而不会出现问题。 我也可以调用TwitterProvider,然后WeatherProvider没有问题。 但是,如果我调用WeatherProvider然后TwitterProvider,TwitterProvider就像我打电话一样挂起: [[NSURLConnection alloc] initWithRequest:request delegate:self]; 。 其他点: – 当我打电话给WeatherProvider和TwitterProvider,TwitterProvider仍然挂起之间似乎没有多久。 – 在WeatherProvider中,我使用NSXMLParser和NSAutoreleasePool来parsingWeatherProvider的输出。 – 当应用程序启动时,ConnectionManager创buildWeatherProvider和TwitterProvider的实例,并在用户请求数据刷新时重用这些实例。 – 我运行与活动监视器连接的应用程序,它validation应用程序基本上是挂起来的。 没有CPU使用率,或额外的内存分配或networking活动似乎正在发生。 在一对夫妇文件中有一堆代码,所以我试图在这里包括相关的位(据我所知!)。 我非常感谢您提供的任何帮助,即使这只是其他debugging方法。 WeatherProvider -(void)getCurrentWeather: (NSString*)lat lon:(NSString*)lon lastUpdate:(double)lastUpdate { double now = [[NSDate date] timeIntervalSince1970]; NSString *noaaApiUrl; // don't update if current forecast is < than 1 hour old […]

NSURLConnection无法http发布大文件

我们正在尝试在我们的应用程序中添加function,以允许它向我们的Web服务发送一个大约50kb的大文件,文件本身是一个HTML模板,但是下面的代码我们发现数据似乎被切断当networking服务保存时。 Web服务目前被devise为检查$ _POST ['html']variables并将其写入文件。 有没有更好的方式来做到这一点,有没有人有任何想法,为什么上传不完整? 谢谢Aaron NSString *myText; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"htm"]; if (filePath) { myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; } NSURL *URL = [NSURL URLWithString:@"http://mywebsiteurl.com/receiveData.php"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; request.HTTPMethod = @"POST"; NSString *params = [NSString stringWithFormat:@"html=%@", myText]; NSData *data = [params dataUsingEncoding:NSASCIIStringEncoding]; [request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"]; [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; […]