nsdata

Parsing JSON response .

痴心易碎 提交于 2019-11-28 14:48:51
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { response=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];} Here, I get the response in the "response value" --> [{"response":true,"danger":false}] The thing is: How can I rescue the "danger"(true/false) into a new variable to use it in other methods? I need to know if "danger" is true or false becouse if its true, i have to show an alert. I would really appreciate someone help, as I am stuck in here. use NSJSONSerialization: http://developer.apple.com/library/ios/#documentation/Foundation

Need to convert NSData to NSArray

佐手、 提交于 2019-11-28 14:14:57
I am pulling down a plist from a URL using an NSURLConnection, which returns an NSData object. I would like to convert this to an NSArray. Can anyone help me? I am refactoring a method that currently does a synchronous request to the URL, using arrayWithContentsOfURL: to get the NSArray. Thanks!! Use +[NSPropertyListSerialization dataWithPropertyList:format:options:error:] to convert the data, then check if the result -isKindOfClass:[NSArray class] . Use NSKeyedArchiver for archiving object to data. NSKeyedUnarchiver for unarchiving object from data: NSArray *object = [NSKeyedUnarchiver

NSImage to NSData as PNG Swift

谁都会走 提交于 2019-11-28 13:18:58
I am writing a Mac app based on an iOS app. The code below converts a UIImage to NSData to upload to Parse.com. I would like to do the same for Mac but I do not seem to be able to convert it to NSData. What should I be doing? Thanks var image = UIImage(named: "SmudgeInc") let imageData = UIImagePNGRepresentation(image) let imageFile = PFFile(name:"image.png", data:imageData) You can use the NSImage property TIFFRepresentation to convert your NSImage to NSData : let myImageData = yourImage.TIFFRepresentation! If you need to save your image data to a PNG file you can use NSBitmapImageRep(data:)

How can i get original nsdata of uiimage?

╄→гoц情女王★ 提交于 2019-11-28 13:01:10
In my app, user can select a pic from album or camera where i can get uiimage representation. Since the album may have pic from web, the file type is not only jpg. Then i need to sent it to the server without convertion. Here i can only use nsdata. I know UIImageJPEGRepresentation and UIImagePNGRepresentation, but i think this two method may convert the original image. Maybe when quality set to 1 UIImageJPEGRepresentation can get original pic? Is there any method to get the original uiimage nsdata? You can use the ALAssetsLibrary and ALAssetRepresentation to get the original data. Example: -

Converting GIF images to nsdata

孤街浪徒 提交于 2019-11-28 10:59:20
问题 I have an iPhone application that needs to save an image onto the database in BLOB format. The problem is that if the image is in .gif format then it cannot be converted to NSDATA format and hence i am not been able to save that onto the database in BLOB format. What should I do? Please help with some code.. Thanks in advance Joy 回答1: A gif image can be converted into NSData...Here's the code snippet: NSString *pathForGif = [[NSBundle mainBundle] pathForResource: @"gifFile" ofType: @"gif"];

Creating a base-64 string from NSData

主宰稳场 提交于 2019-11-28 10:10:26
How is it possible to get a base64 string from an NSData instance? Saurabh please try to search before posting questions I already post a answer for this here - Verifying a Receipt with the App Store - try this function there. Yang (if you targeting on IOS 7 ...) There is an easy way using provided API: https://stackoverflow.com/a/19088341/2481444 I also tested the accepted code. They both generate the same result. It also has decoding function. @S.J NSString* base64String = [nsdata base64Encoding]; 来源: https://stackoverflow.com/questions/6006823/creating-a-base-64-string-from-nsdata

iOS UIImageJPEGRepresentation error: Not a JPEG file: starts with 0xff 0xd9

做~自己de王妃 提交于 2019-11-28 10:00:21
I am writing a .jpg file to my app's Documents directory like this: NSData *img = UIImageJPEGRepresentation(myUIImage, 1.0); BOOL retValue = [img writeToFile:myFilePath atomically:YES]; Later, I load that image back into a UIImage using: UIImage *myImage = [UIImage imageWithContentsOfFile:path]; I know it works because I can draw the image in a table cell and it is fine. Now if I try to use UIImageJPEGRepresentation(myImage, 1.0), the debugger prints out these lines: <Error>: Not a JPEG file: starts with 0xff 0xd9 <Error>: Application transferred too few scanlines And the function returns nil.

Convert any Data Type into NSData and back again

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 09:16:41
I'm working on an app where you can send either a text, image or a contact over Multipeer Connectivity to another device. It will then save in the second device's Core Data. What I do is send the data over as an NSDictionary and convert it back again. So I am left with an NSDictionary on the receiving device. How then, can I save the object for the key of @"objectData" to Core Data? I'd like it to work with NSString, UIImage & ABPerson. // Create a new object in the managed object context. Received *receivedData = [NSEntityDescription insertNewObjectForEntityForName:@"Received"

NSURLErrorDomain with code=-1100

萝らか妹 提交于 2019-11-28 08:08:28
问题 I was trying to download a picture to my app from The request failed with the error NSURLErrorDomain and the code is really -1100. The url should be correct since I checked it in the browser. Anyone knows why? let userImageURL: String! = "http://i.imgur.com/QhCzQoR.jpg"; let url = NSURL(fileURLWithPath: userImageURL); let request:NSURLRequest = NSURLRequest(URL: url!) NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: { (response

iPhone and GZip

Deadly 提交于 2019-11-28 07:05:24
Now I know that xCode automaticly does the GZip decrompession for you within: NSData *data = [NSData dataWithContentsOfURL:URL]; And it does work if I point to a Gzip file on my server. But since my content is dynamic, I have a PHP script that rather then create a gzip file like so: $zp = gzopen($file, "r"); $data = gzread($zp, $filesize); gzclose($zp); I encode my own data with: echo gzencode($data, 9); With this I add the following headers: header("Content-Type: application/x-gzip"); header("Content-Encoding: gzip"); header("Accepts-Encoding: gzip"); When I browse to the URL, my browser