nsdata

Decode MP3 File from NSData

僤鯓⒐⒋嵵緔 提交于 2019-12-04 23:00:01
问题 For my application, I need to decode an MP3 file which is stored in an NSData object. For security reasons, it is undesirable to write the NSData object to disk and re-open it using a System URL reference, even if its only locally stored for a few moments. I would like to take advantage Extended Audio File Services (or Audio File Services) to do this, but I'm having trouble getting a representation of the NSData, which exists only in memory, that can be read by these Audio File Services. Edit

Append NSData to a file in Objective C

江枫思渺然 提交于 2019-12-04 22:39:59
I'm attempting to download a large file on the iPhone and save it to disk as it is downloaded. Ideally, in: -(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data { } I want to append 'data' to a file on disk. I've checked out the NSData documentation. There are functions to write to a file, but I can't see anything to append to an existing file. Does anyone know how I can append this data? Any help much appreciated! Nick. You can use a combination of -writeData: and -seekToEndOfFile methods from NSFileHandle class for writing NSData to the end of a file. There's a Apple

iOS Caching images with AFImageCache doesn't seem to work

百般思念 提交于 2019-12-04 21:11:48
I'm trying to cache some images loaded from a URL by using AFImageCache, without success... I'm not sure If i'm doing anything wrong and would love your opinions if you've ever used this library. I'm getting an image from a NSURLRequest, and then caching it as follows UIImage *img; //This image is a png icon returned from the server NSData *imgData = UIImagePNGRepresentation(img); // Always checking length to make sure its more than 0, and it is [[AFImageCache sharedImageCache] cacheImageData: imgData forURL: myURL cacheName: @"IconCache"]; On the next run, i'll try to check if the image was

Open .msg and .eml files from iOS UIWebview

守給你的承諾、 提交于 2019-12-04 19:43:48
I am trying to display .msg and .eml files using iOS sdk 5.1 in a UIWebView. I have the files in a binary format (NSData). I am able to display doc, docx, ppt, pptx, xls, xlsx, pdf, png, bmp and jpg files in the UIWebView but not the .msg and .eml files. Are msg and eml files supported by UIWebView? If not, is there some other way to display such files? They open fine from the Mail app. I am getting the following error from webView:didFailLoadWithError: 2012-08-09 15:59:03.851 HelloWorld[5848:707] Error loading attachment Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted"

How to convert image to bitmap code for bluetooth print in iphone

风流意气都作罢 提交于 2019-12-04 19:26:07
I am interested to print image from iPhone programmatically using bluetooth printer device. In one of the sample code I have implemented code for Text print but in that sample I am not getting how to convert image into format, like unsigned char buffer3[796]={ 0x55 , 0x66 , 0x77 , 0x88 , 0x44 , 0x1B , 0x58 , 0x31 , 0x19, 0x20, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00

Error Domain=NSCocoaErrorDomain Code=512 \"The operation couldn’t be completed.The operation couldn’t be completed. Is a directory

笑着哭i 提交于 2019-12-04 19:17:50
I want use writeToFile to store a pic image to the documents, but find the error below, how to solve it ? Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" {NSFilePath=/Users/alexqdh/Library/Application Support/iPhone Simulator/6.0/Applications/xxx/Documents/girl.png, NSUnderlyingError=0x753e630 "The operation couldn’t be completed. Is a directory"} -(NSString*)getImagePath:(NSString *)name { NSArray *path =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docPath = [path objectAtIndex:0]; NSFileManager

NSData from hex String?

孤街醉人 提交于 2019-12-04 19:09:47
I know this question has been asked for ObjectiveC , but my Swift isn't strong enough yet to transliterate the char *bytes stuff. So given let string = "600DBEEF" How do I create an NSData which represents those 4 bytes: 60 0D BE EF ? With the arrival of Swift3 and the new Foundation Data type, I finally circled back to this: extension UnicodeScalar { var hexNibble:UInt8 { let value = self.value if 48 <= value && value <= 57 { return UInt8(value - 48) } else if 65 <= value && value <= 70 { return UInt8(value - 55) } else if 97 <= value && value <= 102 { return UInt8(value - 87) } fatalError("\

Elegant Algorithm for Parsing Data Stream Into Record

大兔子大兔子 提交于 2019-12-04 19:04:12
I am interfacing with a hardware device that streams data to my app over Wifi. The data is streaming in just fine. The data contains a character header (DATA:) that indicates a new record has begun. The issues is that the data I receive doesn't necessarily fall on the header boundary, so I have to capture the data until what I've captured contains the header. Then, everything that precedes the header goes into the previous record and everything that comes after it goes into a new record. I have this working, but wondered if anyone has done this before and has a good computer-sciencey way to

How do I extract the width and height of a PNG from looking at the header in objective c?

妖精的绣舞 提交于 2019-12-04 18:30:39
问题 I have a need to find the dimensions of images online without downloading them. To accomplish this I do this: + (CGSize) getImageDimensions:(NSString *)url { // Send a synchronous request NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url]]; NSString *rangeString = [url hasSuffix: @"png"] ? @"bytes=0-100" : @"bytes=0-1300"; [urlRequest setValue:rangeString forHTTPHeaderField:@"Range"]; NSURLResponse * response = nil; NSError * error = nil; NSData

Display PDF in UIWebView using loadData

半城伤御伤魂 提交于 2019-12-04 17:48:05
问题 I am trying to display a PDF I have stored locally in a UIWebView. This is how I currently attempt to do this: if (![[NSFileManager defaultManager] fileExistsAtPath:self.url]) { LOG_ERROR(@"Couldn't load local file. File at path: %@ doesn't exist", self.url); return; } nsurl=[NSURL fileURLWithPath:self.url]; NSData *data = [NSData dataWithContentsOfFile:self.url]; LOG_DEBUG(@"data length:%d",[data length]); [self.webView loadData:data MIMEType:@"application/pdf" textEncodingName:@"utf-8"