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