nsdata

Converting AVAudioPCMBuffer to NSData

吃可爱长大的小学妹 提交于 2019-12-11 17:13:36
问题 I'm currently trying to convert the audio samples from AVAudioPCMBuffer to NSData - I had taken a look at the accepted answer on this SO Post and this code from GitHub but it appears some of the AVFAudio API's have changed...below is the extension I have for AVAudioPCMBuffer : private extension AVAudioPCMBuffer { func toNSData() -> NSData { let channels = UnsafeBufferPointer(start: int16ChannelData, count: 1) let ch0Data = NSData(bytes: channels[0], length:Int(frameCapacity * format

Downloading images from server and saving into Database

两盒软妹~` 提交于 2019-12-11 16:16:20
问题 I have to download images and save it into my local database. So I am storing the images in NSData and than inserting it into local database. But there are atleast 50 images coming from the server so storing the images into NSData and then inserting into local database it taking more time. Is there any solution so that it will consume less time. Please suggest me. 回答1: The more common way to handle image download from the internet is just cache it to the memory(NSURLCache) or disk

Detect if Base 64 string is image or text

一世执手 提交于 2019-12-11 14:53:02
问题 Is there a way to detect if the Base 64 string contained in an NSData instance is an image or a text or any other object? 回答1: You can't generally just look at the base 64 string and decide, but you can decode the first few bytes of data, look at the hex codes (you can do this by decoding your base-64 string into a NSData and just NSLog it or examining it in the debugger), and draw some conclusions. For example: Image files generally start with special byte sequences (e.g. JPEG start with the

How to play NSData from Core Data in AVAudioPlayer

∥☆過路亽.° 提交于 2019-12-11 13:32:29
问题 I save mp3 file into Core Data as NSData binary data. Then I load this file with help of NSFetchedResultsController . Then I wrote following code but I got the error. How can I fix it? fatal error: unexpectedly found nil while unwrapping an Optional value var audioPlayer = AVAudioPlayer() func play() { if musicData != nil { audioPlayer = AVAudioPlayer(data: musicData, error: nil) AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil) AVAudioSession

Cancel NSData initWithContentsOfURL in NSOperation

为君一笑 提交于 2019-12-11 13:27:26
问题 I currently have the following code in an NSOperation that has an observer for keyPath "isCancelled": downloaded = FALSE; NSURL *url = [NSURL URLWithString:requestString]; dataXML = [[NSData alloc] initWithContentsOfURL:url]; downloaded = TRUE; I want to make it so that the observeValueForKeyPath function is able to cancel the dataXML continuing or just completely stop the NSOperation once the NSOperation is sent a cancel message. The NSOperation's cancelling operation cancel only notifies

Can't convert NSData read from a local file and output as string in Swift

跟風遠走 提交于 2019-12-11 12:31:53
问题 Well I am trying to creating a simple tool to read an specific offset address from a file that's within the project. I can read it fine and get the bytes, the problem is that I want to convert the result into a string, but I just can't. My output is this: <00000100 88000d00 02140dbb 05c3a282> but I want into String. Found some examples of doing it using an extension for NSData, but still didn't work. So anyone could help?? Here's my code: class ViewController: UIViewController { let filemgr =

How do I convert an NSData object with hex data to ASCII in Swift?

╄→гoц情女王★ 提交于 2019-12-11 12:19:49
问题 I have an NSData object with hex data and I want to convert it to an ASCII string. I've seen several similar questions to mine but they are all either in Objective-C and/or they convert a string into hex data instead of the other way around. I found this function but it doesn't work in Swift 2 and the Apple documentation doesn't explain the difference between the old stride and the new stride (it doesn't explain stride at all): func hex2ascii (example: String) -> String { var chars =

dataWithContentsOfURL and imageWithData take 84% of the whole loading time

廉价感情. 提交于 2019-12-11 12:05:51
问题 these two lines took 40% and 42% (together 84%) of the whole loading time of my app. I tested it with Instruments . NSData *storeImageData = [NSData dataWithContentsOfURL:storeImageURL]; //40% whole load time UIImage *storeImage = [UIImage imageWithData:storeImageData]; //42% whole load time Is there another / better way to speed up the loading time of my app? These two lines and a lot more code are in a loop wich will loop about 500 times. Note after adding "http://" to the usual "www.blah

Send attachments using sms/mms in iOS SDK

天涯浪子 提交于 2019-12-11 11:36:01
问题 In iOS 7, there is support for adding attachments in sms messages via third party applications. I want to know: What kind of files are supported as attachments? e.g. .png, .pdf etc. Can I send NSData through an sms/mms message? e.g. .dat format Would the recipient of these messages be able to open these attachments in third party applications using iOS's "Open In" feature? 回答1: The MFMessageComposeViewController wants the attachment to have the correct extension for the type of image you're

String(data: data, encoding: NSUTF8StringEncoding) return nil

旧巷老猫 提交于 2019-12-11 10:53:50
问题 I am using JSQMessage and pare to send and save video files if (mediaType == kUTTypeVideo as String) || (mediaType == kUTTypeMovie as String) { let movieURL = info[UIImagePickerControllerMediaURL] as? NSURL let videoMediaItem = JSQVideoMediaItem.init(fileURL: movieURL, isReadyToPlay: true) let message = JSQMessage(senderId: self.senderId, senderDisplayName: senderDisplayName, date: NSDate(), media: videoMediaItem) self.saveMediaToParse(message, data: NSData(contentsOfURL: movieURL!)!,