How does ios send feedback code using system emails?

Source: Internet
Author: User

This class is mainly used for MFMailComposeViewController. The package is OK.

1.

Modify the corresponding code in the laungh function of the appDelegate class of ios:

[Cpp]View
Plaincopy

  1. // Set RootViewController to window
  2. If ([[UIDevice currentDevice]. systemVersion floatValue] <6.0)
  3. {
  4. // Warning: addSubView doesn' t work on iOS6
  5. [Window setrootviewcontroller: viewcontroller];
  6. [Window addsubview: viewcontroller. View];
  7. }
  8. Else
  9. {
  10. // Use this method on ios6
  11. [Window setrootviewcontroller: viewcontroller];
  12. }



The main purpose is to set

[Window setRootViewController: viewController];

To avoid crash when window. rootViewController is called later.


2. the header file content is as follows:

@interface EmailIOS : UIViewController <MFMailComposeViewControllerDelegate>{    MFMailComposeViewController* mailPicker;    UIWindow * window;}- (void)SendMail;@end


3. *. mm file implementation is as follows:

@ Implementation EmailIOS-(void) SendMail {if (! [MFMailComposeViewController canSendMail]) {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: nil message: [NSString stringwithuf8string: shareagemanager: sharedreceivagemanager () -> 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 feedback"]; [mailPicker setSubject: strSubject]; // Set up recipients NSArray * toRecipients = [NSArray arrayWithObject: @ "XXX@fuckU.com"]; [mailPicker handle: toRecipients]; NSString * device = [[UIDevice currentDevice] model]; NSString * ios = [[UIDevice currentDevice] systemVersion]; NSString * body = [NSString stringWithFormat: @ "Please leave your valuable suggestions and comments: \ n the following information helps us to confirm your problem. We recommend that you keep it. \ 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: addS UbView 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: shareddire () -> /// [[[CCDirector shareddire] view] insertSubview: mailPicker. view atIndex: 30];}-(void) mailComposeController :( MFMailComposeViewController *) controller d IdFinishWithResult :( MFMailComposeResult) result error :( NSError *) error {NSString * message; // Notifies users about errors associated with the interfaceswitch (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 ;} // The version is split during add, so the version is also split here. Otherwise, crash if ([[UIDevice currentDevice]. systemVersion floatValue] <6.0) {[mailPicker. view removeFromSuperview];} else {[mailPicker dismissModalViewControllerAnimated: YES];} [mailPicker release]; mailPicker = nil; // remove self [window removeFromSuperview] is not required here; [window release];}-(BOOL) returns :( UIInterfaceOrientation) interfaceOrientation {return partial (interfaceOrientation);} // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead-(NSUInteger) supportedInterfaceOrientations {# ifdef _ IPHONE_6_0 return UIInterfaceOrientationMaskLandscape; # endif return 0;}-(BOOL) shouldAutorotate {return YES;} @ end

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.