forked from fossasia/open-event-attendee-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoreViewController.swift
62 lines (54 loc) · 2.26 KB
/
MoreViewController.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
//
// MoreViewController.swift
// FOSSAsia
//
// Created by Jurvis Tan on 11/2/16.
// Copyright © 2016 FossAsia. All rights reserved.
//
import UIKit
import SafariServices
private struct DefaultURLs {
static let fossasia2018 = "https://2018.fossasia.org/"
static let fossaisaTwitter = "https://twitter.com/fossasia"
static let fossasiaItune = "https://itunes.apple.com/us/app/fossasia/id1089164461?ls=1&mt=8"
static let fossasiaGoogleGroups = "http://groups.google.com/group/fossasia"
}
class MoreViewController: UITableViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard (indexPath as NSIndexPath).section == 0 else {
return
}
switch (indexPath as NSIndexPath).row {
case 0:
self.present(self.createSVC(DefaultURLs.fossasia2018), animated: true, completion: nil)
break
case 1:
self.present(self.createSVC(DefaultURLs.fossaisaTwitter), animated: true, completion: nil)
break
case 2:
let alertController = UIAlertController(title: Constants.appStoreAlertTitle, message: Constants.appStoreAlertMessage, preferredStyle: .alert)
let openAction = UIAlertAction(title: Constants.okTitle, style: .default, handler: { (action) -> Void in
let itunesLink = DefaultURLs.fossasiaItune
if let url = URL(string: itunesLink) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
})
let cancelAction = UIAlertAction(title: Constants.cancelTitle, style: .cancel, handler: { (action) -> Void in
// do nothing
})
alertController.addAction(openAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: { () -> Void in
})
break
case 3:
self.present(self.createSVC(DefaultURLs.fossasiaGoogleGroups), animated: true, completion: nil)
break
default:
break
}
}
func createSVC(_ urlString: String) -> SFSafariViewController {
return SFSafariViewController(url: URL(string: urlString)!)
}
}