Tag: nsurlconnection

将UIImage编码为Base64string时,传输到服务器时不起作用

将UIImage编码为Base64string可在设备上工作,但将string传输到服务器会以某种方式破坏string,并阻止服务器成功解码图像。 关于这个问题的任何build议? // Define params params["thumbnail_base64"] = imageToBase64(blockSet.thumbnailURL) … // Convert params -> query string let postString = buildQueryString(params) // Define upload URL let uploadURL = NSURL(string: RootURL + UploadFilePath)! // Hit server let request = NSMutableURLRequest(URL: uploadURL) request.HTTPMethod = "POST" request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding) … private func buildQueryString(parameters: [String:String], omitQuestionMark: Bool = false) -> String […]

后续的NSURLConnections不会触发委托方法

我已经找遍了这个问题的答案,并已经看到了很多类似的问题,但解决scheme似乎没有涉及到我的情况。 我很新的iOS开发,所以任何帮助,将不胜感激。 目前的应用程序正在寻找基于他们的网站生成的XML饲料显示在城市发生的事件。 我将事件存储在plist中,并在应用程序加载时明确检查新事件。 目前的stream程如下: 应用程序启动并使NSURLConnection检查服务器的时间戳并下载。 检查新下载的时间戳与本地时间戳,看看是否更大。 如果是,它会重写包含plist的文件,并触发一个需要新事件的通知。 这是第二个NSURLConnection似乎没有触发的地方。 callback方法本身触发,但它似乎不像委托方法之后触发。 奇怪的是,如果我同时调用两个连接而不是另一个连接,他们都会触发并调用委托方法。 下面是一些类的代码,为了清楚起见删除了一些内容: 申请代表: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Set up analytics account // Set the tab bar controller as the window's root view controller and display. self.window.rootViewController = self.tabBarController; [self.window makeKeyAndVisible]; //Set up listeners for event handling [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(timeStampResponse:) name:@"TimeStampResponse" object:nil]; […]

NSURLConnection – 在使用另一个类作为委托时以及存在身份validation质询时抓取响应数据

我正在使用我的内部API从我的服务器检索数据。 我正在使用基本身份validation来实现这一点。 由于API的性质,我没有在我的服务器代码上实现任何会话或其他任何内容,所以我发送了所有请求的用户名和密码。 正因为如此,我不想为我使用的每个viewcontroller实现NSURLConnection委托。 所以,我创build了一个辅助类,它扩展NSObject,并将其设置为NSURLConnectionDelegate。 @interface HandlerClass : NSObject <NSURLConnectionDelegate> 我实现了我所需要的每一种方法,而且我把它称为: NSURL *URL = [NSURL URLWithString:@"https://url/ifuser/"]; NSLog(@"Connection "); NSURLRequest *request = [NSURLRequest requestWithURL:URL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]; NSHTTPURLResponse *response; HandlerClass *cc = [[HandlerClass alloc] init]; cc.username = self.username.text; cc.password = self.password.text; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:cc]; 但无论我尝试,我不能达到该代表的数据响应数据。 我从字面上试图阅读互联网上的每一篇文章,包括stackoverflow和其他网站。 每个解决scheme都不需要authentication。 但我只需要authentication的解决scheme。 谢谢。 ~~~~~~~~~~~~~~~~~~~~~~~~~ 编辑:我知道我做了几个冗余的错误。 但我可以弄清楚什么是错的。 我只需要使用NSRunLoop来实现我的目标。 […]

将UIProgressView添加到NSURLConnection?

是否有可能添加一个UIProgressView到NSURLConnection? 是这样简单的获取数据的长度,然后将其设置为一个int然后将该int发送到我的其他类到我的UIProgressView? 有人可以告诉我如何做到这一点? 有没有任何例子或链接将我指向正确的方向? 谢谢!!!

从URL加载图像的UITableViewCell(需要加载它们asynchronous)

