113 lines
4.0 KiB
Swift
113 lines
4.0 KiB
Swift
//
|
|
// ViewController.swift
|
|
// GuruAnalytics_iOS
|
|
//
|
|
// Created by mayue on 11/07/2022.
|
|
// Copyright (c) 2022 mayue. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import GuruAnalyticsLib
|
|
import MessageUI
|
|
import RxSwift
|
|
|
|
class ViewController: UIViewController {
|
|
|
|
private var timer1: Disposable?
|
|
private var timer2: Disposable?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
// Do any additional setup after loading the view, typically from a nib.
|
|
}
|
|
|
|
@IBAction func setFirebaseId(_ sender: Any) {
|
|
GuruAnalytics.setFirebaseId("2312:3XSFA0211231")
|
|
}
|
|
|
|
@IBAction func create(_ sender: Any) {
|
|
GuruAnalytics.setScreen("home")
|
|
GuruAnalytics.logEvent("crate_clk_" + String(Int(Date().timeIntervalSince1970)),
|
|
parameters: ["category": "category_\(Int.random(in: 0...100000))",
|
|
"int_v_test": 2147483647, "double_v_test": 200.1,
|
|
"string_v_test": "400",
|
|
"long_v_test": Int64(1)])
|
|
}
|
|
|
|
@IBAction func deleteItem(_ sender: Any) {
|
|
|
|
}
|
|
|
|
@IBAction func getLogs(_ sender: UIButton) {
|
|
GuruAnalytics.eventsLogsDirectory({ [weak self] url in
|
|
guard let `self` = self, let url = url else { return }
|
|
|
|
if MFMailComposeViewController.canSendMail() {
|
|
let controller = MFMailComposeViewController()
|
|
|
|
do {
|
|
let data = try Data(contentsOf: url)
|
|
controller.addAttachmentData(data, mimeType: "application/zip", fileName: url.lastPathComponent)
|
|
} catch {
|
|
NSLog("\(error)")
|
|
}
|
|
|
|
controller.mailComposeDelegate = self
|
|
self.present(controller, animated: true, completion: nil)
|
|
}
|
|
|
|
})
|
|
}
|
|
|
|
@IBAction func startTimer(_ sender: Any) {
|
|
timer1 = Observable<Int>.interval(.milliseconds(10), scheduler: SerialDispatchQueueScheduler(qos: .default))
|
|
.subscribe(onNext: { int in
|
|
if int % 2 == 0 {
|
|
GuruAnalytics.setUserProperty("\(int)", forName: "SerialDispatchQueueScheduler_interval_2")
|
|
}
|
|
GuruAnalytics.logEvent("SerialDispatchQueueScheduler_interval", parameters: ["value": int])
|
|
if int % 3 == 0 {
|
|
GuruAnalytics.setUserProperty("\(int)", forName: "SerialDispatchQueueScheduler_interval_3")
|
|
}
|
|
})
|
|
|
|
timer2 = Observable<Int>.interval(.milliseconds(20), scheduler: MainScheduler.instance)
|
|
.subscribe(onNext: { int in
|
|
if int % 2 == 0 {
|
|
GuruAnalytics.setUserProperty("\(int)", forName: "MainScheduler_interval")
|
|
}
|
|
GuruAnalytics.logEvent("MainScheduler_interval", parameters: ["value": int])
|
|
if int % 3 == 0 {
|
|
GuruAnalytics.setUserProperty("\(int)", forName: "MainScheduler_interval")
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
@IBAction func stopTimer(_ sender: Any) {
|
|
timer1?.dispose()
|
|
timer1 = nil
|
|
timer2?.dispose()
|
|
timer2 = nil
|
|
}
|
|
|
|
@IBAction func onSliderAction(_ sender: UISlider) {
|
|
UIScreen.main.brightness = CGFloat(sender.value);
|
|
}
|
|
@IBAction func onEnableUploadSwitcher(_ sender: UISwitch) {
|
|
GuruAnalytics.setEnableUpload(isOn: sender.isOn)
|
|
}
|
|
|
|
override func didReceiveMemoryWarning() {
|
|
super.didReceiveMemoryWarning()
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
}
|
|
|
|
extension ViewController: MFMailComposeViewControllerDelegate {
|
|
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
|
controller.presentingViewController?.dismiss(animated: true, completion: nil)
|
|
}
|
|
}
|