Created
March 28, 2020 14:52
-
-
Save SwapnanilDhol/012827d257324eda7fff4dbc40afa974 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SettingsViewController.swift | |
// ColorPicker | |
// | |
// Created by Swapnanil Dhol on 9/13/19. | |
// Copyright © 2019 Swapnanil Dhol. All rights reserved. | |
// | |
import UIKit | |
import TipJarViewController | |
import SafariServices | |
import MessageUI | |
class SettingsTableViewController: UITableViewController, MFMailComposeViewControllerDelegate{ | |
var device = String() | |
let generator = UIImpactFeedbackGenerator() | |
let controller = TipJarViewController<TipJarOptions>() | |
@IBOutlet weak private var tipBannerButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
tipBannerButton.imageView?.layer.cornerRadius = 8 | |
} | |
func rateApp() { | |
let url = URL(string: "itms-apps:itunes.apple.com/us/app/apple-store/1480273650?mt=8&action=write-review")! | |
UIApplication.shared.open(url) | |
} | |
func sendEmail() { | |
if MFMailComposeViewController.canSendMail() { | |
let mail = MFMailComposeViewController() | |
mail.mailComposeDelegate = self | |
mail.setToRecipients(["[email protected]"]) | |
if UIDevice.current.userInterfaceIdiom == .pad | |
{ | |
device = "iPad" | |
} | |
else {device = "iPhone"} | |
mail.setSubject("Report a Bug in Neon (\(device))") | |
present(mail, animated: true) | |
} else { | |
// show failure alert | |
} | |
} | |
@IBAction private func tipScreenButton(_ sender: Any) | |
{ | |
DispatchQueue.main.async { | |
UIImpactFeedbackGenerator().impactOccurred() | |
self.present(self.controller, animated: true, completion: nil) | |
} | |
} | |
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { | |
controller.dismiss(animated: true) | |
} | |
override func numberOfSections(in tableView: UITableView) -> Int { | |
return 3 | |
} | |
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
tableView.deselectRow(at: indexPath, animated: true) | |
generator.impactOccurred() | |
// if indexPath == [0,0] | |
// { | |
// DispatchQueue.main.async { | |
// self.present(self.controller, animated: true, completion: nil) | |
// | |
// } | |
// } | |
if indexPath == [1,0] | |
{rateApp()} | |
if indexPath == [1,1] | |
{ | |
let screenName = "neontheapp" | |
let appURL = NSURL(string: "twitter://user?screen_name=\(screenName)")! | |
let webURL = NSURL(string: "https://twitter.com/\(screenName)")! | |
let application = UIApplication.shared | |
if application.canOpenURL(appURL as URL) { | |
application.open(appURL as URL) | |
} else { | |
application.open(webURL as URL) | |
} | |
} | |
if indexPath == [1,2] | |
{ | |
sendEmail() | |
} | |
if indexPath == [1,3] | |
{ | |
performSegue(withIdentifier: "changeAppIconSegue", sender: self) | |
} | |
if indexPath == [2,0] | |
{ | |
let url = URL(string: "https://swapnanildhol16.wordpress.com")! | |
let safariViewController = SFSafariViewController(url: url) | |
self.present(safariViewController, animated: true, completion: nil) | |
} | |
if indexPath == [2,1] | |
{ | |
let userName = "instanautical" | |
let url = URL(string: "https://instagram.com/\(userName)")! | |
let appURL = URL(string: "instagram://user?username=\(userName)")! | |
let app = UIApplication.shared | |
if app.canOpenURL(url) | |
{app.open(appURL)} | |
else {app.open(url)} | |
} | |
if indexPath == [2,2] | |
{ | |
//Github | |
let url = URL(string: "https://github.com/SwapnanilDhol")! | |
let app = UIApplication.shared | |
if app.canOpenURL(url) | |
{app.open(url)} | |
else {app.open(url)} | |
} | |
if indexPath == [2,3] | |
{ | |
let url = URL(string: "https://twitter.com/SwapnanilDhol")! | |
let app = UIApplication.shared | |
if app.canOpenURL(url) | |
{app.open(url)} | |
else {app.open(url)} | |
} | |
//MARK: Debug Only | |
if indexPath == [3,0] | |
{ | |
UserDefaults.standard.set(true, forKey: "firstTime") | |
UserDefaults.standard.set(true, forKey: "randomFirstTime") | |
UINotificationFeedbackGenerator().notificationOccurred(.success) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment