我正在尝试从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:audio / wav”
文件路径接缝正常(参见NSLog数据),mime类型设置为“audio / wav”..无法解决这个问题..
答案 0 :(得分:2)
错误是当我创建NSData时,wav文件不是100%写的.. duuuh
感谢你们的努力
答案 1 :(得分:0)
也许目的地正在剥离那种类型的附件?您是否尝试手动发送带有.wav的消息并查看它是否有效?尝试发送给Zendesk时遇到了同样的问题。事实证明他们剥离了一些mimetypes的附件。