2010-12-30 4 views
0

私はiphoneを初めて使っています。私は電子メール機能を実装しようとしています。連絡先を追加する必要があります。連絡先はボタンのクリックイベントに表示されます。連絡先のリストの下で、私は連絡先を選択し、アドレスのテキストフィールドに配置されます。これどうやってするの?iphoneでのメール

サンプルコードを送信できますか?

ありがとうございます。

答えて

0

使用これは間違いなく動作します。このコードは、

-(IBAction)send{ 
[self callMailComposer]; 
} 

-(void)callMailComposer{ 
Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
if (mailClass != nil) 
{ 
    // We must always check whether the current device is configured for  sending emails 
    if ([mailClass canSendMail]) 
     [self displayComposerSheet]; 
    else 
     [self launchMailAppOnDevice]; 
} 

else 
{ 
    [self launchMailAppOnDevice]; 
} 
} 

プラグママーク -

プラグママークメール作成

プラグママーク

// Displays an email composition interface inside the application. Populates all the Mail fields. 

-(void)displayComposerSheet 
{ 
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 


picker.mailComposeDelegate = self; 
NSString *tosubject [email protected]""; 
[picker setSubject:tosubject]; 


// Set up recipients 
[picker setCcRecipients:nil]; 
[picker setBccRecipients:nil]; 

[picker setToRecipients:nil]; 



[picker setMessageBody:strNewsLink isHTML:NO]; 

[self presentModalViewController:picker animated:YES]; 

if(picker) [picker release]; 
if(picker) picker=nil; 

}

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation. 

    - (void)mailComposeController:(MFMailComposeViewController*)controller     didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
//message.hidden = NO; 
// Notifies users about errors associated with the interface 
switch (result) 
{ 
    case MFMailComposeResultCancelled: 
     [UIAlertView showAlertViewWithTitle:@"Canes Crunch" message:@"You have Cancelled of sending e-mail"]; 

     break; 
    case MFMailComposeResultSaved: 
     [UIAlertView showAlertViewWithTitle:@"Canes Crunch" message:@"Your e-mail has been saved successfully"]; 

     break; 
    case MFMailComposeResultSent: 
     [UIAlertView showAlertViewWithTitle:@"Canes Crunch" message:@"Your e-mail has been sent successfully"]; 

     break; 
    case MFMailComposeResultFailed: 
     [UIAlertView showAlertViewWithTitle:@"Canes Crunch" message:@"Failed to send e-mail"]; 

     break; 
    default: 
     [UIAlertView showAlertViewWithTitle:@"Canes Crunch" message:@"E-mail Not Sent"]; 

     break; 
} 
[self dismissModalViewControllerAnimated:YES]; 

}

プラグママーク

プラグママーク策

プラグママーク

// Launches the Mail application on the device. 
-(void)launchMailAppOnDevice 
{ 

NSString *recipients = @"mailto:?cc=&subject="; 
NSString *body = @"&body="; 
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body]; 
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]]; 

} 
関連する問題