-
Notifications
You must be signed in to change notification settings - Fork 0
/
AboutViewController.swift
87 lines (63 loc) · 2.99 KB
/
AboutViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// AboutViewController.swift
// Beloe Radio
//
// Created by Danila Chub on 5/1/21.
// Copyright (c) 2020 Beloe-Radio.by. All rights reserved.
//
import UIKit
import MessageUI
import GoogleMobileAds
class AboutViewController: UIViewController {
//*****************************************************************
// MARK: - ViewDidLoad
//*****************************************************************
override func viewDidLoad() {
super.viewDidLoad()
}
//*****************************************************************
// MARK: - IBActions
//*****************************************************************
@IBAction func emailButtonDidTouch(_ sender: UIButton) {
// Use your own email address & subject
let receipients = ["Chdanil@gmail.com"]
let subject = "From Beloe Radio App"
let messageBody = ""
let configuredMailComposeViewController = configureMailComposeViewController(recepients: receipients, subject: subject, messageBody: messageBody)
if canSendMail() {
present(configuredMailComposeViewController, animated: true, completion: nil)
} else {
showSendMailErrorAlert()
}
}
@IBAction func websiteButtonDidTouch(_ sender: UIButton) {
// Use your own website here
guard let url = URL(string: "http://Beloe-Radio.by") else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
//*****************************************************************
// MARK: - MFMailComposeViewController Delegate
//*****************************************************************
extension AboutViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
func canSendMail() -> Bool {
return MFMailComposeViewController.canSendMail()
}
func configureMailComposeViewController(recepients: [String], subject: String, messageBody: String) -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(recepients)
mailComposerVC.setSubject(subject)
mailComposerVC.setMessageBody(messageBody, isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertController(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
sendMailErrorAlert.addAction(cancelAction)
present(sendMailErrorAlert, animated: true, completion: nil)
}
}