我有一个自定义的类,通过XMLparsing并获取图像的URLstring(我存储在一个数组中)。 然后我想要检索这些string来加载图像,并显示每个UITableViewCell。 这是我的代码: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; UILabel *labelText = (UILabel *)[cell viewWithTag:1000]; labelText.text = [[self.listOfPlaceDetails objectAtIndex:indexPath.row] objectForKey:@"name"]; NSURL *imageURL = [NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageCell"]]; NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; UIImage *image = [UIImage imageWithData:imageData]; cell.imageView.image = image; return cell; } 很显然,当我向下滚动桌面时,应用程序会加载更多的图像,当图像加载时,用户将无法做任何事情。 […]

ASIHTTPRequest和AFNetworking在2013年。可以select什么?

我正在开发一个基于networking的大型iOS项目。 而且我对现在应该select什么框架感兴趣。 我看到很多关于它的post: ASIHTTPRequest vs AFNetworking框架等,但都是旧的。 我也读过这个: http : //allseeing-i.com/%5Brequest_release%5D ; After giving it a lot of thought over the last few weeks, I've decided that I'm not going to continue working on ASIHTTPRequest in future. 它是在2011年写回。所以据我了解, ASIHTTPRequest是过时的? 我在iOS上没有太多的经验。 所以我感兴趣什么是现代的事情。 什么更好 – ASIHTTPRequest或AFNetworking ? 我对下一个标准感兴趣: JSON性能(与NSJSONSerialization集成) API丰富(上传文件,http查询) 简单 iOS 6和未来的iOS 7集成

为什么当通过蜂窝networking下载图像时,总会遇到NSURLConnection超时?

我的应用程序似乎在蜂窝networking上工作非常糟糕 – 用户界面通常具有旋转器而不是图像,但并不总是如此。 它使用并发NSOperations驱动的NSURLConnections。 它在WIFI上运行良好 – 完全没有问题。 我发现我得到很多NSURLConnection超时,但不知道为什么。 我怎样才能跟踪这个问题呢?

图片(或video)在Swift中发布到服务器

您好我正在使用NSURLSession在迅速发布json数据到服务器如下 var request = NSMutableURLRequest(URL: NSURL(string: "http://mypath.com")) var session = NSURLSession.sharedSession() request.HTTPMethod = "POST" var params2 :NSDictionary = ["email":"myemail@gmail.com"] var params :NSDictionary = ["function":"forgotPassword", "parameters":params2] var err: NSError? request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err) request.addValue("application/json", forHTTPHeaderField: "Content-Type") request.addValue("application/json", forHTTPHeaderField: "Accept") var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in var strData = […]

NSURLConnection didSendBodyData进度

我正在使用POST请求上传一些数据到服务器,我试图根据NSURLConnection的didSendBodyData方法的totalBytesWritten属性更新UIProgressView的进度。 使用下面的代码,我没有得到适当的进度视图更新,它始终为0.000,直到完成。 我不确定要乘以或除以获得更好的上传进度。 我会很感激提供的任何帮助! 码: – (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite { NSNumber *progress = [NSNumber numberWithFloat:(totalBytesWritten / totalBytesExpectedToWrite)]; NSLog(@"Proggy: %f",progress.floatValue); self.uploadProgressView.progress = progress.floatValue; }

MBProgressHud和SDWebImagePrefetcher

我试图显示一个自定义的MBProgressHUD同时使用NSURLConnection方法下载MBProgressHUD的URL列表。 SDWebImagePrefetcher有一个方法,当被调用时,在控制台中显示图像下载的进度。 现在,我想展示NSLog在自定义MBProgressHUD中的MBProgressHUD ,我希望HUD能够保持在屏幕上,直到完成这个过程,但是我不知道该怎么做,再加NSURLConnection我的NSURLConnection方法被调用时,它显示最初的HUD(连接),然后快速跳转到“完成”,即使图像仍然需要下载。 这是我的代码: – (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { HUD.mode = MBProgressHUDModeDeterminate; } – (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { HUD.labelText = @"Loading"; HUD.detailsLabelText = @"Downloading contents…"; //here, i would like to show the progress of the download, but it seems to jump this part HUD.dimBackground = YES; } – (void)connectionDidFinishLoading:(NSURLConnection *)connection { //arr […]