cocoa-touch - Objective C - 通过 MFMailComposeViewController 的附件未显示

标签 cocoa-touch email audio wav mfmailcomposeviewcontroller

我正在尝试从 iOS 应用程序附加一个 wav 文件,但即使附件在撰写的邮件中可见,也未送达。

相关代码如下:

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setSubject:NSLocalizedString(@"mailTopic", nil)];
    [controller setMessageBody:NSLocalizedString(@"mailBody", nil) isHTML:YES];
    NSString *wavPath = [self exportAssetAsWaveFormat:self.myRec.soundFilePath]; // CAF->Wav export

    if (wavPath != nil) {
        NSLog(@"wavPath: %@", wavPath);
        NSData *recData = [NSData dataWithContentsOfFile:wavPath];
        NSString *mime = [self giveMimeForPath:wavPath];
        [controller addAttachmentData:recData mimeType:mime fileName:@"MySound.wav"];
        [self presentModalViewController:controller animated:YES];
        [controller release];
    }
}


-(NSString *) giveMimeForPath:(NSString *)filePath {
    NSURL* fileUrl = [NSURL fileURLWithPath:filePath];
    NSURLRequest* fileUrlRequest = [[NSURLRequest alloc] initWithURL:fileUrl cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:.1];
    NSURLResponse* response = nil;

    [NSURLConnection sendSynchronousRequest:fileUrlRequest returningResponse:&response  error:nil];
    NSString* mimeType = [response MIMEType];
    NSLog(@"MIME: %@", mimeType);
    [fileUrlRequest release];

    return mimeType;
}

NSLog 结果:

NSLog(@"wavPath: %@", wavPath); ->“wavPath:/var/mobile/Applications/71256DCA-9007-4697-957E-AEAE827FD97F/Documents/MySound.wav”

NSLog(@"MIME: %@", mimeType); ->“MIME:音频/wav”

文件路径接缝没问题(参见 NSLog 数据),并且 mime 类型设置为“audio/wav”..无法弄清楚这一点..

最佳答案

错误是当我用它创建 NSData 时,wav 文件还没有 100% 写入..duuuh

感谢大家的努力

关于cocoa-touch - Objective C - 通过 MFMailComposeViewController 的附件未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10381392/

相关文章:

ios - 使用线程/ block 安全集合来协调多个异步操作? (NSMutableArray 或 NSMutableSet)

ruby-on-rails - Rails ActionMailer 将电子邮件复制到已发送文件夹 SMTP ruby

c# - 发送纯文本电子邮件并在来自服务器的电子邮件响应中获取 =0D=0A

iphone - 如何在uiscrollview中滑动图像时添加短声音

javascript - 如何在移动设备上按下 Web Audio 元素时立即发出声音?

ios - 向 UINavigationController 添加按钮的问题

ios - Storyboard无法打开

iphone - 我正在所有类中创建栏按钮。有没有办法只创建一次栏按钮并在所有类中使用它?

javascript - 在 CMS 中的何处放置简单的 "Accept Conditions and Book"脚本

c# - 使用 System.Media.SoundPlayer 播放 Windows 系统声音