nsdata

How can add more space if NSData < fixed size in Cocoa

一个人想着一个人 提交于 2019-12-12 02:52:52
问题 I have a problem: I used below codes to get data from NSData , but I want to get data from [0;2048] bytes . If my data > 2048* strong text *, it can run fine but if my data < 2048 , it'll wrong. So that I want to add more some space at last if my data < 2048 to enough 2048 bytes . Can you help me? Thanks so much. NSData *data = [NSData dataWithBytes:[arrayText UTF8String] length:[arrayText lengthOfBytesUsingEncoding:NSUTF8StringEncoding]]; NSData *datawrite = [data subdataWithRange

Converting NSString to NSData without changing data

旧街凉风 提交于 2019-12-12 02:45:03
问题 I have an NSString that contains a series of hex values, for example: 6173736e 616d65a2 15165570 6f696e74 584e534f 626a6563 However, I need this exact same data to be in an NSData object. I have tried doing things such as: mydata = [mystring dataUsingEncoding:NSASCIIStringEncoding]; //have tried all kind of encoding options Regardless of what I do though, mydata never contains the same values the NSString had, which is what I need. Would greatly appreciate any help! Thank you. 回答1: You seem

Upload files (images, pdf) with parameters to the server

半腔热情 提交于 2019-12-12 01:48:22
问题 I would like to upload 1pdf file and array of images. I can upload 1pdf and 2jpg files, if jpg files more than two I get message: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (No value.) UserInfo=0x174268000 {NSDebugDescription=No value.} Why is this happening? Also I tested server with POSTMAN and it work well. NSURL *URL = [NSURL URLWithString:constFileUploadURL]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];

iPhone - dataWithContentsOfURL: does not work for some URLs

给你一囗甜甜゛ 提交于 2019-12-12 01:31:33
问题 I am using NSData to get content from a URL (RSS feed) and then parse it. While most of the URLs are loaded fine, some of them don't return any data. These URLs open on the web so I know they are valid, but they just don't return any NSData. One such URL - feed://jpl.nasa.gov/multimedia/rss/rovers.xml Here's how I am using it (the NSURL object is formed properly) NSURL *feedURL = [NSURL URLWithString:[myUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSData *data =

Nothing displayed after splitting a list of image URLs

a 夏天 提交于 2019-12-12 01:12:28
问题 I have six image URLs in a string named aux . I split it with component separated by newlines. I want to pick images one by one from aux and display each in an ImageView . My code is: aux = [_homeText.text stringByAppendingString:[NSString stringWithFormat:@" %@ ",item.shortDescription]]; [_homeText setText:aux]; NSString *list =aux; NSArray *listItems = [list componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]; [listItems count]; if ([listItems objectAtIndex:0]) {

Objective C and ARC: Object produced in one thread does not get released in the consuming thread

情到浓时终转凉″ 提交于 2019-12-12 00:35:54
问题 I have a small project that reads an HTTP stream from a remote server, demuxes it, extracts audio stream, decodes it into 16-bit PCM, and feeds into a corresponding AudioQueue. The decoder/demuxer/fetcher runs in a separate thread and it uses my home-grown blocking queue (see code below) to deliver the decoded frames to the AudioQueue callback. The queue uses NSMutableArray to store objects. Once this thing is in-flight, it leaks objects inserted into the queue. Memory profiler says that the

How can I deal with connection problem when I use NSData?

南楼画角 提交于 2019-12-11 23:48:34
问题 One init method of NSXMLParser is initWithData:(NSData *data). When I init the NSData like this, NSURL *url = [NSURL URLWithString:@"http://221.34.21.9"]; NSData *date = [[NSData alloc] initWithContentsOfURL:url]; if the IP address cannot be reached, my app will wait for that address's response forever. How can I solve this problem? Thanks! 回答1: You will have to get the data through a NSURLConnection , which will have a timeout value, as described in the URL Loading System Programming Guide.

iOS no communication between iPhone app and MySQL database via PHP

蹲街弑〆低调 提交于 2019-12-11 23:43:58
问题 I need help trying to figure out why my iPhone app is not communicating with my PHP. I have a text field where the user can enter a message and there is a button that is supposed to tell the app when the text has been entered and needs to be posted to my mySQL database. My PHP and iOS code are pasted below, but I also included some debugging statements here. I put a break at the line if([serverOutput...) and at that point I get the following: alertsuccess UIAlertView * 0x00000000 dataURL

How to get date and filesize from a picture?

巧了我就是萌 提交于 2019-12-11 20:11:00
问题 If pictures are loaded into an app from a album, how is it possible to get the filesize in MB and the date of that picture displayed on a app like on the screenshot below? I know you can retrieve the filesize via a NSLog using the following code, but how can I get this into a string and also the date of that picture? NSLog(@"size of image in KB: %i",[UIImagePNGRepresentation(UIImage) length]); 回答1: Use CoreGraphics size_t imageSize = CGImageGetBytesPerRow(image.CGImage) * CGImageGetHeight

Objective C - writeToFile successful but removeFile returns error for same file

一个人想着一个人 提交于 2019-12-11 19:27:15
问题 I am saving photos a user takes with UIImagePickerController to the user's documents directory. When the app successfully uploads the image to the server, I would like to delete the locally saved image. I save the image to documents directory like this: /*Save image to documents directory, as opposed to core data for better memory management*/ NSString *myUniqueName = [NSString stringWithFormat:@"%lu.png", (unsigned long)([[NSDate date] timeIntervalSince1970]*10.0)]; NSArray *paths =