Skip to content
This repository was archived by the owner on Jun 13, 2019. It is now read-only.

Commit 33b307d

Browse files
authored
Merge pull request #39 from k-thorat/feature-email
added email console log feature
2 parents ec0aa6c + 38267f6 commit 33b307d

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

Framework/Dotzu/Dotzu/Logs.storyboard

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="3CJ-ep-uee">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13178.6" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="3CJ-ep-uee">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13156.2"/>
99
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
1010
<capability name="Navigation items with more than one left or right bar item" minToolsVersion="7.0"/>
1111
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -20,7 +20,7 @@
2020
<viewControllerLayoutGuide type="bottom" id="E80-LL-KES"/>
2121
</layoutGuides>
2222
<view key="view" contentMode="scaleToFill" id="vD5-tz-SMX">
23-
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
23+
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
2424
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2525
<subviews>
2626
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="agn-ad-IWN">
@@ -117,7 +117,7 @@
117117
<viewControllerLayoutGuide type="bottom" id="R96-YX-hcO"/>
118118
</layoutGuides>
119119
<view key="view" contentMode="scaleToFill" id="XEb-Ml-Yki">
120-
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
120+
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
121121
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
122122
<subviews>
123123
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Ecr-Nv-94t">
@@ -162,7 +162,7 @@
162162
</view>
163163
<navigationItem key="navigationItem" id="zdN-FM-yI9">
164164
<segmentedControl key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="bar" selectedSegmentIndex="0" id="m5B-Ti-NBe">
165-
<rect key="frame" x="113" y="7" width="150" height="30"/>
165+
<rect key="frame" x="112.5" y="7" width="150" height="30"/>
166166
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
167167
<segments>
168168
<segment title="Logs"/>
@@ -173,14 +173,14 @@
173173
</connections>
174174
</segmentedControl>
175175
<rightBarButtonItems>
176-
<barButtonItem image="filter" id="H8s-CQ-trf">
176+
<barButtonItem systemItem="action" id="3pC-LT-CmH">
177177
<connections>
178-
<segue destination="4xb-fk-IJe" kind="presentation" identifier="filterSegue" modalPresentationStyle="overFullScreen" id="ZEU-l6-M97"/>
178+
<action selector="showActions" destination="fto-va-uFc" id="IIZ-He-bPh"/>
179179
</connections>
180180
</barButtonItem>
181-
<barButtonItem systemItem="trash" id="3pC-LT-CmH">
181+
<barButtonItem image="filter" id="H8s-CQ-trf">
182182
<connections>
183-
<action selector="resetLogs:" destination="fto-va-uFc" id="ASp-gP-cIH"/>
183+
<segue destination="4xb-fk-IJe" kind="presentation" identifier="filterSegue" modalPresentationStyle="overFullScreen" id="ZEU-l6-M97"/>
184184
</connections>
185185
</barButtonItem>
186186
</rightBarButtonItems>
@@ -519,7 +519,7 @@
519519
<tabBarItem key="tabBarItem" title="logs" image="tabbar-logs" selectedImage="tabbar-logs" id="Uuf-aW-P9g"/>
520520
<toolbarItems/>
521521
<navigationBar key="navigationBar" contentMode="scaleToFill" translucent="NO" id="EEW-tV-ACR">
522-
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
522+
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
523523
<autoresizingMask key="autoresizingMask"/>
524524
<color key="barTintColor" red="0.1215686277" green="0.1294117719" blue="0.1411764771" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
525525
<textAttributes key="titleTextAttributes">

Framework/Dotzu/Dotzu/ManagerListLogViewController.swift

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import MessageUI
1011

1112
class ManagerListLogViewController: UIViewController {
1213

@@ -81,7 +82,54 @@ class ManagerListLogViewController: UIViewController {
8182
LogNotificationApp.resetCountBadge.post(Void())
8283
}
8384

84-
@IBAction func resetLogs(_ sender: Any) {
85+
@IBAction func showActions() {
86+
87+
let alertController = UIAlertController(title: "More actions",
88+
message: nil,
89+
preferredStyle: .actionSheet)
90+
91+
let sendLogsButton = UIAlertAction(title: "Email logs",
92+
style: .default,
93+
handler: { [weak self] (action) in self?.emailLogs() })
94+
alertController.addAction(sendLogsButton)
95+
96+
let resetLogsButton = UIAlertAction(title: "Reset logs & network",
97+
style: .destructive,
98+
handler: { [weak self] (action) in self?.resetLogs() })
99+
alertController.addAction(resetLogsButton)
100+
101+
let cancelButton = UIAlertAction(title: "Cancel", style: .cancel, handler:nil)
102+
alertController.addAction(cancelButton)
103+
104+
self.navigationController?.present(alertController, animated: true, completion: nil)
105+
106+
}
107+
108+
private func emailLogs() {
109+
110+
if MFMailComposeViewController.canSendMail() {
111+
112+
let mail = MFMailComposeViewController()
113+
mail.mailComposeDelegate = self;
114+
let appName = Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String
115+
mail.setSubject("\(appName ?? "App") Log")
116+
117+
var formattedData = Data()
118+
for itemIndex in 0...self.dataSourceLogs.count {
119+
if let log = self.dataSourceLogs[itemIndex] {
120+
let format = LoggerFormat.format(log: log)
121+
let data = Data(("Log Index:\(itemIndex)\n \(format.str) \n\n").utf8)
122+
formattedData.append(data)
123+
}
124+
}
125+
126+
mail.addAttachmentData(formattedData, mimeType: "text/plain", fileName: "log-\(Date())")
127+
128+
self.present(mail, animated: true, completion: nil)
129+
}
130+
}
131+
132+
private func resetLogs() {
85133
dataSourceLogs.reset()
86134
dataSourceNetwork.reset()
87135
let storeLogs = StoreManager<Log>(store: .log)
@@ -192,3 +240,13 @@ extension ManagerListLogViewController: UITableViewDelegate {
192240
performSegue(withIdentifier: "detailRequestSegue", sender: LogRequest)
193241
}
194242
}
243+
244+
extension ManagerListLogViewController: MFMailComposeViewControllerDelegate {
245+
246+
public func mailComposeController(_ controller: MFMailComposeViewController,
247+
didFinishWith result: MFMailComposeResult,
248+
error: Error?) {
249+
250+
controller.dismiss(animated: true, completion: nil)
251+
}
252+
}

0 commit comments

Comments
 (0)