nsdata

Downloading a large file in iOS app

筅森魡賤 提交于 2020-01-02 07:33:15
问题 I'm trying to clean up some existing code that downloads a large file from a server in chunks, checks the checksum on each 50 packets, then stitches them together. I'm having some trouble to see if it's the most efficient way as right now it crashes some time because of memory issues. If I don't have the checksum, it does not seem to crash, but I would prefer if I could check my files first. @property (nonatomic, retain) NSMutableData * ReceivedData; - (void)connectionDidFinishLoading:

How to convert Data of Int16 audio samples to array of float audio samples

烈酒焚心 提交于 2020-01-02 06:34:15
问题 I'm currently working with audio samples. I get them from AVAssetReader and have a CMSampleBuffer with something like this: guard let sampleBuffer = readerOutput.copyNextSampleBuffer() else { guard reader.status == .completed else { return nil } // Completed // samples is an array of Int16 let samples = sampleData.withUnsafeBytes { Array(UnsafeBufferPointer<Int16>( start: $0, count: sampleData.count / MemoryLayout<Int16>.size)) } // The only way I found to convert [Int16] -> [Float]... return

Append NSData to a file in Objective C

天大地大妈咪最大 提交于 2020-01-02 00:14:10
问题 I'm attempting to download a large file on the iPhone and save it to disk as it is downloaded. Ideally, in: -(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data { } I want to append 'data' to a file on disk. I've checked out the NSData documentation. There are functions to write to a file, but I can't see anything to append to an existing file. Does anyone know how I can append this data? Any help much appreciated! Nick. 回答1: You can use a combination of -writeData: and

How do i insert UIImage on UIWebView

时间秒杀一切 提交于 2020-01-01 15:35:17
问题 I'm trying to display an Animated-GIF image in a UIImageView. Because this way only the first frame is shown i wanted to try a different approach. UIWebView. How can i get an Animated-GIF that is in memory (NSData) to display on a UIWebView with all frames..? 回答1: Thanks Thomas for you response, i don't know if it works because i managed to do it myself now.. Been decoding the GIFs for more then a week now and still with no succes so i went from UIImageView to UIWebView and the following code

NSMutableUrlRequest eats plus signs

浪尽此生 提交于 2020-01-01 11:56:27
问题 I create NSMutableUrlRequest for sending data to server, add all necessary fields to it and then add the string for sending like this: [theRequest setHTTPBody:[postString dataUsingEncoding: NSUTF8StringEncoding]]; postString is a usual NSString. The problem is, when I receive this request at the server, all the plus (+) signs disappear from the http body. So if I had "abcde+fghj" on iPhone, I get "abcde fghj" on the server". Can this be some encoding problem from using dataUsingEncoding:

NSData from NSKeyedArchiver to NSString

随声附和 提交于 2020-01-01 05:03:27
问题 I'm trying to convert NSData generated from NSKeyedArchiver to an NSString so that I can pass it around and eventually convert it back to NSData. I have to pass this as a string (I'm using three20 URL passing). I've gone through various encodings, UTF8, ASCII, etc. and can't get anything to work. NSKeyedArchiver says that the NSData is formated as a property list: NSPropertyListBinaryFormat_v1_0. Does anyone have any idea how I can convert this NSData to a String and back again? Size of the

How to convert an Int into NSData in Swift?

跟風遠走 提交于 2020-01-01 01:16:07
问题 In Objective-C I use the following code to Convert an Int variable into NSData , a packet of bytes. int myScore = 0; NSData *packet = [NSData dataWithBytes:&myScore length:sizeof(myScore)]; Use the converted NSData variable into a method. [match sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error: &error]; I tried converting the Objective-C code into Swift: var myScore : Int = 0 func sendDataToAllPlayers(packet: Int!, withDataMode mode: GKMatchSendDataMode, error:

objective-c: how to assign string to NSMutableData?

夙愿已清 提交于 2019-12-31 02:55:07
问题 I am to send data to digital meter for which I want data in NSMutableData form. I am trying to assign it data but getting errors. NSMutableData *body = [[NSMutableData alloc] initWithData:[NSData @"1"]; I want to asign string e.g. "1", "start" etc to NSMutableData. 回答1: You can't convert directly from an NSString to NSMutableData , you have to encode the string as NSData first. (There are several ways to go from NSData to NSMutableData, but I think mutableCopy is the clearest.); Try this:

Removing unicode and backslash escapes from NSString converted from NSData

£可爱£侵袭症+ 提交于 2019-12-31 01:49:18
问题 I am converting the response data from a web request to an NSString in the following manner: NSData *data = self.responseData; if (!data) { return nil; } NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)[self.response textEncodingName])); NSString *responseString = [[NSString alloc] initWithData:data encoding:encoding]; However the resulting string looks like this: "birthday":"04\/01\/1990", "email":"some

NSData to Java String

China☆狼群 提交于 2019-12-30 13:25:09
问题 I've been writing a Web Application recently that interacts with iPhones. The iPhone iphone will actually send information to the server in the form of a plist. So it's not uncommon to see something like... <key>RandomData</key> <data>UW31vrxbUTl07PaDRDEln3EWTLojFFmsm7YuRAscirI=</data> Now I know this data is hashed/encrypted in some fashion. When I open up the plist with an editor (Property List Editor), it shows me a more "human readable" format. For example, the data above would be