0
我正在創建一個應用程序,允許用戶從單個頁面下載聲音文件並將其發送給自己,一旦導航到頁面並選擇了音調。多個下載按鈕
我想知道如果有誰知道如何連接下載按鈕這是每一頁上,並把它連接到郵件撰寫。我已經想出了聯繫頁面上的郵件編輯器,但是當我嘗試將郵件編輯器連接到每個頁面上的下載按鈕時,沒有任何反應,我嘗試過使用標籤,並且仍然失去了任何幫助,我們將不勝感激。在此先感謝
我正在創建一個應用程序,允許用戶從單個頁面下載聲音文件並將其發送給自己,一旦導航到頁面並選擇了音調。多個下載按鈕
我想知道如果有誰知道如何連接下載按鈕這是每一頁上,並把它連接到郵件撰寫。我已經想出了聯繫頁面上的郵件編輯器,但是當我嘗試將郵件編輯器連接到每個頁面上的下載按鈕時,沒有任何反應,我嘗試過使用標籤,並且仍然失去了任何幫助,我們將不勝感激。在此先感謝
我假設下載按鈕是您的按鈕。我假設每個「頁面」是不同的視圖控制器?
如果你想要非常高效,你可以創建一個單獨的類來保存你的郵件編輯器邏輯。
爲了快速修復,您可以將按鈕連接到視圖控制器中的IBAction,並將郵件編輯器邏輯放在那裏或從那裏調用它的方法。
下面是一個簡單的例子:
- (IBAction)sendProblemReport:(UIButton*)sender { //note: connect your button here
UIButton *button;
if ([sender isKindOfClass:[UIButton class]]) {
button = sender;
}
else {
return; //leave if not a button
}
//note: if you do it this way be sure to set tag values in interface builder on your button. The other way is to have an action for each button.
switch (button.tag) {
case 1:
NSURL *fileURL1 = [[NSURL alloc] initFileURLWithPath:@"YOUR FILE PATH HERE"];
NSData *soundfile = [[NSData alloc] initWithContentsOfURL:fileURL1];
NSString *fileTitle = @"YOUR Nice File Name"; //sound.mp3
[self showDiagMailSheetAttachingSoundFile:soundFile usingFileName:filename];
break;
}
}
- (void)showDiagMailSheetAttachingSoundFile:(NSData*)soundFile usingFileName:(NSString*)fileName {
MFMailComposeViewController *diagMail = [[MFMailComposeViewController alloc]init];
[diagMail setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[diagMail setToRecipients:@[@"[email protected]"]];
[diagMail setCcRecipients:nil];
[diagMail setBccRecipients:nil];
[diagMail setSubject:@"subject message"];
[diagMail setMessageBody:nil isHTML:NO];
[diagMail addAttachmentData:soundFile file mimeType:@"audio/mpeg" fileName:fileName]; //note: not sure of the mime type you need.
diagMail.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:diagMail animated:YES completion:nil];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
// @"Result: Mail sending canceled";
break;
case MFMailComposeResultSaved:
// @"Result: Mail saved";
break;
case MFMailComposeResultSent:
// @"Result: Mail sent";
break;
case MFMailComposeResultFailed:
// @"Result: Mail sending failed";
break;
default:
// @"Result: Mail not sent";
break;
}
[self dismissViewControllerAnimated:YES completion:^{
[self cancel:self];
}];
}
注意:把這個在一個獨立的子類,你可以使用類只返回一個「MFMailComposeViewController」那麼你會提出它在每個視圖控制器。該方法更高效,並允許您在多個地方調用相同的代碼。
好的,希望有所幫助。如果不讓我知道。
這種方式也允許我通過「下載」按鈕將每個聲音文件附加到每個頁面,所以當它被點擊時,郵件編輯器會拿出附加的聲音文件 – user1985904 2013-03-15 00:30:02
是的,它應該。我將編輯答案幷包含附件的代碼。 – CocoaEv 2013-03-15 00:33:55
當你說連接按鈕,你的意思是連接它通過cntrl拖動,因爲如果是這樣,它不會連接,你也有電子郵件我可以聯繫你,因爲這會容易得多,如果不是沒有問題 – user1985904 2013-03-15 00:55:40