5

我试过这个没有运气:

        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];
4

1 回答 1

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 Window 并选择连接的调试设备中的 Applications 选项卡。您应该在主面板上看到文件结构。

于 2013-12-03T13:09:20.100 回答