gpt4 book ai didi

cocoa-touch - objective-c -通过MFMailComposeViewController的附件未显示

转载 作者:行者123 更新时间:2023-12-02 22:28:31 24 4
gpt4 key购买 nike

我正在尝试从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:音频/音频”

文件路径接缝正常(请参阅NSLog数据),并且mime类型设置为“audio / wav”。

最佳答案

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

谢谢你们的努力

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com