nsdata

Is there any difference between dataWithContentsOfURL (threaded) and dataTaskWithURL?

早过忘川 提交于 2019-12-02 07:19:08
We're using dataWithContentsOfURL because it is, uh, simple... NSData *datRaw = [NSData dataWithContentsOfURL:ur]; Now, of course, that will hang the main UI thread. So we put it on another thread. We do that exactly thus, -(void)performSearch:(NSString *)stuff then:(void(^)(void))after { dispatch_queue_t otherThread =dispatch_queue_create(nil,0); dispatch_queue_t mainThread =dispatch_get_main_queue(); dispatch_async(otherThread, ^{ self.resultsRA = [self ... calls dataWithContentsOfURL ...]; dispatch_async(mainThread, ^{ if (after) after(); }); }); } (Incidentally, here's an excellent

how to convert byte array to image in ios

风流意气都作罢 提交于 2019-12-02 07:04:33
问题 today my task is convert byte array to image First I try to convert image to byte array :- For converting Image to Byte array first we have to do is to convert that particular image [ UIImage ] to NSData .Then we will convert that NSData to Byte array. Here I will give the sample code, just go through... //Converting UIImage to NSData UIImage *image = [UIImage imageNamed: @"photo-04.jpg"]; NSData *imageData = UIImagePNGRepresentation(image); //Converting NSData to Byte array NSUInteger len =

Unarchiving UIImageView with subviews

倾然丶 夕夏残阳落幕 提交于 2019-12-02 05:12:12
问题 I'm going a bit crazy trying to archive and unarchive a UIImageView which has number of subviews which are custom views derived from UIImageView. Here's what I've done: Add a category to the project to allow for the fact that UIImage does not conform to NSCoding: #import "UIImage-NSCoding.h" #define kEncodingKey @"UIImage" @implementation UIImage(NSCoding) - (id)initWithCoder:(NSCoder *)decoder { if ((self = [super init])) { NSData *data = [decoder decodeObjectForKey:kEncodingKey]; self =

Data corrupt after converting byte[] to NSData

喜你入骨 提交于 2019-12-02 04:10:24
问题 I have .Net web service response containing a byte[] entry, among other fields. The data is a PDF file. I extract the Dictionary from the received data with: [NSJSONSerialization JSONObjectWithData] Hereafter I use the following code to convert the byte[] to NSData. I then save the result to disk (see last line). When opening the resulting PDF file, I get the following error: "failed to find PDF header: `%PDF' not found." NSArray *byteArray = [rootDictionary objectForKey:@"file"]; unsigned c

Iterate through NSData and grab chunks

余生长醉 提交于 2019-12-02 03:47:53
问题 IS there any way to iterate through NSData so I can split it based on specific byte patterns? I need to break of certain chunks into an array for later look up. 回答1: To split an NSData on some separator, you can search for the separator with rangeOfData:options:range: and then split using subdataWithRange: . For example (based on some code I'm currently working on, but I haven't tested this specific block): NSRange range = [data rangeOfData:delimiter options:0 range:NSMakeRange(0, data.length

How do I convert a 24-bit integer into a 3-byte array?

可紊 提交于 2019-12-02 03:29:10
问题 Hey Im totally out of my depth and my brain is starting to hurt.. :( I need to covert an integer so that it will fit in a 3 byte array.(is that a 24bit int?) and then back again to send/receive this number from a byte stream through a socket I have: NSMutableData* data = [NSMutableData data]; int msg = 125; const void *bytes[3]; bytes[0] = msg; bytes[1] = msg >> 8; bytes[2] = msg >> 16; [data appendBytes:bytes length:3]; NSLog(@"rtn: %d", [[[NSString alloc] initWithData:data encoding

saving images in string format (to use in xml)..not working

拈花ヽ惹草 提交于 2019-12-02 03:14:59
i am converting image from picker into nsdata(jpeg representation) and then converting it into nsstring using the following code NSData *data=UIImageJPEGRepresentation(image,1.0); NSString *imageString=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; [[NSUserDefaults standardUserDefaults] setObject:imageString forKey:@"image_name"]; and at the other end where i need to display the image the uiimage is formed as follows. NSString *imageString=[[NSString alloc] init]; imageString=[[NSUserDefaults standardUserDefaults] objectForKey:@"image_name"]; UIImage *image=[UIImage

How can I convert my Zip-file to NSData to email my Zip file as an attachment

て烟熏妆下的殇ゞ 提交于 2019-12-02 02:55:54
I', m using the Objective Zip library to compress several images i took. I came to the point (I guess) where I' zipping an image. Now I'd like to send this zipped File with the mailcomposer. However I need to declare a "NSData object" within my mail function. [picker addAttachmentData:"NSData object" mimeType:@"application/zip" fileName:@"test.zip"]; Here's a snippit of my code -(IBAction)sendMail{ NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory

How to convert NSData bytes into NSNumber or NSInteger?

微笑、不失礼 提交于 2019-12-02 02:04:08
There's a special NSString initWithData method for grabbing bits and converting them into string. However, I haven't found that in NSNumber class ref. Currently, I'm getting raw data (bytes) from a server in NSData format. I know how to do that in C, using memcpy and int pointers. But I am curious about what the convenience methods are for doing that straight from NSData . No conversion is needed. For example, I'm getting 00000010 byte, and I need to turn that into NSNumber of value 2, or NSInteger . ikuramedia NSData is just a bucket for bytes and has no knowledge of the data contained

How to convert NSData bytes into NSNumber or NSInteger?

荒凉一梦 提交于 2019-12-02 00:50:25
问题 There's a special NSString initWithData method for grabbing bits and converting them into string. However, I haven't found that in NSNumber class ref. Currently, I'm getting raw data (bytes) from a server in NSData format. I know how to do that in C, using memcpy and int pointers. But I am curious about what the convenience methods are for doing that straight from NSData . No conversion is needed. For example, I'm getting 00000010 byte, and I need to turn that into NSNumber of value 2, or