nsdata

Check if NSData contains ASCII or UTF8 Encoding

拥有回忆 提交于 2019-12-06 15:49:24
I am retrieving HTML, containing UTF8 or ASCII encoded text. For most common use it is ASCII decoding that works to display the text right: NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding]; Now I have another HTML page with UTF8 encoding, so I have to use: NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; What kind of encoding I retrieve is random when loading websites. My question is, is there a way to check the NSData for what kind of decoding is the right to use? So I know which

data from camera video returning zero

拟墨画扇 提交于 2019-12-06 15:29:00
this is my code for getting a video from UIImagePickerController : - (IBAction)takeVideo:(UIButton *)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; [self presentViewController:picker animated:YES completion:NULL]; } - (void)viewDidAppear:(BOOL)animated { self.movieController = [[MPMoviePlayerController alloc] init]; self.movieController.controlStyle =

Converting NSData back to Audio File

五迷三道 提交于 2019-12-06 14:10:37
i have converted my .caf audio file to NSData object using the following line of code: NSData *audioData = [NSData dataWithContentsOfFile:[MyRecorderFilePathURL path] options: 0 error:&err]; I am doing so to upload the binary object to a server through a web service. How do i convert audioData back to a .caf file which can be played using AVAudioPlayer ? AVAudioPlayer has a method for playing sound from NSData object . You can use - (id)initWithData:(NSData *)data error:(NSError **)outError method of AVAudioPlayer 来源: https://stackoverflow.com/questions/9157916/converting-nsdata-back-to-audio

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

☆樱花仙子☆ 提交于 2019-12-06 12:46:08
问题 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

How to gzip NSData with zlib?

只谈情不闲聊 提交于 2019-12-06 06:19:23
I want to use zlib because I'm assuming it's the best & fastest way to gzip NSData . But, is there a better way? If not, which version of the zlib library should I link to in Xcode: libz.dylib, libz.1.dylib, libz.1.1.3.dylib, or libz.1.2.5.dylib? Please provide a code example of how to us zlib to convert NSData *normalHTTPBody into NSData gzippedHTTPBody Yes, zlib is what is used to gzip data. I know of no better way. As for speed, you can select the compression level to optimize speed vs. compression for your application. You will likely find that libz.dylib and libz.1.dylib are symbolic

Getting NSData from UIImage object that contains CGImage

拜拜、爱过 提交于 2019-12-06 05:44:21
In order to upload an image file to my server, I need to get it's NSData. I am having trouble doing this right now, because my UIImage contains a CGImage. Let me show you how I am doing things. When a user takes a photo, this is what I do with the captured photo: NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; UIImage *image = [[UIImage alloc]initWithData:imageData]; _subLayer = [CALayer layer]; image = [self selfieCorrection:image]; image = [self rotate:image andOrientation:image.imageOrientation]; CGRect cropRectFinal = CGRectMake

Handling CFNull objects in NSPropertyListSerialization

左心房为你撑大大i 提交于 2019-12-06 05:07:43
问题 In my application, I am trying to serialize a server response dictionary and writing it to file system. But I am getting error "Property list invalid for format" for some responses. The reason is CFNull objects in the server response. Now, the server response will keep on changing so I do not have a definite way to remove CFNull objects (). Below is my code: NSString *anError = nil; NSData *aData = [NSPropertyListSerialization dataFromPropertyList:iFile format:NSPropertyListXMLFormat_v1_0

Swift generics and CMutableVoidPointer

扶醉桌前 提交于 2019-12-06 04:21:41
I have the following function at the moment in my generic class func writeHeader(buffer: CMutableVoidPointer) { var headerData = NSData(bytesNoCopy:buffer, length:sizeof(H)) self.fileHandle.writeData(headerData) } But as you see this is not very type safe. I tried this but it does not compile func writeHeader(buffer: CMutablePointer<H>) { var headerData = NSData(bytesNoCopy:buffer, length:sizeof(H)) self.fileHandle.writeData(headerData) } Any idea? UPDATE This is part of a generic class as mentioned in the first sentence, sorry next time im more specific. class DataStore<H> { ..... } This

The data couldn't be read because it isn't in the correct format.\"

寵の児 提交于 2019-12-06 03:51:05
] 2 I am using AFNetworking to send data to server.Below is my code: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager setRequestSerializer:[AFJSONRequestSerializer serializer]]; [manager setResponseSerializer:[AFJSONResponseSerializer serializer]]; [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; NSMutableDictionary *dict = [[NSMutableDictionary alloc]init]; [dict setValue:[[arrLoginDetails objectAtIndex:0] objectForKey:@"id"] forKey:@"user_id"]; [dict setValue:[[arrLoginDetails objectAtIndex:0] objectForKey:

NSData to NString conversion problem

时光总嘲笑我的痴心妄想 提交于 2019-12-06 03:32:39
问题 I'm getting an HTML file as NSData and need to extract some parts of it. For that I need to convert it to NSString with UTF8 encoding. The thing is that this conversion fails, probably because the NSData contains bytes that are invalid for UTF8. I have tried to get the byte array of the data and go over it, but each time I come across non ASCII character (hebrew letters for example) I get jibrish. Help will be appreciated. UPDATE: To Gordon - the NSData generated like that: NSData *theData =