Attacher une image choisie dans la librairie dans un mail

juillet 2012 modifié dans Apple Developer Programs #1
Bonjour , j'ai essayé avec le code ci dessous d'ajouter la photo que l'utilisateur choisit de la librairie dans un mail , mais ca ne marche pas .. si vous pourriez me dire si oui ou non mon code est exact :
<br />
-(void)imagePickerController:(UIImagePickerController *)picker<br />
	   didFinishPickingImage:(UIImage *)image<br />
				 editingInfo:(NSDictionary *) {<br />
    [picker dismissModalViewControllerAnimated:YES];<br />
 <br />
    ok = [[MFMailComposeViewController alloc] init];<br />
    [ok setMailComposeDelegate:self];<br />
 <br />
    if ([MFMailComposeViewController canSendMail]) {<br />
	    [ok setToRecipients:[NSArray arrayWithObjects:@&quot;antes@gmail.com&quot;, nil]];<br />
	    [ok setSubject:@&quot;Contact par rapport à ...&quot;];<br />
	    [ok setMessageBody:@&quot;Je vous contacte à  propos de...&quot; isHTML:NO];<br />
	 <br />
   <br />
	 <br />
	 <br />
		 <br />
		    UIImage *image = [Info objectForKey:UIImagePickerControllerOriginalImage];<br />
		    NSData *thepicture = UIImageJPEGRepresentation(image, 1);<br />
		    [ok addAttachmentData:<br />
		    thepicture mimeType:@&quot;image/jpeg&quot; fileName:UIImagePickerControllerOriginalImage];	 <br />
	 <br />
	 <br />
	    }<br />
 <br />
	    [ok setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];<br />
	    [self presentModalViewController:ok animated:YES];<br />
	    [ok release];<br />
	 <br />
	 <br />
	 <br />
}<br />
<br />
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {<br />
 <br />
    if (error) {<br />
	    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@&quot;error&quot; message:[NSString stringWithFormat:@&quot;error %@&quot; , [error description]] delegate:nil cancelButtonTitle:@&quot;Annuler&quot; otherButtonTitles:nil, nil];<br />
	 <br />
	 <br />
	    [alert show];<br />
	    [alert release];<br />
	    [self dismissModalViewControllerAnimated:YES];<br />
    }<br />
 <br />
    else {<br />
	    [self dismissModalViewControllerAnimated:YES];<br />
    }<br />
}<br />






Merci pour votre précieuse aide !

