nsdata

How to convert CMSampleBufferRef to NSData

家住魔仙堡 提交于 2020-01-10 10:29:09
问题 How do you convert CMSampleBufferRef to NSData? I've managed to get the data for an MPMediaItem by following Erik Aigner's answer on this thread, however the data is of type CMSampleBufferRef . I know CMSampleBufferRef is a struct and is defined in the CMSampleBuffer Reference in the iOS Dev Library, but I don't think I fully understand what it is. None of the CMSampleBuffer functions seem to be an obvious solution. 回答1: Here you go this works for audio sample buffer which is what you are

How to convert NSValue to NSData and back?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-10 10:14:35
问题 A have a number of NSValue (obtained via KVC valueForKey ) that I need to append to an NSData object in order to send it over the network using Game Center. Obviously I will also need to convert the NSValue back from NSData for more KVC ( setValue:forKey: ). I don't know the exact type of each NSValue , so I'm limited to using the interfaces provided by NSValue and NSData . I should mention that the NSValue are never pointer types. I'm surprised that there's no [NSData dataWithValue:value]

Unrecognized selector sent to instance while archiving data (NSCoding)

回眸只為那壹抹淺笑 提交于 2020-01-09 09:59:25
问题 -(void)transformObjects:(NSMutableArray*)array key:(NSString*)key { NSMutableArray* archiveArray = [[NSMutableArray alloc]initWithCapacity:array.count]; for (Furniture *furniture in array) { // The error occurs on the line below NSData *furnitureEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:furniture]; [archiveArray addObject:furnitureEncodedObject]; } NSUserDefaults *userData = [NSUserDefaults standardUserDefaults]; [userData setObject:archiveArray forKey:key]; } Error log:

How do I save an .m4a from web and copy to clipboard?

99封情书 提交于 2020-01-07 04:52:08
问题 I am downloading a .m4a from a url on an iOS device then copying to clipboard. So far, this is what I have: NSArray *preview = [JSON valueForKey:@"results.previewUrl"]; NSURL *previewUrl = [NSURL URLWithString:[preview objectAtIndex:0]]; NSData *previewData = [NSData dataWithContentsOfURL:previewUrl]; How do I copy that .m4a to clipboard? I believe there is a way to copy .mp3s and .mp4s (.m4a is same as .mp4). results.previewUrl is http://a281.phobos.apple.com/us/r1000/119/Music/v4/f1/7b/d6

How can I exchange various type's data through NSData?

折月煮酒 提交于 2020-01-07 03:55:09
问题 I'm creating a bluetooth match game application. I'm using func session(session: MCSession, didReceiveData data: NSData, fromPeer peerID: MCPeerID) on MCSessionDelegate . I want to exchange various type's data, like GameStatusClass, PlayerClass, EnemyClass, CGPoint etc, case by case. Then this is my code. I think, my code is not good because unarchiveObjectWithData is called twice. Do you have some idea to write simply or nice sample code? enum ModelType { case A case B } class BasicModel:

Why saving and loading UIImages in documents folder doesn't work properly in iOS 8+?

依然范特西╮ 提交于 2020-01-07 03:41:34
问题 I've been trying to save and load UIImages in my app's Documents folder or preferably temp folder (so every time my app gets closed images will be deleted) but they aren't working correctly. I've tried three approaches but only the third approach works and i'm wondering what's the right way to do it? I highly appreciate any help. //First Approach, to save and load later, Doesn't work. //Saving the image NSURL *documentsDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory

Failing to POST NSData of PDF to server

旧城冷巷雨未停 提交于 2020-01-06 19:32:30
问题 I have an iPad application in which I need to send a server a PDF file, alongside two POST variables, a user ID and a job ID. I am using the code below to do this: NSData *pdfData = [NSData dataWithContentsOfFile:currentPDFFileName]; NSData *validPDF = [[NSString stringWithString:@"%PDF"] dataUsingEncoding: NSASCIIStringEncoding]; if (!(pdfData && [[pdfData subdataWithRange:NSMakeRange(0, 4)] isEqualToData:validPDF])) { NSLog (@"Not valid"); } NSLog (@"%@", currentPDFFileName); NSLog (@"%@",

BLOB in SQLite?

故事扮演 提交于 2020-01-06 18:32:33
问题 I have created a SQLite database with an id AUTOINCREMENT and image BLOB. Now, I want to INSERT a image in the image column. I am a big objective-c nube and have been trying all sorts of stuff but they don't seem to be working. I know lots about MYSQl, but not SQLite and I can't seem to figure it out. I have uploadImage (UIImage). I am using Matteo Bertozzi's SQLite wrapper here. Here's some of my code I have after someone picks an image off their phone: - (void)imagePickerController:

Do a simple DNS lookup in Swift

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 14:51:45
问题 I am trying to do a simple DNS lookup with Swift code. So far, I have if host != "\0" { let hostRef = CFHostCreateWithName(kCFAllocatorDefault, host.bridgeToObjectiveC()).takeRetainedValue() var resolved = CFHostStartInfoResolution(hostRef, CFHostInfoType.Addresses, nil) let addresses = CFHostGetAddressing(hostRef, &resolved).takeRetainedValue() as NSArray for address: AnyObject in addresses { println(address) // address is of type NSData. } } as per Convert NSData to sockaddr struct in swift

How to get image from NSOutputStream in Objective-C

醉酒当歌 提交于 2020-01-06 04:46:04
问题 I am using twilio chat SDK, in that I am doing store and retrieve the image. So to retrieve the image from twilio I am getting NSOutputStream , And I don't know that how to convert NSOutputStream to image. Please see the below code which provided by twilio and give me some suggestions. chatCell.message = message.body; if (message.hasMedia) { NSLog(@"mediaFilename: %@ (optional)", message.mediaFilename); NSLog(@"mediaSize: %lu", (unsigned long)message.mediaSize); // Set up output stream for