【Unity】ファイル添付してメーラーを起動する
黒羽のアリカでエラーログをメール添付して送る機能を作っていたときのメモ もともとApplication.OpenURLでmailtoスキーマを開いていたが、ファイル添付をしたかったので自作した
結論
iOSのNative Pluginを作って、MFMailComposeViewControllerを呼び出す
externメソッドを呼ぶ際にファイルのパスを渡す
code: Plugins/iOS/HxMail.mm
extern "C" {
@interface HXMailComposeViewDelegate : NSObject<MFMailComposeViewControllerDelegate>
@end
@implementation HXMailComposeViewDelegate
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
}
@end
void Hexat_Send_Mail_With_File (const char *to, const char *title, const char *message, const char *logfileUrl) {
[picker setToRecipients:@NSString stringWithCString:to encoding:NSUTF8StringEncoding];
picker.mailComposeDelegate = del;
}
}
code: Mail.cs
private static extern void Hexat_Send_Mail_With_File(
string to, string title, string message, string logFileUrl
);
public static void Mail(string to, string title, string message, string logFileUrl)
{
#if UNITY_IOS && !UNITY_EDITOR Hexat_Send_Mail_With_File(to, title, message, logFileUrl);
}
注意
iOSでしか動きません
ファイルが大きすぎるとどうなるかは知りません