nsdata

convert NSData of an image into a string

為{幸葍}努か 提交于 2019-12-11 05:48:09
问题 I have an NSData object called image. It is a very small .png file. print(image) displays: <89504e47 0d0a1a0a 0000000d 49484452 0000000a 0000000a 08060000 008d32cf bd000000 01735247 4200aece 1ce90000 00097048 59730000 16250000 16250149 5224f000 00001c69 444f5400 00000200 00000000 00000500 00002800 00000500 00000500 00005ec1 07ed5500 00002a49 44415428 1562f88f 04181818 fea36398 34038c01 a2d11581 f8308060 11ab109b 691826e2 5284ac10 000000ff ff232a1e 6b000000 27494441 5463f80f 040c0c0c 3831481e

Convert NSData to signed integer

守給你的承諾、 提交于 2019-12-11 05:41:57
问题 I have seen some similiar questions but I can't get this right: I receive a 16 bit signed integer in an NSData object, e.g '0xFF3C'. How can I read out the correct number from this? EDIT: With James Webster's answer I get: Received hex value : <0800> Converted value: 803995656 Received hex value : <0a00> Converted value: 803995658 Received hex value : <1a00> Converted value: 803995674 Received hex value : <faff> Converted value: 804061178 Received hex value : <e4ff> Converted value: 804061156

Identify extension of a file without extension

守給你的承諾、 提交于 2019-12-11 04:59:06
问题 In my current application I am downloading few files from server, and storing them locally. Based on extension of file I am loading the file in appropriate view. Example: file extensions: mov, 3gp, m4a, etc., => display in media player. file extensions: rtf, pptx, numbers, etc., =>display in UIWebView. file extensions: gif, png, xbm, etc., =>display in UIImageView. Problem is: some of the downloaded files may not have any extension. One approach which I found is- in connectionDidFinishLoading

How to check the NSDATA type?

泪湿孤枕 提交于 2019-12-11 04:46:48
问题 I have the class which downloads images First I have NSMutable URLRequest than I establish NSURLConnection and than I want to check which data I received in this function - (void)connectionDidFinishLoading:(NSURLConnection *)connection If it is image than write to the folder when it is some text than skip to the next image. How do I check the type of received data? 回答1: In delegate method of NSURLConnection, you can get header of response, from which you can get content type. If content type

How create UIImage from bytes?

我是研究僧i 提交于 2019-12-11 04:06:14
问题 I need in UIImage created from my colors (for example, i need in image 1x1 pixel with black color). I've got array: unsigned char *color[] = {0, 0, 0, 1}; How can i create UIImage from this array ? I've try unsigned char *bytes[4] = {0,0,0,1}; NSData *data = [NSData dataWithBytes:bytes length:4]; UIImage *img = [UIImage imageWithData:data]; but this method has no result... 回答1: You'll want to create a bitmap context (using CGBitmapContextCreate()), and draw into that. This requires using

NSData with CCCrypt in multi-threaded environment

巧了我就是萌 提交于 2019-12-11 03:39:00
问题 I have a file that was encrypted using AES. I use the following NSData category: #import <CommonCrypto/CommonCryptor.h> @implementation NSData (AES) - (NSData *)AES256DecryptWithKey:(NSString *)key { // 'key' should be 32 bytes for AES256, will be null-padded otherwise char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused) bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding) // fetch key data [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];

How to convert a File Blob to NSData?

天大地大妈咪最大 提交于 2019-12-11 03:02:55
问题 I have a problem converting a File Blob comming from a Webservice to an NSData Object. The File Blob can be any type of file. I can request a file from a Webserver via RestKit and get the following response: [{ "FileBlob": [ 65, 108, 108, 111, 99, 46, 32, 83, /* more integer values omitted */ ], "FileID": 1234567890, "FileName": "name.txt" }] I convert the Response into a Dictionary via JSONKit NSDictionary *dict = [[response bodyAsString] objectFromJSONString]; which works fine. But i cannot

How can I stop AVAudioPlayer from repeating before it reaches the end of my data?

 ̄綄美尐妖づ 提交于 2019-12-11 02:25:05
问题 I'm playing looped sound with AVAudioPlayer by setting the numberOfLoops property to -1. And I want to control the loop rate programmatically, so I'm loading my audio data like this: NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Click" ofType:@"aif"]; NSMutableData *soundData = [NSMutableData dataWithContentsOfFile:soundFilePath]; And then changing its length before initializing the audio player: int loopDuration = .5; // seconds int desiredDataLength = loopDuration * 2 *

convert .zip file into NSData

て烟熏妆下的殇ゞ 提交于 2019-12-11 01:32:59
问题 Hey, Is it correct to initialize an NSData with a zip file? I want to convert a zip file into NSData and construct another file with the data (in simple language 'copy it'). I have the code as: NSURL *theFileUrl = [NSURL URLWithString: @"file://localhost/Users/xxx/Desktop/testZippedFile.zip"]; NSData *data = [NSData dataWithContentsOfURL: theFileUrl]; When I, NSLog(@"Data: %@", data) , i do get some output but when I try to initialize an NSString with this data, it doesn't work: NSString *str

Get the json which is in NSData

荒凉一梦 提交于 2019-12-11 00:35:30
问题 I'm new in Objective-c. I want to make an HTTPRequest to an API. This works, I get my response in an NSData object. This response is a json response. How can I parse my response to get a dictionary with key: value format? I used this code to get the data: data = [NSURLConnection sendSynchronousRequest: req returningResponse: nil error: nil]; Thanks 回答1: Use NSJSONSerialization (iOS5+) to convert JSON strings to Cocoa objects ( NSDictionary in your case) and vice-versa. PS : If you need to