nsdata

Is it possible to upload a file to server without converting it into NSData?

喜夏-厌秋 提交于 2019-12-22 09:17:57
问题 I am developing an app in which I have to upload a file to server from device, i know how to send file to server using following NSMutableURLRequest , but is it possible to store file to server without converting to NSData ?? I have seen How upload image in to asp.net server without converting into NSData in iPhone this question but didn't find any solution. 回答1: Networks are analogue and computer and devices are digital they not understand what is what for them all the things are digital

NSData from UInt8

∥☆過路亽.° 提交于 2019-12-22 07:04:20
问题 I have recently found a source code in swift and I am trying to get it to objective-C. The one thing I was unable to understand is this: var theData:UInt8! theData = 3; NSData(bytes: [theData] as [UInt8], length: 1) Can anybody help me with the Obj-C equivalent? Just to give you some context, I need to send UInt8 to a CoreBluetooth peripheral (CBPeripheral) as UInt8. Float or integer won't work because the data type would be too big. 回答1: If you write the Swift code slightly simpler as var

NSData from hex String?

半城伤御伤魂 提交于 2019-12-22 01:16:47
问题 I know this question has been asked for ObjectiveC , but my Swift isn't strong enough yet to transliterate the char *bytes stuff. So given let string = "600DBEEF" How do I create an NSData which represents those 4 bytes: 60 0D BE EF ? 回答1: With the arrival of Swift3 and the new Foundation Data type, I finally circled back to this: extension UnicodeScalar { var hexNibble:UInt8 { let value = self.value if 48 <= value && value <= 57 { return UInt8(value - 48) } else if 65 <= value && value <= 70

Open .msg and .eml files from iOS UIWebview

☆樱花仙子☆ 提交于 2019-12-22 00:16:48
问题 I am trying to display .msg and .eml files using iOS sdk 5.1 in a UIWebView. I have the files in a binary format (NSData). I am able to display doc, docx, ppt, pptx, xls, xlsx, pdf, png, bmp and jpg files in the UIWebView but not the .msg and .eml files. Are msg and eml files supported by UIWebView? If not, is there some other way to display such files? They open fine from the Mail app. I am getting the following error from webView:didFailLoadWithError: 2012-08-09 15:59:03.851 HelloWorld[5848

Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed.The operation couldn’t be completed. Is a directory

一世执手 提交于 2019-12-21 23:32:07
问题 I want use writeToFile to store a pic image to the documents, but find the error below, how to solve it ? Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" {NSFilePath=/Users/alexqdh/Library/Application Support/iPhone Simulator/6.0/Applications/xxx/Documents/girl.png, NSUnderlyingError=0x753e630 "The operation couldn’t be completed. Is a directory"} -(NSString*)getImagePath:(NSString *)name { NSArray *path =NSSearchPathForDirectoriesInDomains

Finding file type of NSData recieved from server

只谈情不闲聊 提交于 2019-12-21 21:50:38
问题 I am receiving a text file from a socket over TCP/IP. There is no file extension (or filename for that matter) as the data is received as bytes. I can take the data from this (in the form of NSData) and load it into a UITextView and display it fine. I want to persist this data to a file. However, I don't know what format the data is in (txt, rtf, doc, docx)? I assume it as .txt and save it in the documents directory, but is there a programmatic way of finding out for sure? I've looked around

How do I convert HTML NSData to an NSString?

為{幸葍}努か 提交于 2019-12-21 18:34:34
问题 I'm using [NSData dataWithContentsOfURL:] to create two NSData instances and I want to compare these instances to gauge how different they are. Since they're both from the same website, using a string to find what is different will help me highlight the actual element(s) that has (have) changed. Is it possible to change this data to a string to find the difference? 回答1: Try initWithData:encoding: method of NSString to create string with your data. Exmp: NSString *str = [[NSString alloc]

The operation couldn’t be completed. Operation not permitted

送分小仙女□ 提交于 2019-12-21 12:35:45
问题 Very strange problem with my iPhone App. We have an App that has been approved and is in sales at the App Store. It contains a feature to download some database updates. The update comes in a ZIP via HTTP. The problem is that I cannot save this downloaded ZIP because I get the "The operation couldn’t be completed. Operation not permitted" error. BUT: this happens on 2 phones out of 10. If a phone cannot save the file it cannot do at all. If I redownload the app from the store it does not

Swift 3.0: Data to JSON [String : Any]

╄→гoц情女王★ 提交于 2019-12-21 07:13:12
问题 Evening, I'm trying to creating an APIClient, but I'm having a problem with a warning : APIClient.swift:53:81: Cast from 'Data' to unrelated type '[String : Any]' always fails In this code I'm trying to convert Data into JSON as a dictionary [String : Any] . I guess the compiler can't know if this cast could or could not be possible so it throws the error, but I'm pretty sure it will work. So how can I avoid this warning or how can I write safer code? case 200: do { let json = try

Merging NSData video files into one video file

柔情痞子 提交于 2019-12-21 05:35:44
问题 I have a bunch of video files that I want to merge into one video file, I am using NSMutableData to achieve the task NSMutableData *concatenatedData = [[NSMutableData alloc] init]; for (int i=0; i <[videoArray count]; i ++) { [concatenatedData appendData: [videoArray objectAtIndex:i]]; } [concatenatedData writeToFile:[[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"outputConct.mov"] atomically:YES]; UISaveVideoAtPathToSavedPhotosAlbum([[NSString alloc] initWithFormat:@"%@%@