Réponses

  • AliGatorAliGator Membre, Modérateur
    Message sans balise "code" = illisible, j'ai même pas lu.

    Pense à  mieux formatter tes messages pour qu'on ait envie un minimum de les lire et de t'aider... et pense aussi à  aller te présenter dans la section adéquate, qu'on sache un peu qui tu es et surtout ton niveau.
  • 'AliGator' a écrit:


    Message sans balise "code" = illisible, j'ai même pas lu.

    Pense à  mieux formatter tes messages pour qu'on ait envie un minimum de les lire et de t'aider... et pense aussi à  aller te présenter dans la section adéquate, qu'on sache un peu qui tu es et surtout ton niveau.




    Merci , je suis nouveau donc je ne connaissais pas trop les regles du forums . Peux tu m'envoyer un lien , ou me dire comment je peut me presenter dans "la section adéquate" en question ?

    Merci
  • Bonjour,



    Pour te présenter il faut clicker sur Forums ensuite y a une rubrique présentation ou tu pourra dire bonjour à  tout le monde et parler un peu de toi ( je viens de le faire aussi).



    Pour ton problème iOS, essai de regarder si tu charge bien l'image, par exemple cette ligne :
    [color=#660066][font=monospace][size=3]UIImage[/size][/font][/color][color=#666600][font=monospace][size=3]*[/size][/font][/color][color=#000000][font=monospace][size=3]image [/size][/font][/color][color=#666600][font=monospace][size=3]=[/size][/font][/color][color=#666600][font=monospace][size=3][[/size][/font][/color][color=#660066][font=monospace][size=3]Info[/size][/font][/color][color=#000000][font=monospace][size=3] objectForKey[/size][/font][/color][color=#666600][font=monospace][size=3]:[/size][/font][/color][color=#660066][font=monospace][size=3]UIImagePickerControllerOriginalImage[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color]
    


    est ce que t'es sur que tu récupère bien ton objet image .?
  • <br />
    [ok addAttachmentData:<br />
    				    thepicture mimeType:@&quot;image/jpeg&quot; fileName:UIImagePickerControllerOriginalImage];   <br />
    		<br />
    




    C'est ce bout de code dont je suis pas sur , et peut etre que c'est la ou je perds mon objet image..

    Pour la presentation , desolé mais je ne trouve pas d'onglet presentation !
  • Bonjour,

    Essai de fair comme ça, et essai de donner des noms explicites a tes classes/objets/méthodes , evite de genre "ok",




    <br />
    [color=#666600][font=monospace][size=3]-([/size][/font][/color][color=#000088][font=monospace][size=3]void[/size][/font][/color][color=#666600][font=monospace][size=3])[/size][/font][/color][color=#000000][font=monospace][size=3]imagePickerController[/size][/font][/color][color=#666600][font=monospace][size=3] <img src='http://forum.cocoacafe.fr/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />[/size][/font][/color][color=#660066][font=monospace][size=3]UIImagePickerController[/size][/font][/color][color=#666600][font=monospace][size=3]*)[/size][/font][/color][color=#000000][font=monospace][size=3]picker<br />
    		   didFinishPickingImage[/size][/font][/color][color=#666600][font=monospace][size=3] <img src='http://forum.cocoacafe.fr/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />[/size][/font][/color][color=#660066][font=monospace][size=3]UIImage[/size][/font][/color][color=#666600][font=monospace][size=3]*)[/size][/font][/color][color=#000000][font=monospace][size=3]image<br />
    								 editingInfo[/size][/font][/color][color=#666600][font=monospace][size=3] <img src='http://forum.cocoacafe.fr/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />[/size][/font][/color][color=#660066][font=monospace][size=3]NSDictionary[/size][/font][/color][color=#666600][font=monospace][size=3]*)[/size][/font][/color][color=#666600][font=monospace][size=3]{[/size][/font][/color]<br />
    [left][i]// Access the uncropped image from info dictionary[/i][/left]<br />
      UIImage [color=#002200]*[/color]image [color=#002200]=[/color] [color=#002200][[/color]info objectForKey[color=#002200]:[/color][color=#BF1D1A]@[/color][color=#BF1D1A]&quot;UIImagePickerControllerOriginalImage&quot;[/color][color=#002200]][/color];<br />
    <br />
      [color=#11740A][i]// Dismiss the camera[/i][/color]<br />
      [color=#002200][[/color]self dismissModalViewControllerAnimated[color=#002200]:[/color][color=#A61390]YES[/color][color=#002200]][/color];<br />
    <br />
      [color=#11740A][i]// Pass the image from camera to method that will email the same[/i][/color]<br />
      [color=#11740A][i]// A delay is needed so camera view can be dismissed[/i][/color]<br />
      [color=#002200][[/color]self performSelector[color=#002200]:[/color][color=#A61390]@selector[/color][color=#002200]([/color]emailImage[color=#002200]:[/color][color=#002200])[/color] withObject[color=#002200]:[/color]image afterDelay[color=#002200]:[/color][color=#2400D9]1.0[/color][color=#002200]][/color];<br />
    <br />
    }<br />
    <br />
    [color=#002200]-[/color] [color=#002200]([/color][color=#A61390]void[/color][color=#002200])[/color]emailImage[color=#002200]:[/color][color=#002200]([/color]UIImage [color=#002200]*[/color][color=#002200])[/color]image<br />
    <br />
    [color=#660066][font=monospace][size=3]MFMailComposeViewController*[/size][/font][/color] ok [color=#666600][font=monospace][size=3]=[/size][/font][/color][color=#666600][font=monospace][size=3][[[/size][/font][/color][color=#660066][font=monospace][size=3]MFMailComposeViewController[/size][/font][/color][color=#000000][font=monospace][size=3] alloc[/size][/font][/color][color=#666600][font=monospace][size=3]][/size][/font][/color][color=#000000][font=monospace][size=3] init[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color]<br />
    [color=#666600][font=monospace][size=3][[/size][/font][/color][color=#000000][font=monospace][size=3]ok setMailComposeDelegate[/size][/font][/color][color=#666600][font=monospace][size=3]:[/size][/font][/color][color=#000088][font=monospace][size=3]self[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color]<br />
    <br />
    [color=#000000][font=monospace][size=3]	[/size][/font][/color][color=#000088][font=monospace][size=3]if[/size][/font][/color][color=#666600][font=monospace][size=3]([[/size][/font][/color][color=#660066][font=monospace][size=3]MFMailComposeViewController[/size][/font][/color][color=#000000][font=monospace][size=3] canSendMail[/size][/font][/color][color=#666600][font=monospace][size=3]])[/size][/font][/color][color=#666600][font=monospace][size=3]{[/size][/font][/color]<br />
    [color=#666600][font=monospace][size=3][[/size][/font][/color][color=#000000][font=monospace][size=3]ok setToRecipients[/size][/font][/color][color=#666600][font=monospace][size=3]:[[/size][/font][/color][color=#660066][font=monospace][size=3]NSArray[/size][/font][/color][color=#000000][font=monospace][size=3] arrayWithObjects[/size][/font][/color][color=#666600][font=monospace][size=3]:@[/size][/font][/color][color=#008800][font=monospace][size=3]&quot;antes@gmail.com&quot;[/size][/font][/color][color=#666600][font=monospace][size=3],[/size][/font][/color][color=#000088][font=monospace][size=3]nil[/size][/font][/color][color=#666600][font=monospace][size=3]]];[/size][/font][/color]<br />
    [color=#666600][font=monospace][size=3][[/size][/font][/color][color=#000000][font=monospace][size=3]ok setSubject[/size][/font][/color][color=#666600][font=monospace][size=3]:@[/size][/font][/color][color=#008800][font=monospace][size=3]&quot;Contact par rapport à ...&quot;[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color]<br />
    [color=#666600][font=monospace][size=3][[/size][/font][/color][color=#000000][font=monospace][size=3]ok setMessageBody[/size][/font][/color][color=#666600][font=monospace][size=3]:@[/size][/font][/color][color=#008800][font=monospace][size=3]&quot;Je vous contacte à  propos de...&quot;[/size][/font][/color][color=#000000][font=monospace][size=3] isHTML[/size][/font][/color][color=#666600][font=monospace][size=3]:[/size][/font][/color][color=#000000][font=monospace][size=3]NO[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color]<br />
    <br />
    <br />
    [color=#660066][font=monospace][size=3]NSData[/size][/font][/color][color=#666600][font=monospace][size=3]*[/size][/font][/color][color=#000000][font=monospace][size=3]thepicture [/size][/font][/color][color=#666600][font=monospace][size=3]=[/size][/font][/color][color=#660066][font=monospace][size=3]UIImageJPEGRepresentation[/size][/font][/color][color=#666600][font=monospace][size=3]([/size][/font][/color][color=#000000][font=monospace][size=3]image[/size][/font][/color][color=#666600][font=monospace][size=3]);[/size][/font][/color]<br />
    [color=#666600][font=monospace][size=3][[/size][/font][/color][color=#000000][font=monospace][size=3]ok addAttachmentData[/size][/font][/color][color=#666600][font=monospace][size=3]:[/size][/font][/color]<br />
    [color=#000000][font=monospace][size=3]					thepicture mimeType[/size][/font][/color][color=#666600][font=monospace][size=3]:@[/size][/font][/color][color=#008800][font=monospace][size=3]&quot;image/jpeg&quot;[/size][/font][/color][color=#000000][font=monospace][size=3] fileName[/size][/font][/color][color=#666600][font=monospace][size=3]:[/size][/font][/color][color=#660066][font=monospace][size=3]UIImagePickerControllerOriginalImage[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color][color=#000000][font=monospace][size=3]	<br />
    		<br />
    		<br />
    			[/size][/font][/color][color=#666600][font=monospace][size=3]}[/size][/font][/color]<br />
    <br />
    [color=#000000][font=monospace][size=3]  [/size][/font][/color][color=#666600][font=monospace][size=3][[/size][/font][/color][color=#000000][font=monospace][size=3]ok setModalTransitionStyle[/size][/font][/color][color=#666600][font=monospace][size=3]:[/size][/font][/color][color=#660066][font=monospace][size=3]UIModalTransitionStyleCrossDissolve[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color]<br />
    [color=#666600][font=monospace][size=3][[/size][/font][/color][color=#000088][font=monospace][size=3]self[/size][/font][/color][color=#000000][font=monospace][size=3] presentModalViewController[/size][/font][/color][color=#666600][font=monospace][size=3]:[/size][/font][/color][color=#000000][font=monospace][size=3]ok animated[/size][/font][/color][color=#666600][font=monospace][size=3]:[/size][/font][/color][color=#000000][font=monospace][size=3]YES[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color]<br />
    [color=#666600][font=monospace][size=3][[/size][/font][/color][color=#000000][font=monospace][size=3]ok release[/size][/font][/color][color=#666600][font=monospace][size=3]];[/size][/font][/color]<br />
    [color=#666600][font=monospace][size=3]}[/size][/font][/color]<br />
    
  • Le Mail Composer apparait sans l'image , mais j'ai l'impression que c'est une erreur d'extension :

    http://hpics.li/f3d50c3
  • Quelqu'un m'a répondu sur un autre forum , et ce code marche :
    <br />
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info<br />
    {<br />
        [picker dismissViewControllerAnimated:YES completion:^(void){<br />
    	    MFMailComposeViewController *mailComposeVC = [[MFMailComposeViewController alloc] init];<br />
    	    mailComposeVC.mailComposeDelegate = self;<br />
    	    [mailComposeVC setSubject:@&quot;Hello from iPhone&quot;];<br />
    	    NSArray *toRecipients = [NSArray arrayWithObjects:@&quot;someone@gmail.com&quot;, nil];<br />
    	    [mailComposeVC setToRecipients:toRecipients];<br />
    	    NSData *myData = UIImageJPEGRepresentation([info objectForKey:@&quot;UIImagePickerControllerOriginalImage&quot;], 0.8f); <br />
    	    [mailComposeVC addAttachmentData:myData mimeType:@&quot;image/png&quot; fileName:@&quot;sunshine.jpg&quot;];<br />
    	    NSString *emailBody = @&quot;It is not raining for some strange reason&#33;&quot;;<br />
    	    [mailComposeVC setMessageBody:emailBody isHTML:NO];<br />
    	    [self presentModalViewController:mailComposeVC animated:YES];<br />
    <br />
        }];<br />
    }<br />
    




    Merci quand meme pour votre aide.
Connectez-vous ou Inscrivez-vous pour répondre.