StanwoodUITestingCore 1.0.1

StanwoodUITestingCore 1.0.1

Tal Zion 维护。



  • stanwood

StanwoodUITestingCore

Swift Version iOS 10+ MIT

目录

作者

Tal Zion [email protected]

安装

platform :ios, '10.0'

pod 'StanwoodUITestingCore', :configurations => ['Debug']

注意:请确保只在 Debug 配置中添加 StanwoodUITestingCore。

更新

$ pod update StanwoodCore

使用

导入框架

#if DEBUG
    import StanwoodUITestingCore
#endif

添加UITestingCoreListener监听器实例

#if DEBUG
    private var listener: UITestingCoreListener!
#endif

监听事件并更新Firebase实时数据库实例

#if DEBUG
listener = UITestingCoreListener()
        
// Auth anonymously
// Note: Make sure this option is enabled on Firebsae, and only runs on the Debug instance
Auth.auth().signInAnonymously { (user, error) in
            
   DispatchQueue.global(qos: .background).async {
                
     // Listening to view events
     self.listener.listen { (item) in
                    
     // Setting a Database instance
     let dataBase = Database.database()
     var ref = dataBase.reference()
     ref = ref.child("uitesting_hierarchy_ios")
                    
     // Observing previous core versions
     ref.observeSingleEvent(of: .value, with: { (snapshot) in
                        
         // Checking if the version exists
         guard let value = snapshot.value as? [String: Any],
            let data = try? JSONSerialization.data(withJSONObject: value, options: .prettyPrinted)  else {
                  let currentItems = UITestingCoreItems(versions: [item])
                  if let payload = currentItems.payload() {
                      ref.setValue(payload)
                  }
                  return
          }
                        
          // Updating the current version
          if var currentItems = try? JSONDecoder().decode(UITestingCoreItems.self, from: data) {
               currentItems.append(item)
                            
               if let payload = currentItems.payload() {
                   ref.setValue(payload)
                }
           }
        })      
      }
   }
}
#endif

开关

如果要禁用监听器,请调用

listener.shouldListen = false

许可证

StanwoodUITestingCore遵循MIT许可证。更多信息请参阅许可证文件