added iOS source code
[wl-app.git] / iOS / WolneLektury / Screens / Common / WLViewController.swift
1 //
2 //  WLViewController.swift
3 //  WolneLektury
4 //
5 //  Created by Pawel Dabrowski on 25/09/2018.
6 //  Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
7 //
8
9 import UIKit
10 import MatomoTracker
11
12 class WLViewController: UIViewController {
13
14     func name() -> String {
15         
16         return String(describing: type(of: self)).replacingOccurrences(of: "ViewController", with: "")
17     }
18     
19     func parentNames() -> [String] {
20         var namesList = [String]()
21         if let controller = self.parent as? WLViewController {
22             namesList.append(contentsOf: controller.parentNames())
23             namesList.append(name())
24         }
25         else if let controller = self.parent as? UINavigationController {
26             for vc in controller.childViewControllers{
27                 if let vc = vc as? WLViewController {
28                     namesList.append(vc.name())
29                 }
30             }
31         }
32         else {
33             namesList.append(name())
34         }
35         return namesList
36     }
37     
38     func trackScreen() {
39         
40         print("trackScreen \(parentNames())")
41         MatomoTracker.shared.track(view: parentNames())
42     }
43     
44     override func viewDidLoad() {
45         super.viewDidLoad()
46         trackScreen()
47     }
48
49     override func didReceiveMemoryWarning() {
50         super.didReceiveMemoryWarning()
51         // Dispose of any resources that can be recreated.
52     }
53     
54 }