0

私は、ユーザーがサウンドを選択した場合に、アプリから自分にメールで送信できるアプリに取り組んでいます。

添付ファイルの部分は「機能しているように見えます」が、メールを送信すると、受信者に添付ファイルがありませんか?

iPad / iPhone自体では、作曲に関しては取り付けているように見えますが、機能していませんか?:/

これが私が使用しているコードです。

- (void)onSend:(id)sender{

    int nIndex;

    UIButton    *btnSender = (UIButton *)sender;
    NSLog( @"%d", btnSender.tag );

    for ( int i = 0; i < [ m_aryFileName count ]; i++ ) {

        if( i == ( btnSender.tag - 100 ) ){
            nIndex = i;
        }

    }

    NSString *strFileName = [ m_aryFileName objectAtIndex:nIndex ];
    strFileName = [ strFileName stringByAppendingString:@".mp3" ];
    NSData*     nData = [ NSData dataWithContentsOfFile:strFileName ];

    MFMailComposeViewController *pickerMail = [[MFMailComposeViewController alloc] init];
    pickerMail.mailComposeDelegate = self;

    [pickerMail setSubject:@"myMail Attachment"];

    // Attach an image to the email
    [pickerMail addAttachmentData:nData mimeType:@"audio/mp3" fileName:strFileName ];

    // Fill out the email body text
    NSString *emailBody = @"Here is your attachment";

    [pickerMail setMessageBody:emailBody isHTML:YES];

    [self presentModalViewController:pickerMail animated:YES];
    [pickerMail release];

}
4

4 に答える 4

1

このコードメイトを試してみてください、

NSString *strFileName = [m_aryFileName objectAtIndex:nIndex];
strFileName = [strFileName stringByAppendingString:@".mp3"];
NSURL    *fileURL = [[NSURL alloc] initFileURLWithPath:strFileName];
NSData *nData = [[NSData alloc] initWithContentsOfURL:fileURL];

MFMailComposeViewController *pickerMail = [[MFMailComposeViewController alloc] init];
pickerMail.mailComposeDelegate = self;
[pickerMail setSubject:@"myMail Attachment"];
[pickerMail addAttachmentData:nData mimeType:@"audio/mpeg" fileName:strFileName ];
NSString *emailBody = @"Here is your attachment";
[pickerMail setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:pickerMail animated:YES];
于 2013-02-27T13:27:41.847 に答える
1

以下のコードはあなたに役立つかもしれません:

NSData * videoData = [NSData dataWithContentsOfURL:mediaUrl];

[mailcomposer addAttachmentData:videoData mimeType:@ "video / mp4" fileName:@ "Video"]

于 2013-03-04T11:47:39.063 に答える
0
if ([MFMailComposeViewController canSendMail] && m_pDataArray != nil) 
{
    NSString * pSongPath = [[NSBundle mainBundle] pathForResource:@"song" ofType"@"mp3"]; ;//get the file
    MFMailComposeViewController * pMailComposer = [[MFMailComposeViewController alloc] init];
    pMailComposer.mailComposeDelegate = self;
    [pMailComposer setMessageBody:@"msg body" isHTML:NO];
    NSURL * pFileUrl = [[[NSURL alloc] initFileURLWithPath:pSongPath] autorelease];
    NSData * pData = [[[NSData alloc] initWithContentsOfURL:pFileUrl] autorelease];
     [pMailComposer addAttachmentData:pData mimeType:@"audio/mpeg" fileName:@"song.mp3" ]];
     [self presentModalViewController:pMailComposer animated:YES];
     [pMailComposer release];
}
else
{
    UIAlertView *pAlert = [[UIAlertView alloc] initWithTitle:@"Failure" message:@"Your device doesn't support the composer sheet"                                                       delegate:nil  cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [pAlert show];
    [pAlert release];
    pAlert = nil;
}

ファイルの拡張子が.mp3のようになっていることを確認してください。その場合、ファイルは正しく機能します。

于 2013-03-04T11:31:00.233 に答える
0

audio/mpeg代わりにのmimeタイプを使用してみてください。この値を取得するには、次のコードを実行します。

#import <MobileCoreServices/MobileCoreServices.h>

CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
                                                        (__bridge CFStringRef)@"mp3",
                                                        NULL);
CFStringRef mimeTags = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
CFRelease(uti);
NSString *mediaType = [NSString stringWithString:(__bridge NSString *)mimeTags];
CFRelease(mimeTags);

それはどのように機能しますか?

于 2013-03-04T12:06:44.650 に答える