nsdata

UIImage to raw NSData / avoid compression

淺唱寂寞╮ 提交于 2019-11-29 12:18:59
I have my own image downloader class, it holds a queue and downloads images one (or a certain amount) at a time, writes them to the cache folder and retrieves them from the cache folder when necessary. I also have a UIImageView subclass to which I can pass a URL, through the image downloader class it will look if the image already exists on the device and show it if it does, or download and show it after it finished. After an image finishes downloading I do the following. I create a UIImage from the downloaded NSData, save the downloaded NSData to disk and return the UIImage. // This is

NSJSONSerialization and Emoji

百般思念 提交于 2019-11-29 11:53:27
I'm currently trying to POST some JSON containing emojis to a python API. I tried feeding the NSJSONSerialization directly with the string containing the emojis from my UITextField but the serializer crashed with no meaningful explanation. Afterwards I tried to do some format conversion and ended up with something like this: NSString *uniText = mytextField.text; NSData *msgData = [uniText dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *goodMsg = [[NSString alloc] initWithData:msgData encoding:NSUTF8StringEncoding] ; This basically works except that the resulting UTF-8 is kinda

Convert NSAttributedString into Data for storage

元气小坏坏 提交于 2019-11-29 11:09:51
I have a UITextView with attributed text and allowsEditingTextAttributes set to true . I'm trying to convert the attributed string into a Data object, using the following code: let text = self.textView.attributedText let data = try text.data(from: NSMakeRange(0, text.length), documentAttributes: [:]) However, this is throwing the following error: Error Domain=NSCocoaErrorDomain Code=66062 "(null)" Any ideas what this error means or what could cause this? I'm on the latest Xcode and iOS. Thanks. You need to specify what kind of document data you would like to convert your attributed string to:

Progress bar while downloading files iOS

瘦欲@ 提交于 2019-11-29 10:49:57
I am using the following to download the files from the internet: NSData *myXMLData1 = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"Link]]; Now, I would like to put a progress bar while the download is going on. I checked various posts but i am not able to find out how to do it exactly. Please help me!! I would recommend looking into the ASIHTTP library, which contains a lot of usefull classes on mobile handling and download handling. Here is a link where they describe what ASIHTTP can offer in terms of download progress tracking : http://allseeing-i.com/ASIHTTPRequest/How-to

NSMutableArray Data Attachement With E-mail Body?

会有一股神秘感。 提交于 2019-11-29 08:58:47
My NSMutableArray data are in NSData formate.I am trying to attached NSMutableArray data to E-mail body.Here is my NSMutableArray code: NSUserDefaults *defaults1 = [NSUserDefaults standardUserDefaults]; NSString *msg1 = [defaults1 objectForKey:@"key5"]; NSData *colorData = [defaults1 objectForKey:@"key6"]; UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData]; NSData *colorData1 = [defaults1 objectForKey:@"key7"]; UIColor *color1 = [NSKeyedUnarchiver unarchiveObjectWithData:colorData1]; NSData *colorData2 = [defaults1 objectForKey:@"key8"]; UIFont *color2 = [NSKeyedUnarchiver

NSData dataWithContentsOfURL: not returning data for URL that shows in browser

会有一股神秘感。 提交于 2019-11-29 08:52:13
I am making an iOS client for the Stack Exchange API. After a long, drawn out fight I finally managed to implement authentication - which gives me a token I stick into a URL. When the token is valid, the URL looks like this: https://api.stackexchange.com/2.1/me/associated?key=_____MY_SECRET_KEY______&access_token=_____ACCESS_TOKEN_:)_____ which, when valid, brings me to this JSON in a webpage: {"items":[{"site_name":"Stack Overflow","site_url":"http://stackoverflow.com","user_id":1849664,"reputation":4220,"account_id":1703573,"creation_date":1353769269,"badge_counts":{"gold":8,"silver":12,

NSData to String in Swift Issues

允我心安 提交于 2019-11-29 07:27:01
I'm having issues converting my NSData to NSString in swift. I'm using what I think is the correct command and format: NSString(data: <DATA>, encoding: <ENCODING>) however whatever I do i keep ending up with a nil value. I am running the latest Xcode beta so I'm not sure if that is related but I'm hoping its a simple easy error that I've run into. I've attached playground code as well as a screen capture. Playground Code for Xcode 6.3 Beta 2 Build (6D532l) import Foundation //: # NSData to String Conversion Playground //: ### Step 1 //: The first step is to take an array of bytes and conver

Does -dataWithContentsOfURL: of NSData work in a background thread?

﹥>﹥吖頭↗ 提交于 2019-11-29 07:06:52
问题 Does -dataWithContentsOfURL: of NSData work in a background thread? 回答1: No, it doesn't. In order to get data from URL asynchronously you should use the NSURLRequest and NSURLConnection approach. You will have to implement the NSURLConnectionDelegate methods: -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response; -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data; -(void)connectionDidFinishLoading:(NSURLConnection *)connection;

NSData dataWithContentsOfURL

此生再无相见时 提交于 2019-11-29 06:28:59
I have this method for button click (download). The problem is that it is terminating due to an exception: [Session started at 2011-03-14 13:06:45 +0530.] 2011-03-14 13:06:45.710 XML[7079:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString isFileURL]: unrecognized selector sent to instance 0x62b8' -(IBAction) download { UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:@"http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif"]]; [image release]; } What is the problem? It expects an NSURL as argument, not a string.

Trying to Write NSString sha1 function, but it's returning null

一个人想着一个人 提交于 2019-11-29 04:52:14
I have the following Objective-C function: +(NSString *)stringToSha1:(NSString *)str{ NSMutableData *dataToHash = [[NSMutableData alloc] init]; [dataToHash appendData:[str dataUsingEncoding:NSUTF8StringEncoding]]; unsigned char hashBytes[CC_SHA1_DIGEST_LENGTH]; CC_SHA1([dataToHash bytes], [dataToHash length], hashBytes); NSData *encodedData = [NSData dataWithBytes:hashBytes length:CC_SHA1_DIGEST_LENGTH]; [dataToHash release]; NSString *encodedStr = [NSString stringWithUTF8String:[encodedData bytes]]; //NSString *encodedStr = [[NSString alloc] initWithBytes:[encodedData bytes] // length: