nsdata

How to convert video path to NSData

放肆的年华 提交于 2019-12-25 09:16:52
问题 I have used DKImagePicker for fetching multiple videos from gallery. Able to fetch video but not getting convert to NSData . And also receiving error from server. Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_0040.MOV” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/var/mobile/Media/DCIM/100APPLE/IMG_0040.MOV, NSUnderlyingError=0x172e5f6b0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} May be not converted to NSData

How do I convert an NSString value to NSData?

二次信任 提交于 2019-12-25 08:28:42
问题 How do I convert an NSString value to NSData ? 回答1: NSString* str = @"teststring"; NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding]; 回答2: NSString *str = @"helowrld"; // This converts the string to an NSData object NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding]; you can take reference from this link 回答3: Do: NSData *data = [yourString dataUsingEncoding:NSUTF8StringEncoding]; then feel free to proceed with NSJSONSerialization:JSONObjectWithData . Correction to the

Set data for each bit in NSData iOS

纵然是瞬间 提交于 2019-12-25 06:57:57
问题 I created NSData of length 2 bytes (16 bits) and I want to set first 12 bits as binary value of (int)120 and 13th bit as 0 or 1(bit), 14th bit as 0 or 1 (bit) and 15th bit as 0 or 1(bit). This is what I want to do: 0000 0111 1000 --> 12 bits as 120 (int) 1 <-- 13th bit 0 <-- 14th bit 1 <-- 15th bit 1 <-- 16th bit Expected output => 0000 0111 1000 1011 : final binary and convert it to NSData. How can I do that? Please give me some advice. Thanks all. 回答1: This is the exact code you might need:

Problem writing NSData in my device

拥有回忆 提交于 2019-12-25 06:53:08
问题 Can someone explain me why my code doesn't work? //get the documents directory: NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; //make a file name to write the data to using the //documents directory: NSString *fullFileName = [NSString stringWithFormat:@"%@/subscriptions", documentsDirectory]; [dataReply writeToFile:fullFileName atomically:NO]; NSData *getData=[[NSData alloc

Convert BLOB image from NSData to NSString so it can be displayed in HTML UIWebView

旧街凉风 提交于 2019-12-25 06:44:59
问题 So I successfully retrieved my BLOB image from the database and set it to NSData *content.. content = [[NSData alloc] initWithBytes:sqlite3_column_blob(query, 16) length:sqlite3_column_bytes(query, 16)]; What I am trying to do is to get this content into a NSString, because I would like to then pass this string to javascript and display the image. I am not exactly sure if this is even possible, but i have read on the link below that you can display images in css/html in base64. http://mark

Loading and Playing Audio with avaudioplayer, UITableView NSURL

我们两清 提交于 2019-12-25 05:20:16
问题 I have a table view of audio objects, each with a url property. I'm looking for the fastest way (for the user) to play each audio file on touch. I tried getting the data first from the url: -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSURL *audioURL = [NSURL URLWithString:(NSString *)[[[self.objects objectAtIndex:indexPath.row] objectForKey:@"audioFile"] url]]; NSData *audioData = [NSData dataWithContentsOfURL:audioURL]; NSError *error; self

How to convert NData populated with hex values to NSString

╄→尐↘猪︶ㄣ 提交于 2019-12-25 04:58:19
问题 I have a NSdata object that is populated with a bunch of information thats formated in hex.. I am trying to convert it into its proper string representation but am struggling to have any success. One thing I have tried is to simply put it into a NSString and then NSLog it with a special character identifier thingy.. forgot the word (%02x), However to do this I am encoding it to NSUTF16.. which i dont want to do.. I mearly want to see exactly whats the data I am getting looks like as a

Logging in a text file iPhone

柔情痞子 提交于 2019-12-25 04:19:56
问题 I have a score system and I would like to log all scores in a text file separated by line breaks. Here is my current save code: NSData *dataToWrite = [[NSString stringWithFormat:@"String to write ID:%i \n",random] dataUsingEncoding:NSUTF8StringEncoding]; NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *path = [docsDirectory stringByAppendingPathComponent:@"text.txt"]; // Write the file [dataToWrite

Converting a pdf image to NSData for Parse.com

╄→гoц情女王★ 提交于 2019-12-25 04:15:11
问题 I am using vector graphics in my application and want to store some on Parse.com. I need to first convert these to NSData before upload. Is it possible to convert a pdf file to NSData? UIImage *image = [UIImage imageNamed:@"coolImage.pdf"]; NSData *data = UIImageJPEGRepresentation(image); I know NSData allows for a jpg of png representation but what about pdfs? Any tips on this would be greatly appreciated! 回答1: //to convert pdf to NSData NSString *pdfPath = [documentsDirectory

iPhone: NSData and Byte conversation issue?

前提是你 提交于 2019-12-25 03:43:48
问题 I want to send iPhone image to server database. I wrote following code. I am getting data mismatch exception and not able to resolve it. Could anyone please help me out. Code on iPhone side: - (void) uploadUserInfo:(NSString*)userId profilePic:(UIImage*)profilePic { __block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL: [NSURL URLWithString:[NSString stringWithFormat:@"%@/%d/uploadUserInfo?cultureDetect=false", dataUrl, currentAppID]]]; [request setPostValue:userId forKey: