ここemailcomposerwithattachment
にあるプラグインを使用して PDF を添付しようとしています。
問題は、電子メール コンポーザが表示されると、PDF が添付されていることが示されますが、送信後に電子メールを確認すると、ファイルがありません。
これはそれを呼び出す私のコードです。ファイル パスが正しく設定されていることを確認しました。(アプリの別の場所で子ブラウザーで動作する同じファイルを使用して) 正しく設定されているように見えます。
助言がありますか?また、私はコルドバ2.1.0を使用しています
プラグインを呼び出すコードは次のとおりです。
var strPath = window.location.href;
var path = encodeURI(strPath.substr(0,strPath.lastIndexOf('/')) + URL);
window.plugins.emailComposer.showEmailComposer(subject,body,[],[],[],true,[path]);
EmailComposer コードは次のとおりです。
- (void) showEmailComposer:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
[options valueForKey:@"toRecipients"], @"toRecipients",
[options valueForKey:@"ccRecipients"], @"ccRecipients",
[options valueForKey:@"bccRecipients"], @"bccRecipients",
[options valueForKey:@"subject"], @"subject",
[options valueForKey:@"body"], @"body",
[options valueForKey:@"bIsHTML"], @"bIsHTML",
[options valueForKey:@"attachments"], @"attachments",
nil];
[self showEmailComposerWithParameters:parameters];
}
-(void) showEmailComposerWithParameters:(NSDictionary*)parameters {
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
// set subject
@try {
NSString* subject = [parameters objectForKey:@"subject"];
if (subject) {
[mailComposer setSubject:subject];
}
}
@catch (NSException *exception) {
NSLog(@"EmailComposer - Cannot set subject; error: %@", exception);
}
// set body
@try {
NSString* body = [parameters objectForKey:@"body"];
BOOL isHTML = [[parameters objectForKey:@"bIsHTML"] boolValue];
if(body) {
[mailComposer setMessageBody:body isHTML:isHTML];
}
}
@catch (NSException *exception) {
NSLog(@"EmailComposer - Cannot set body; error: %@", exception);
}
// Set recipients
@try {
NSArray* toRecipientsArray = [parameters objectForKey:@"toRecipients"];
if(toRecipientsArray) {
[mailComposer setToRecipients:toRecipientsArray];
}
}
@catch (NSException *exception) {
NSLog(@"EmailComposer - Cannot set TO recipients; error: %@", exception);
}
@try {
NSArray* ccRecipientsArray = [parameters objectForKey:@"ccRecipients"];
if(ccRecipientsArray) {
[mailComposer setCcRecipients:ccRecipientsArray];
}
}
@catch (NSException *exception) {
NSLog(@"EmailComposer - Cannot set CC recipients; error: %@", exception);
}
@try {
NSArray* bccRecipientsArray = [parameters objectForKey:@"bccRecipients"];
if(bccRecipientsArray) {
[mailComposer setBccRecipients:bccRecipientsArray];
}
}
@catch (NSException *exception) {
NSLog(@"EmailComposer - Cannot set BCC recipients; error: %@", exception);
}
@try {
int counter = 1;
NSArray *attachmentPaths = [parameters objectForKey:@"attachments"];
if (attachmentPaths) {
for (NSString* path in attachmentPaths) {
@try {
NSLog(@"setting the path: %@", path);
if ([path hasSuffix:@".pdf"]) {
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
[mailComposer addAttachmentData:data mimeType:@"application/pdf" fileName:[NSString stringWithFormat:@"attachment%d.pdf", counter]];
} else {
// supposed image
UIImage *image = [UIImage imageWithContentsOfFile:path];
NSData *data = UIImagePNGRepresentation(image);
[mailComposer addAttachmentData:data mimeType:@"image/png" fileName:[NSString stringWithFormat:@"attachment%d.png", counter]];
}
counter++;
}
@catch (NSException *exception) {
NSLog(@"Cannot attach file at path %@; error: %@", path, exception);
}
}
}
}
@catch (NSException *exception) {
NSLog(@"EmailComposer - Cannot set attachments; error: %@", exception);
}
if (mailComposer != nil) {
[self.viewController presentModalViewController:mailComposer animated:YES];
} else {
[self returnWithCode:RETURN_CODE_EMAIL_NOTSENT];
}
[mailComposer release];
}