UIActivityViewController是否可以附加AAC?

时间:2012-10-28 08:07:23

标签: objective-c ios6 uiactivityviewcontroller

我试了这个没有运气:

        NSData *imageData = UIImageJPEGRepresentation([sight.photo valueForKey:@"image"], 0.8);

        NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

        NSString *filePath = [docsPath stringByAppendingPathComponent:@"sound.m4a"];
        NSURL *fileUrl     = [NSURL fileURLWithPath:filePath];
        NSData *aacData = [sight.sound valueForKey:@"soundrecord"];
        [aacData writeToURL:fileUrl atomically:YES];
        //    NSString *text = self.textField.text;
        NSArray *items = @[imageData, aacData];

1 个答案:

答案 0 :(得分:4)

是的,但您需要将音频文件URL传递给活动表而不是NSData。

NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,    NSUserDomainMask, YES)objectAtIndex:0];
NSString *filePath = [docPath stringByAppendingPathComponent:@"sound.aac"];

NSURL *fileUrl     = [NSURL fileURLWithPath:filePath isDirectory:NO];
NSArray *activityItems = @[fileUrl];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

如果从活动表中启动电子邮件编辑器时发现附件未显示,请确保文件路径和URL正确并且文件存在(包括设备/模拟器驱动器上的扩展名)。

要在模拟器上打开文件,请转到文件夹(〜/ Library / Application Support / iPhone Simulator / ...

要检查设备上的文件名,请转到XCode Organizer窗口,然后在连接的调试设备中选择“应用程序”选项卡。您应该在主面板上看到文件结构。