nsdata

Convert a UIImage into NSData BUT stay as a GIF file

假装没事ソ 提交于 2019-12-18 13:36:43
问题 I have a UIImage which is a GIF file. I need to make it make it into an NSData object. But it needs to stay a GIF so I can't use UIImageJPEGRepresentation. Any ideas? 回答1: I faced the same issue you mention and here is the code i used to save the animated gif to Photos without losing animation: ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; NSData *data = [NSData dataWithContentsOfURL:[self getCurrentGIFURL]]; [library writeImageDataToSavedPhotosAlbum:data metadata:nil

Convert unsigned char array to NSData and back

左心房为你撑大大i 提交于 2019-12-18 10:23:11
问题 How do you convert an unsigned char array to an NSData in objective c? This is what I am trying to do, but it doesn't work. Buffer is my unsigned char array. NSData *data = [NSData dataWithBytes:message length:length]; 回答1: You can just use this NSData class method + (id)dataWithBytes:(const void *)bytes length:(NSUInteger)length Something like NSUInteger size = // some size unsigned char array[size]; NSData* data = [NSData dataWithBytes:(const void *)array length:sizeof(unsigned char)*size];

NSJSONSerialization and Emoji

心已入冬 提交于 2019-12-18 06:58:30
问题 I'm currently trying to POST some JSON containing emojis to a python API. I tried feeding the NSJSONSerialization directly with the string containing the emojis from my UITextField but the serializer crashed with no meaningful explanation. Afterwards I tried to do some format conversion and ended up with something like this: NSString *uniText = mytextField.text; NSData *msgData = [uniText dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *goodMsg = [[NSString alloc] initWithData

NSData to String in Swift Issues

大城市里の小女人 提交于 2019-12-18 05:04:07
问题 I'm having issues converting my NSData to NSString in swift. I'm using what I think is the correct command and format: NSString(data: <DATA>, encoding: <ENCODING>) however whatever I do i keep ending up with a nil value. I am running the latest Xcode beta so I'm not sure if that is related but I'm hoping its a simple easy error that I've run into. I've attached playground code as well as a screen capture. Playground Code for Xcode 6.3 Beta 2 Build (6D532l) import Foundation //: # NSData to

NSData to String in Swift Issues

放肆的年华 提交于 2019-12-18 05:04:03
问题 I'm having issues converting my NSData to NSString in swift. I'm using what I think is the correct command and format: NSString(data: <DATA>, encoding: <ENCODING>) however whatever I do i keep ending up with a nil value. I am running the latest Xcode beta so I'm not sure if that is related but I'm hoping its a simple easy error that I've run into. I've attached playground code as well as a screen capture. Playground Code for Xcode 6.3 Beta 2 Build (6D532l) import Foundation //: # NSData to

Record audio to NSData

北慕城南 提交于 2019-12-18 03:44:25
问题 I have set up a TCP connection between two iPhones and I am able to send NSData packages between the two. I would like to talk into the microphone and get the recording as an NSData object and send this to the other iPhone. I have successfulyl used Audio Queue Services to record audio and play it but I have not managed to get the recording as NSData. I posted a question about converting the recording to NSData when using Audio Queue Services but it has not got me any further. Therefore I

How to play video from NSData

女生的网名这么多〃 提交于 2019-12-18 02:49:25
问题 I would like to know if it's possible to play a video from an NSData object... with the MPMoviePlayerController. 回答1: Ben's answer works perfectly on simulator but wont work on the device, You cannot write anywhere on the device. Check code below NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myMove.mp4"]; [videoData

Convert UIImage to NSData without using UIImagePngrepresentation or UIImageJpegRepresentation

给你一囗甜甜゛ 提交于 2019-12-17 21:52:46
问题 I Need to convert UIImage to NSData but without using UIImagePngRepresentation or UIImageJpegRepresentation , for images from photolib i can use assetlib method as mentioned here Using ALAssetsLibrary and ALAsset take out Image as NSData , but for captured image , assset url is not there hence in that case i need to convert UIImage directly to bytes with exif data , how can i accomplish this ? please help 回答1: H Bastan, Based on your comment: ...I want to save the captured image return by

Creating a base-64 string from NSData

亡梦爱人 提交于 2019-12-17 19:21:57
问题 How is it possible to get a base64 string from an NSData instance? 回答1: please try to search before posting questions I already post a answer for this here - Verifying a Receipt with the App Store - try this function there. 回答2: (if you targeting on IOS 7 ...) There is an easy way using provided API: https://stackoverflow.com/a/19088341/2481444 I also tested the accepted code. They both generate the same result. It also has decoding function. @S.J 回答3: NSString* base64String = [nsdata

Convert NSData to String?

心不动则不痛 提交于 2019-12-17 17:27:39
问题 I am storing a openssl private Key EVP_PKEY as nsdata. For this I am serializing into a byte stream using the code below unsigned char *buf, *p; int len; len = i2d_PrivateKey(pkey, NULL); buf = OPENSSL_malloc(len); p = buf; i2d_PrivateKey(pkey, &p); where pkey is of type EVP_PKEY. Then I am storing the bytes from buffer 'p' as an NSData using the line given below NSData *keydata = [NSData dataWithBytes:P length:len]; Now I am converting it to a NSString using the code given below but when i