nsdata

NSData & NSURL - url with space having problem

吃可爱长大的小学妹 提交于 2019-11-27 01:13:49
问题 I have following code in my application. NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]]; pathOfThumbNail has following path http://70.84.58.40/projects/igolf/TipThumb/GOLF 58B.jpg When I open above path in safari browser - path is changed automatically & image is successfully displayed. http://70.84.58.40/projects/igolf/TipThumb/GOLF%2058B.jpg But in iPhone, due to space in path, image isn't loaded in nsdata. 回答1: Use:

iOS: Select a GIF from the photo library, convert to NSData for use in multipart/form-data

大憨熊 提交于 2019-11-27 01:11:17
问题 What's currently working in my code: I select a JPG or PNG from the Photo Library (using standard ImagePicker methods), and convert that image to NSData using: self.myImageData = UIImageJPEGRepresentation(myImage, 0.9); which I then post to a server using multipart/form-data. I now want to do the same for a GIF, while retaining the original GIF data (so that an animated GIF going into the library, comes back out still animating). In didFinishPickingMediaWithInfo, I am able to get the URL of

Converting NSData to int

[亡魂溺海] 提交于 2019-11-27 01:07:09
问题 I've an NSData object, the length is 4 bytes .These four bytes i'm extracting from another NSData object using , fourByteData=[completeData subdataWithRange:NSMakeRange(0, 16)]; My first question is, will the above statement provide me the first four bytes of complete data. If Yes, then how to convert all these bytes to an equivalent int. 回答1: Is 268566528 the value you expect or perhaps you expect 528? If the correct value is 528 then the byte order is big-endian but the cpu is little-endian

Converting between NSData and base64 strings

 ̄綄美尐妖づ 提交于 2019-11-27 00:41:48
What is the easiest and fastest code to do a conversion between NSData and a base64 string? I've read a bunch of solutions at SO and mostly they involve in adding another class etc. I found a great solution here but it's too complex. Scroll down to the Conclusion section on the page you linked and download the provided NSData+Base64 files . Its the best solution I have seen so far and is incredibly easy to use. If you can learn anything about Cocoa, you can learn to use that project. Example NSString *originalString = [NSString stringWithFormat:@"test"]; NSData *data = [NSData

Iphone - How to encrypt NSData with public key and decrypt with private key?

末鹿安然 提交于 2019-11-26 23:51:22
I am converting a UIImage to NSData. Now I need to encrypt that NSData using a public key and I need to decrypt using a private key. Please provide a step by step procedure. Which algorithm do I need to use? Is there any good library for encryption and decryption? Also provide some code snippet for encryption and decryption. I have tried RSA Encryption and Decryption for NSString and you may well modify it and make it work for NSData Add Security.Framework to your project bundle. ViewController.h code is as follows: #import <UIKit/UIKit.h> #import <Security/Security.h> @interface

NSString containing hex convert to ascii equivalent

試著忘記壹切 提交于 2019-11-26 23:24:14
问题 I have an NSString that has hex information such as <00000020 66747970 4d344120 00000000 4d344120 6d703432 69736f6d 00000000 00031203 which came from NSData. What I need to do is convert that NSString of Hex data to Ascii which would be: [0][0][0] ftypM4A [0][0][0][0]M4A mp42isom[0][0][0][0][0][3][18][3] As you might be able to tell this is a M4A file. I loaded the first part of the file in to NSData using NSFileHandle. I then stored it into NSString: NSData *data = [filehandle

Convert AVAudioPCMBuffer to NSData and back

巧了我就是萌 提交于 2019-11-26 23:03:15
问题 How to convert AVAudioPCMBuffer to NSData ? If it should be done as let data = NSData(bytes: buffer.floatChannelData, length: bufferLength) then how to calculate bufferLength ? And how to convert NSData to AVAudioPCMBuffer ? 回答1: Buffer length is frameCapacity * bytesPerFrame. Here are functions that can do conversion between NSData and AVAudioPCMBuffer. func toNSData(PCMBuffer: AVAudioPCMBuffer) -> NSData { let channelCount = 1 // given PCMBuffer channel count is 1 var channels =

Determine MIME type from NSData?

冷暖自知 提交于 2019-11-26 22:48:06
问题 How would you determine the mime type for an NSData object? I plan to have the user to upload a video/picture from their iPhone and have that file be wrapped in a NSData class. I was wondering if I can tell the mime type from the NSData. There are only a few answers to this question and the most recent one is from 2010 (4 years ago!). Thanks! NSData *data; // can be an image or video NSString *mimeType = [data getMimetype]; // how would I implement getMimeType 回答1: Based on ml's answer from a

NSMutableData datawithBytesNoCopy:length:freeWhenDone: seems to make a copy of the buffer provided to it

不羁的心 提交于 2019-11-26 21:41:49
问题 According to Apple documentation, the class method +datawithBytesNoCopy:length:freeWhenDone: inherited from NSData Creates and returns a data object that holds a given number of bytes from a given buffer. But NSUInteger len = 1024; char *buffer = malloc(len); NSMutableData *data = [NSMutableData dataWithBytesNoCopy:buffer length:len freeWhenDone:YES]; char *dataBytes = data.mutableBytes; NSLog(@"%@", dataBytes == buffer ? @":D" : @":("); prints :( The method seems to actually make a copy,

Converting JSON to NSData, and NSData to JSON in Swift

有些话、适合烂在心里 提交于 2019-11-26 20:54:38
问题 I'm having problems converting a JSON element into NSData , and an NSData variable back into JSON in Swift. Firstly, I'd like to extract the encryptedData element of the following JSON data: { "transactionID" : 12345, "encryptedData" : [-67,51,-38,61,-72,102,48] } into an NSData encryptedData variable but can't seem to be able to do it. I'm using SwiftyJSON to parse the JSON as follows: let list: Array<JSON> = json["encryptedData"].arrayValue! But this gives me an array of ScalarNumber which