- Possibility to send log file by email from app ios-revival
authorantonc27 <antonc27@mail.ru>
Tue, 15 Sep 2015 06:05:11 +0200
branchios-revival
changeset 11177 015596575698
parent 11176 906c1878bc2c
child 11181 a515139fc8de
- Possibility to send log file by email from app Note: Ugly ifdef's are necessary, because we don't want to include MessageUI framework into 'Distro Appstore' build scheme
project_files/HedgewarsMobile/Classes/GameLogViewController.m
project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
--- a/project_files/HedgewarsMobile/Classes/GameLogViewController.m	Tue Sep 15 04:28:25 2015 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameLogViewController.m	Tue Sep 15 06:05:11 2015 +0200
@@ -18,7 +18,14 @@
 
 #import "GameLogViewController.h"
 
+#ifdef DEBUG
+#import <MessageUI/MFMailComposeViewController.h>
+#endif
+
 @interface GameLogViewController ()
+#ifdef DEBUG
+<MFMailComposeViewControllerDelegate>
+#endif
 
 @end
 
@@ -30,10 +37,21 @@
 {
     [super viewDidLoad];
     
+    self.title = @"Last game log";
+    
     UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(dismissAction)];
     self.navigationItem.rightBarButtonItem = closeButton;
     [closeButton release];
     
+#ifdef DEBUG
+    if ([self allowSendLogByEmail])
+    {
+        UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStylePlain target:self action:@selector(sendLogByEmailAction)];
+        self.navigationItem.leftBarButtonItem = sendButton;
+        [sendButton release];
+    }
+#endif
+    
     NSString *debugStr = nil;
     if ([[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()])
         debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE() encoding:NSUTF8StringEncoding error:nil];
@@ -50,13 +68,71 @@
     [logView release];
 }
 
+#pragma mark - Parameters
+
+#ifdef DEBUG
+- (BOOL)allowSendLogByEmail
+{
+    return ([MFMailComposeViewController canSendMail] && [[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()]);
+}
+#endif
+
 #pragma mark - Actions
 
+#ifdef DEBUG
+- (void)sendLogByEmailAction
+{
+    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
+    picker.mailComposeDelegate = self;
+    [picker setSubject:@"Log file of iHedgewars game"];
+    
+    // Attach a log file to the email
+    NSData *logData = [NSData dataWithContentsOfFile:DEBUG_FILE()];
+    [picker addAttachmentData:logData mimeType:@"text/plain" fileName:@"game0.log"];
+    
+    // Fill out the email body text
+    NSString *emailBody = @"Add here description of a problem/log";
+    [picker setMessageBody:emailBody isHTML:NO];
+    
+    [self presentViewController:picker animated:YES completion:nil];
+    [picker release];
+}
+#endif
+
 - (void)dismissAction
 {
     [self dismissViewControllerAnimated:YES completion:nil];
 }
 
+#pragma mark - MailCompose delegate
+
+#ifdef DEBUG
+- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
+{
+    // Notifies users about errors associated with the interface
+    switch (result)
+    {
+        case MFMailComposeResultCancelled:
+            NSLog(@"MailComposeResult: canceled");
+            break;
+        case MFMailComposeResultSaved:
+            NSLog(@"MailComposeResult: saved");
+            break;
+        case MFMailComposeResultSent:
+            NSLog(@"MailComposeResult: sent");
+            break;
+        case MFMailComposeResultFailed:
+            NSLog(@"MailComposeResult: failed");
+            break;
+        default:
+            NSLog(@"MailComposeResult: not sent");
+            break;
+    }
+    
+    [self dismissViewControllerAnimated:YES completion:nil];
+}
+#endif
+
 #pragma mark - Memory warning
 
 - (void)didReceiveMemoryWarning
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Tue Sep 15 04:28:25 2015 +0200
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Tue Sep 15 06:05:11 2015 +0200
@@ -1922,6 +1922,8 @@
 		1D6058940D05DD3E006BFB54 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				CODE_SIGN_IDENTITY = "iPhone Developer";
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				GCC_DYNAMIC_NO_PIC = NO;
 				GCC_GENERATE_TEST_COVERAGE_FILES = YES;
 				GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
@@ -1929,17 +1931,21 @@
 				GCC_PREFIX_HEADER = Hedgewars_Prefix.pch;
 				INFOPLIST_FILE = Info.plist;
 				PRODUCT_NAME = Hedgewars;
+				PROVISIONING_PROFILE = "";
 			};
 			name = Debug;
 		};
 		1D6058950D05DD3E006BFB54 /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				CODE_SIGN_IDENTITY = "iPhone Developer";
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				COPY_PHASE_STRIP = YES;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = Hedgewars_Prefix.pch;
 				INFOPLIST_FILE = Info.plist;
 				PRODUCT_NAME = Hedgewars;
+				PROVISIONING_PROFILE = "";
 			};
 			name = Release;
 		};
@@ -2026,11 +2032,14 @@
 		61022D7D12305A2800B08935 /* Distro AppStore */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				CODE_SIGN_IDENTITY = "iPhone Developer";
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				COPY_PHASE_STRIP = YES;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = Hedgewars_Prefix.pch;
 				INFOPLIST_FILE = Info.plist;
 				PRODUCT_NAME = Hedgewars;
+				PROVISIONING_PROFILE = "";
 			};
 			name = "Distro AppStore";
 		};
@@ -2120,6 +2129,8 @@
 				OTHER_LDFLAGS = (
 					"-lz",
 					"-Wl,-no_order_inits",
+					"-framework",
+					MessageUI,
 				);
 				PREBINDING = NO;
 				PROVISIONING_PROFILE = "";
@@ -2140,11 +2151,14 @@
 		6137064C117B1CB3004EE44A /* Distro Adhoc */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
+				CODE_SIGN_IDENTITY = "iPhone Developer";
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				COPY_PHASE_STRIP = YES;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = Hedgewars_Prefix.pch;
 				INFOPLIST_FILE = Info.plist;
 				PRODUCT_NAME = Hedgewars;
+				PROVISIONING_PROFILE = "";
 			};
 			name = "Distro Adhoc";
 		};
@@ -2279,6 +2293,8 @@
 				OTHER_LDFLAGS = (
 					"-lz",
 					"-Wl,-no_order_inits",
+					"-framework",
+					MessageUI,
 				);
 				PREBINDING = NO;
 				PROVISIONING_PROFILE = "";
@@ -2359,6 +2375,8 @@
 				OTHER_LDFLAGS = (
 					"-lz",
 					"-Wl,-no_order_inits",
+					"-framework",
+					MessageUI,
 				);
 				PREBINDING = NO;
 				PROVISIONING_PROFILE = "";