| 
									
										
										
										
											2024-09-04 05:01:33 +00:00
										 |  |  | // | 
					
						
							|  |  |  | //  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") | 
					
						
							| 
									
										
										
										
											2025-08-08 10:12:14 +00:00
										 |  |  |         GuruAnalytics.setAppFlyersId("app_flyers_id:133323") | 
					
						
							| 
									
										
										
										
											2024-09-04 05:01:33 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     @IBAction func create(_ sender: Any) { | 
					
						
							|  |  |  |         GuruAnalytics.setScreen("home") | 
					
						
							|  |  |  |         GuruAnalytics.logEvent("crate_clk_" + String(Int(Date().timeIntervalSince1970)), | 
					
						
							|  |  |  |                                parameters: ["category": "category_\(Int.random(in: 0...100000))", | 
					
						
							| 
									
										
										
										
											2025-08-08 10:12:14 +00:00
										 |  |  |                                             "int_v_test": 2147483647, "double_v_test_1": 200.1, | 
					
						
							|  |  |  |                                             "double_v_test_2": NSNumber(7.00), | 
					
						
							|  |  |  |                                             "double_v_test_3": 7.00, | 
					
						
							| 
									
										
										
										
											2024-09-04 05:01:33 +00:00
										 |  |  |                                             "string_v_test": "400", | 
					
						
							| 
									
										
										
										
											2025-08-08 10:12:14 +00:00
										 |  |  |                                             "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'", | 
					
						
							|  |  |  |                                            ]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-04 05:01:33 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     @IBAction func deleteItem(_ sender: Any) { | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @IBAction func getLogs(_ sender: UIButton) { | 
					
						
							| 
									
										
										
										
											2024-09-23 02:53:09 +00:00
										 |  |  |         GuruAnalytics.eventsLogsDirectory({ [weak self] url in | 
					
						
							| 
									
										
										
										
											2024-09-04 05:01:33 +00:00
										 |  |  |             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) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |