を使用してアプリMFMailComposeViewController
でメールを送信し、受信者が埋め込みをクリックしurl
て対応するWebサイトを開くことができるようにします。
MFMailComposeViewController
これを明示的にサポートしていないようです。何か案は?
5 に答える
以前の回答は正しくなく、無関係だったため、削除しました。たくさんの髪を引っ張った後、私はついに私の場合に何が起こっているのかを理解しました、そしておそらくこの質問で起こっていることです。
MFMailComposeViewControllerのHTML本文を作成するときは、HTMLに改行を入れる必要があります。行の長さが76文字を超える場合、本文は次のように解釈されます。
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
改行を入れると、それContent-Transfer-Encoding: quoted-printable
は起こらず、すべてが期待どおりに機能します。適切なHTMLがあると仮定します。
例として、次のようにボディを構築します。
NSMutableString *body = [NSMutableString string];
// add HTML before the link here with line breaks (\n)
[body appendString:@"<h1>Hello User!</h1>\n"];
[body appendString:@"<a href=\"http://www.mysite.com/path/to/link\">Click Me!</a>\n"];
[body appendString:@"<div>Thanks much!</div>\n"];
乾杯!
:)はい、あなたはこれを行うことができます:
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:subject];
[composer setMessageBody:message isHTML:YES];
ここで、メッセージはHTMLコンテンツを含む単なるNSStringです。内部には、必要なすべてのHTMLを追加できます。
私も同じ問題を抱えてる。
私のリンクはHTMLです。「青」が表示されますが、クリックしてもサファリモバイルが開きません。テキストの編集を許可されています。
クラスで私はこれを持っています:
-(id) init{
self = [super init];
if (self) {
if ([MFMailComposeViewController canSendMail]) {
self.mailComposeDelegate = self;
[self setSubject: @"Subject"];
[self setMessageBody: @"<h2>Body</h2><a href='http://www.google.com'>link example</a>" isHTML: YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Mail Accounts"
message:@"You don't have a Mail account configured, please configure to send email."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
}
}
return self;
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
[controller dismissModalViewControllerAnimated: YES];
}
ここでは、iPadのスクリーンショットを見ることができます。
送信してから「送信済み」メールボックスに移動するとリンクが機能するので、リンクを開くイベントが問題だと思います。
ありがとう。
本文( )setMessageBody:isHTML:
で適切なHTMLリンクを使用して渡し、パラメータに渡します。<a href="your_url">your link text</a>
YES
isHTML
あなたはあなたのコードをあなたの提案で試しましたか?このWebサイトにアクセスする前に試してみましたが、申し訳ありませんが、まったく機能しません。リンクは実際には青色で表示され、HTMLはhtmlとして読み取られますが、リンクはできません。リンクをクリックすると、編集することができます。
より良い提案はありますか?