草庐IT

libGTM_NSData

全部标签

ios - 使用 AVAudioPlayer iOS 从 NSData 播放声音

我想播放从我的服务器检索到的声音文件,作为base64编码文件。到目前为止,我已经使用base64解码文件并将其写入文件:NSFileManager*fileManager=[NSFileManagerdefaultManager];NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);NSString*documentsDirectory=[pathsobjectAtIndex:0];NSString*filePath=[documentsDirector

ios - 将 NSObject 的所有属性编码为 NSData

所以我是iOS的新手,但我对一项简单任务的复杂性感到有点困惑。我试图在NSUserDefaults中存储名为“Vehicle”的自定义NSObject类。显然,这是做不到的,所以我需要先将它编码为NSDATA。很好。但这意味着我需要在解码中对类的每个属性进行编码......在我的Vehicle类中...-(void)encodeWithCoder:(NSCoder*)coder{[coderencodeInt:xforKey:@"x"];[coderencodeInt:yforKey:@"y"];[coderencodeInt:directionforKey:@"direction"]

IOS NSData构造函数VS NSMutableData实时使用目的

我有void*缓冲区...我需要尽快将它封装在一个NSData结构中(NSData或NSMutableData)我猜只使用一个NSMutableData(在类中定义)-(void)resetBytesInRange:(NSRange)range-(void)appendBytes:(constvoid*)byteslength:(NSUInteger)length甚至-(void)replaceBytesInRange:(NSRange)rangewithBytes:(constvoid*)bytes将比使用[NSDatadataWithData:]每次函数调用要快得多...这是用于音

ios - 为了制作示例存折应用程序,在 .pkpass 文件中获取 NSData 为 nil

NSString*filePath=[[[NSBundlemainBundle]resourcePath]stringByAppendingPathComponent:@"freehugcoupon.pkpass"];NSLog(@"Filepath=[%@]",filePath);NSData*data=[NSDatadataWithContentsOfFile:filePath];NSError*error;if(data!=nil){PKPass*pass=[[PKPassalloc]initWithData:dataerror:&error];NSLog(@"Error=[%@

iphone - NSData dataWithContentsOfFile 仪器 100% 泄漏

已更新为什么NSDatadataWithContentsOfFile行在Instruments中显示泄漏?我正在使用ARC。部署目标是iOS5.0@autoreleasepool{AudioPlayerAV*context=[userInfovalueForKey:@"self"];NSString*filepath=[userInfovalueForKey:@"filepath"];[context.playerstop];//checkiffileistherefetchplayerfromdictAVAudioPlayer*_player=nil;NSError*error=ni

iphone - 如何使用 MPMediaPickerController 获取 mp3 的 NSData?

我想从我的手机上传mp3到服务器,为此我使用MPMediaPickerController。获取MPMediaItem的URL后,我想获取此url的NSData,但我在NSData中获取的是null。-(void)mediaPicker:(MPMediaPickerController*)mediaPickerdidPickMediaItems:(MPMediaItemCollection*)mediaItemCollection{[selfdismissViewControllerAnimated:YEScompletion:nil];MPMediaItem*item=[[media

ios - 错误为 "The operation couldn’ 的 NSData 无法完成。 ( cocoa 错误 256。)”

这个问题在这里已经有了答案:Cocoaerror256coredata(5个答案)关闭9年前。试图显示从网络服务下载的图像到UIImage,可以得到确切的图像路径(通过URLString)并显示在NSLog。现在的问题是imageData正在返回null值而不是要返回的值。错误消息将打印为:Theoperationcouldn’tbecompleted.(Cocoaerror256.)用于检索图像路径的代码如下所述,NSString*urlString=[resultobjectForKey:@"image"];NSLog(@"urlimageis%@\n",urlString);NS

ios - 如何在不转换为 NSData 的情况下获取 UIImage(ImageURL) 高度和宽度

在我的项目中,我需要以之字形方式显示不同大小的图像。所以,我将来自服务的uiimages(url)转换为NSData,然后我得到了uiimage。我的代码是NSURL*url=[NSURLURLWithString:[[_resultobjectAtIndex:i]valueForKey:@"PImage"]];NSData*data=[NSDatadataWithContentsOfURL:url];UIImage*image=[UIImageimageWithData:data];所以我可以获得图像大小(宽度和高度),但我的问题是根据图像大小,我需要创建UIView,这段代码对我来

ios - nsdata dataWithBytes 在 iOS7 上导致崩溃

它仅在iOS7上崩溃+(PageSection*)initwithPageSection:_anchorwithHeader:_subHeaderwithDetails:_textwithPhoneNumberIfValid:(id)_phoneNo{constchar*tempAnchor=[_anchorcStringUsingEncoding:[NSStringdefaultCStringEncoding]];constchar*tempSubHeader=[_subHeadercStringUsingEncoding:[NSStringdefaultCStringEncodin

ios - NSData 与归档

我想我只是不知道有什么区别,因为我不理解“黑匣子”,但是使用这些方法中的任何一种有什么区别?我应该什么时候使用NSDatawriteToFile:atomically:我应该什么时候使用[NSKeyedArchiverarchiveRootObject:toFile:]使用它们各自的优缺点是什么? 最佳答案 这两个API做不同的事情:NSData将“原始”字节写入文件。您可以通过假设您读回的字节位于正确的位置来恢复这些字节背后的结构。从某种意义上说,这类似于将曲奇刀应用于具有某种结构的作品,期望正确的作品出现在正确的位置。这种方法的