nsdata

Reading and writing images to an SQLite DB for iPhone use

 ̄綄美尐妖づ 提交于 2019-11-26 15:51:13
I've set up a SQLite DB that currently reads and writes NSString s perfectly. I also want to store an image in the database and recall it later. I've read up a bit on using NSData and encoding the image, but I'm not entirely sure what the syntax is for what I want to do. Any code snippets or examples would be greatly appreciated. My current process goes like this: UIImagePickerController -> User Chooses Image from Photos -> chosenImage is set to instance of UIImageView -> Now I want to take this image and store it in the DB I should mention this call will eventually be replaced with a call to

Finding image type from NSData or UIImage

不羁岁月 提交于 2019-11-26 15:41:34
I am loading an image from a URL provided by a third-party. There is no file extension (or filename for that matter) on the URL (as it is an obscured URL). I can take the data from this (in the form of NSData) and load it into a UIImage and display it fine. I want to persist this data to a file. However, I don't know what format the data is in (PNG, JPG, BMP)? I assume it is JPG (since it's an image from the web) but is there a programmatic way of finding out for sure? I've looked around StackOverflow and at the documentation and haven't been able to find anything. TIA. Edit: Do I really need

converting NSDictionary object to NSData object and vice-versa

谁说我不能喝 提交于 2019-11-26 15:39:07
问题 I have to convert an NSDictionary object into NSData and further I have to get the same NSDictionary out of the NSData object. How should I go about it? 回答1: use NSKeyedArchiver To convert NSDictionary To NSData NSMutableData *data = [[NSMutableData alloc]init]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data]; [archiver encodeObject:YOURDICTIONARY forKey: YOURDATAKEY]; archiver finishEncoding]; [data writeToFile:YOURFILEPATH atomically:YES]; [data

Encrypted NSData to NSString in obj-c?

喜夏-厌秋 提交于 2019-11-26 15:22:44
问题 I have an iPhone app which encrypts an inputted NSString using CCCrypt (AES256) and a plaintext key. The string and key are given to the encryption method which returns an NSData object. Requesting [data description] where 'data' is the encrypted string data gives an NSString like: "<0b368353 a707e7de 3eee5992 ee69827e e3603dc2 b0dbbc0b 861ca87d f39ce72a>" but when I try to convert that to an NSString, I get "(null)". I need to return an NSString to the user, which can be used to decrypt back

NSData won&#39;t accept valid base64 encoded string

隐身守侯 提交于 2019-11-26 14:27:18
问题 I'm implementing JSON Web Token authentication on the iOS (7) cient-side. It's working nicely. My app rceives tokens, and can make authenticated calls to my server with them. Now, I want my client side code to check for an expiration date on the token so it can know when to re-authenticate. Checking for the expiration date on a JWT auth token is straightforward. The authorization token is 3 base64 encoded JSON blobs, separated by a '.' - The expiration timestamp is in the middle blob, in a

Swift structs to NSData and back

大憨熊 提交于 2019-11-26 14:14:29
问题 I have a struct containing a struct and an NSObject that I want to serialize into an NSData object: struct Packet { var name: String var index: Int var numberOfPackets: Int var data: NSData } var thePacket = Packet(name: name, index: i, numberOfPackets: numberOfPackets, data: packetData) How do I best serialize the Packet into an NSData , and how do I best deserialize it? Using var bufferData = NSData(bytes: & thePacket, length: sizeof(Packet)) of only gives me the pointers of name and data.

How to compress/resize image on iOS before uploading to a server?

烂漫一生 提交于 2019-11-26 12:47:53
I'm currently uploading an image to a server using Imgur on iOS with the following code: NSData* imageData = UIImagePNGRepresentation(image); NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* fullPathToFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SBTempImage.png"]; [imageData writeToFile:fullPathToFile atomically:NO]; [uploadRequest setFile:fullPathToFile forKey:@"image"]; The code works fine when run in the simulator and uploading a file from the simulator's photo library because I'm on a fast ethernet connection.

is it possible to save NSMutableArray or NSDictionary data as file in iOS?

大城市里の小女人 提交于 2019-11-26 12:09:27
问题 I want to save an NSMutableArray or NSDictionary as a permanent file. Then, I would like to reopen the file later. Is this possible? If so, how can I do it? 回答1: To write in file NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:FILE_NAME]; [myArray writeToFile:filePath atomically:YES]; To read from file NSArray *paths

Decode Base-64 encoded PNG in an NSString

谁说胖子不能爱 提交于 2019-11-26 11:32:01
问题 I have some NSData which is Base-64 encoded and I would like to decode it, I have seen an example that looks like this NSData* myPNGData = [xmlString dataUsingEncoding:NSUTF8StringEncoding]; [Base64 initialize]; NSData *data = [Base64 decode:img]; cell.image.image = [UIImage imageWithData:myPNGData]; However this gives me a load of errors, I would like to know what to do in order to get this to work. Is there some type of file I need to import into my project or do I have to include a

NSData-AES Class Encryption/Decryption in Cocoa

做~自己de王妃 提交于 2019-11-26 10:29:52
问题 I am attempting to encrypt/decrypt a plain text file in my text editor. encrypting seems to work fine, but the decrypting does not work, the text comes up encrypted. I am certain i\'ve decrypted the text using the word i encrypted it with - could someone look through the snippet below and help me out? Thanks :) Encrypting: NSAlert *alert = [NSAlert alertWithMessageText:@\"Encryption\" defaultButton:@\"Set\" alternateButton:@\"Cancel\" otherButton:nil informativeTextWithFormat:@\"Please enter