2

I'm trying to attach a wav-file from an iOS application but the attachment is not delivered even though it's visible in the composed mail.

Heres the related code:

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 results:

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

NSLog(@"MIME: %@", mimeType); -> "MIME: audio/wav"

The file path seams to be ok (see NSLog data), and the mime type set to "audio/wav".. Cant figure this out..

4

2 回答 2

2

错误是,当我用它创建 NSData 时,wav 文件不是 100% 写入的。duuuh

感谢大佬们的努力

于 2012-05-02T09:02:30.243 回答
0

也许目的地是剥离该类型的附件?您是否尝试过手动发送带有 .wav 的消息并查看它是否有效?我在尝试发送到 Zendesk 时遇到了同样的问题。事实证明,他们剥离了某些 mimetypes 的附件。

于 2012-04-30T10:19:30.950 回答