nsdata

Check if NSData contains ASCII or UTF8 Encoding

别等时光非礼了梦想. 提交于 2019-12-23 04:16:10
问题 I am retrieving HTML, containing UTF8 or ASCII encoded text. For most common use it is ASCII decoding that works to display the text right: NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding]; Now I have another HTML page with UTF8 encoding, so I have to use: NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; What kind of encoding I retrieve is random when loading websites. My question is,

GCDAsyncSocket alters data while transporting it

限于喜欢 提交于 2019-12-23 04:01:54
问题 I'm making a multiplayer iOS game and have run into the following issue: i send a dictionary with an array of custom objects inside it. These custom objects conform to NSCoding . I convert the dictionary to NSData like this: NSData *data = [NSKeyedArchiver archivedDataWithRootObject:packet]; Then send it [asyncSocket writeData:data withTimeout:-1 tag:tag]; Receive [sock readDataWithTimeout:-1 tag:tag]; And try to unarchive NSDictionary *dict = [NSKeyedUnarchiver unarchiveObjectWithData:data];

Truncated Core Data NSData objects

北战南征 提交于 2019-12-23 02:39:27
问题 I am saving arrays of doubles in an NSData* object that is persisted as a binary property in a Core Data (SQLite) data model. I am doing this to store sampled data for graphing in an iPhone app. Sometimes when there are more than 300 doubles in the binary object not all the doubles are getting saved to disk. When I quit and relaunch my app there may be as few as 25 data points that have persisted or as many as 300. Using NSSQLitePragmasOption with synchronous = FULL and this may be making a

Base64 issue in NSMutableURLRequest POST message?

余生颓废 提交于 2019-12-22 20:01:10
问题 I'm having communcation issues between my app and the server. I'm using RNCryptor to encrypt a message, which I then base64 encode and transfer to the server in the request. This is done in both the DATA header, and within the http body as post data. I think I'm making a mistake in how I'm converting & transferring the base64 encoded message via POST. If I receive the encrypted message via the header, it decrypts perfectly fine, every single time. However, if I take the message via the POST

How to gzip NSData with zlib?

随声附和 提交于 2019-12-22 13:55:47
问题 I want to use zlib because I'm assuming it's the best & fastest way to gzip NSData . But, is there a better way? If not, which version of the zlib library should I link to in Xcode: libz.dylib, libz.1.dylib, libz.1.1.3.dylib, or libz.1.2.5.dylib? Please provide a code example of how to us zlib to convert NSData *normalHTTPBody into NSData gzippedHTTPBody 回答1: Yes, zlib is what is used to gzip data. I know of no better way. As for speed, you can select the compression level to optimize speed

Converting NSData back to Audio File

纵然是瞬间 提交于 2019-12-22 12:16:31
问题 i have converted my .caf audio file to NSData object using the following line of code: NSData *audioData = [NSData dataWithContentsOfFile:[MyRecorderFilePathURL path] options: 0 error:&err]; I am doing so to upload the binary object to a server through a web service. How do i convert audioData back to a .caf file which can be played using AVAudioPlayer ? 回答1: AVAudioPlayer has a method for playing sound from NSData object . You can use - (id)initWithData:(NSData *)data error:(NSError **

Progress bar while downloading

左心房为你撑大大i 提交于 2019-12-22 11:16:34
问题 I have an app with in-app downloading. I successfully download mp3 files in this way: NSData *data1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://.../somefile.mp3"]]; [data1 writeToFile:filePath atomically:YES]; But there is really big pause while this code is executing. How can I work out the progress of the download and display it with a progress bar? 回答1: The problem is that dataWithContentsOfURL: is a blocking call. This means that it will block the thread that it is

How to compress data in swift 3?

ぐ巨炮叔叔 提交于 2019-12-22 10:43:35
问题 I have some files in file manager in Swift 3. I want to upload them, but when I will convert them into base 64, their size will be huge! so I want to compress the data before converting it into base 64. Here is my code for converting: for i in 0...(rows?.count)! - 1 { let filePath = filesurl[fileManagerViewController.selectedFileIndex[i]] do { let fileData = try Data.init(contentsOf: filePath) let fileStream:String = fileData.base64EncodedString(options: NSData.Base64EncodingOptions.init

The data couldn't be read because it isn't in the correct format."

偶尔善良 提交于 2019-12-22 09:52:52
问题 ]2I am using AFNetworking to send data to server.Below is my code: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager setRequestSerializer:[AFJSONRequestSerializer serializer]]; [manager setResponseSerializer:[AFJSONResponseSerializer serializer]]; [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; NSMutableDictionary *dict = [[NSMutableDictionary alloc]init]; [dict setValue:[[arrLoginDetails objectAtIndex:0]

How do I make my AFNetworking “responseObject” that I receive a NSDictionary I can parse?

不羁的心 提交于 2019-12-22 09:28:24
问题 I have this call with AFNetworking 1.0 that returns a responseObject with the data from the API that I want: [[AFDiffbotClient sharedClient] postPath:@"http://diffbot.com/api/batch" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { However, I have no idea how to process responseObject . If I check [responseObject class] I get NSData . If I NSLog(@"%@", responseObject) I get a bunch of numbers (memory addresses I assume): <5b0a7b22 68656164 65727322