ios如何利用系统邮件发送反馈 代码
2013-04-21 10:25
381 查看
主要是使用MFMailComposeViewController 这个类,包装下就ok.
1.
将ios的appDelegate类 的laungh函数中,将相应的代码修改为:
[cpp] view
plaincopy
// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[window setRootViewController:viewController];
[window addSubview: viewController.view];
}
else
{
// use this method on ios6
[window setRootViewController:viewController];
}
主要目的是 当SDK< 6.0的时候,也设置
[window setRootViewController:viewController];
以免后面调用 window.rootViewController的时候crash.
2. 头文件内容如下:
@interface EmailIOS : UIViewController <MFMailComposeViewControllerDelegate>
{
MFMailComposeViewController* mailPicker;
UIWindow * window;
}
- (void)SendMail;
@end
3. *.mm文件实现如下:
@implementation EmailIOS
- (void)SendMail
{
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:nil
message:[NSString stringWithUTF8String:LanguageManager::sharedLanguageManager()->getLocalizedString("Please configure your Email first").c_str()]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return ;
}
if(mailPicker != nil)
{
[mailPicker release];
}
mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
mailPicker.navigationBar.tintColor=[UIColor colorWithRed:(11.0/255.0) green:(81.0/255.0) blue:(112.0/255.0) alpha:1];
// mailPicker.navigationBar.tintColor=[UIColor colorWithRed:(90.0/255.0) green:(182.0/255.0) blue:(45.0/255.0) alpha:1];
NSString* strSubject = [NSString stringWithFormat:@"XXX APP反馈"];
[mailPicker setSubject:strSubject];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"XXX@fuckU.com"];
[mailPicker setToRecipients:toRecipients];
NSString * device = [[UIDevice currentDevice] model];
NSString * ios = [[UIDevice currentDevice] systemVersion];
NSString *body = [NSString stringWithFormat:@"请留下您的宝贵建议和意见:\n\n\n以下信息有助于我们确认您的问题,建议保留。\nApp id:\nApp Version: %s\nDevice: %@\nOS Version: %@\n", GAME_VERSION, device, ios];
[mailPicker setMessageBody:body isHTML:NO];
[self presentModalViewController:mailPicker animated:YES];
mailPicker.view.frame = [UIScreen mainScreen].bounds;
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[window addSubview: mailPicker.view];
}
else
{
// use this method on ios6
window.rootViewController = self;
[window setRootViewController:self];
}
[window makeKeyAndVisible];
// cocos2d::CCDirector::sharedDirector()->
//
// [[[CCDirector sharedDirector] view] insertSubview:mailPicker.view atIndex:30];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
NSString * message;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultSent:
{
message = @"Successfully sent!";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email"
message:message
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
break;
case MFMailComposeResultFailed:
{
//message = @"Result: failed";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email"
message:[NSString stringWithFormat:@"Error! Please try again later. (error msg = %@)", @"Failed to send email"]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
break;
default:
{
//message = @"Result: not sent";
//DLog(@"%@",message);
}
break;
}
//add 的时候是分版本的,所以这里也是分版本,否则crash
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
[mailPicker.view removeFromSuperview];
}
else
{
[mailPicker dismissModalViewControllerAnimated:YES];
}
[mailPicker release];
mailPicker = nil;
//这个地方不需要remove self
[window removeFromSuperview];
[window release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
return UIInterfaceOrientationMaskLandscape;
#endif
return 0;
}
- (BOOL) shouldAutorotate {
return YES;
}
@end
1.
将ios的appDelegate类 的laungh函数中,将相应的代码修改为:
[cpp] view
plaincopy
// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[window setRootViewController:viewController];
[window addSubview: viewController.view];
}
else
{
// use this method on ios6
[window setRootViewController:viewController];
}
主要目的是 当SDK< 6.0的时候,也设置
[window setRootViewController:viewController];
以免后面调用 window.rootViewController的时候crash.
2. 头文件内容如下:
@interface EmailIOS : UIViewController <MFMailComposeViewControllerDelegate>
{
MFMailComposeViewController* mailPicker;
UIWindow * window;
}
- (void)SendMail;
@end
3. *.mm文件实现如下:
@implementation EmailIOS
- (void)SendMail
{
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:nil
message:[NSString stringWithUTF8String:LanguageManager::sharedLanguageManager()->getLocalizedString("Please configure your Email first").c_str()]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return ;
}
if(mailPicker != nil)
{
[mailPicker release];
}
mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
mailPicker.navigationBar.tintColor=[UIColor colorWithRed:(11.0/255.0) green:(81.0/255.0) blue:(112.0/255.0) alpha:1];
// mailPicker.navigationBar.tintColor=[UIColor colorWithRed:(90.0/255.0) green:(182.0/255.0) blue:(45.0/255.0) alpha:1];
NSString* strSubject = [NSString stringWithFormat:@"XXX APP反馈"];
[mailPicker setSubject:strSubject];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"XXX@fuckU.com"];
[mailPicker setToRecipients:toRecipients];
NSString * device = [[UIDevice currentDevice] model];
NSString * ios = [[UIDevice currentDevice] systemVersion];
NSString *body = [NSString stringWithFormat:@"请留下您的宝贵建议和意见:\n\n\n以下信息有助于我们确认您的问题,建议保留。\nApp id:\nApp Version: %s\nDevice: %@\nOS Version: %@\n", GAME_VERSION, device, ios];
[mailPicker setMessageBody:body isHTML:NO];
[self presentModalViewController:mailPicker animated:YES];
mailPicker.view.frame = [UIScreen mainScreen].bounds;
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[window addSubview: mailPicker.view];
}
else
{
// use this method on ios6
window.rootViewController = self;
[window setRootViewController:self];
}
[window makeKeyAndVisible];
// cocos2d::CCDirector::sharedDirector()->
//
// [[[CCDirector sharedDirector] view] insertSubview:mailPicker.view atIndex:30];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
NSString * message;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultSent:
{
message = @"Successfully sent!";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email"
message:message
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
break;
case MFMailComposeResultFailed:
{
//message = @"Result: failed";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email"
message:[NSString stringWithFormat:@"Error! Please try again later. (error msg = %@)", @"Failed to send email"]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
break;
default:
{
//message = @"Result: not sent";
//DLog(@"%@",message);
}
break;
}
//add 的时候是分版本的,所以这里也是分版本,否则crash
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
[mailPicker.view removeFromSuperview];
}
else
{
[mailPicker dismissModalViewControllerAnimated:YES];
}
[mailPicker release];
mailPicker = nil;
//这个地方不需要remove self
[window removeFromSuperview];
[window release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
return UIInterfaceOrientationMaskLandscape;
#endif
return 0;
}
- (BOOL) shouldAutorotate {
return YES;
}
@end
相关文章推荐
- ios如何利用系统邮件发送邮件
- 如何用java代码给指定邮箱发送邮件
- 邮件系统中邮件发送不成功如何解决?
- iOS-调用系统的短信和发送邮件功能,实现短信分享邮件分享
- asp.net利用Jmail发送邮件和接收全部代码
- Spring进阶—如何用Java代码实现邮件发送(一)
- linux下c代码如何把指定文件作为附件,通过evolution发送邮件
- 利用oracle系统包UTL_SMTP发送邮件
- iOS开发之邮件发送代码
- 举例说明如何在android中利用Service来实现后台发送邮件功能
- iOS开发之邮件发送代码
- Windows 7系统如何设置某一动作(如发送邮件)默认启动的程序
- 如何利用sendmail发送外部邮件?
- ASP.NET中常用功能代码总结(7)——利用Jmail发送和接收邮件
- [小代码]设定邮件内容,发送邮件(适用于意见反馈功能)
- iOS-调用系统的短信和发送邮件功能,实现短信分享邮件分享
- 在没有个人/公司网站的情况下,如何利用同一个二维码自动识别手机系统(Android/IOS)跳转不同下载页面
- Smtp邮件发送系统公用代码整理—总结
- 浅谈如何利用配置方式配置SMTP发送邮件
- 如何利用sendmail发送外部邮件?