// // 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") GuruAnalytics.setAppFlyersId("app_flyers_id:133323") } @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_1": 200.1, "double_v_test_2": NSNumber(7.00), "double_v_test_3": 7.00, "string_v_test": "400", "long_v_test": Int64(1), "long_v_test2": Int64.max, "long_v_test3": Int64.min, "value": 0.0]) GuruAnalytics.logEvent("spend_virtual_currency", parameters: ["theme_name": "theme_bg_0029", "theme_category": "theme", "virtural_currency_name": "coins", "value": 100, "balance": 33810, "scene": "theme", "level_name": "Instance of I'm 'SettingIntDat'", ]) } @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.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.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) } }