evandcoleman / FakeTouch

FakeTouch is a framework that simulates iOS touch events.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FakeTouch

License: MIT

The FakeTouch framework allows you to recording / simulating the iOS touch events.

This project was created using part of the KIF project and referring to PTFakeTouch and ZSFakeTouch project.

Features

  • Simulates Touch Event.
  • Recorder / Player class for Touch Event.

Getting Started

Requirements

  • iOS 12.0+
  • Xcode 10.0+
  • Swift 4.2+

Installation

Cocoa Pods

pod "FakeTouch", :git => 'https://github.com/watanabetoshinori/FakeTouch.git', :branch => 'master'

Usage

Initialization

Start by importing the package in the file you want to use it.

import FakeTouch

Recording Touch Event

Record the touch event and make it available later.

Initializing Recorder

let recorder = TouchRecorder.shared

Controlling Recording

// Start recording
recorder.record { [weak self] (events, error) in
    if let error = error {
        print(error)
        return
    }
    
    // Keep events for playing later.
    self?.events = events
}

// Stop recording
recorder.stop()

Playing Touch Event

Play a touch event captured with the recorder.

Initializing Player

let player = TouchPlayer(events: events)

// Keeping instance
self.player = player

Controlling Playback

// Start simulation
player.play(finishPlayHandler: { [weak self] (error) in
    if let error = error {
        print(error.localizedDescription)
        return
    }
})

// Stop simulation
player.stop()

Import and Export Touch Event

Touch event supported JSON Codable protocol. You can export / import touch events.

Export

let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let jsonFileURL = documentDirectoryURL.appendingPathComponent("events.json")

do {
    let data = try JSONEncoder().encode(events)
    try data.write(to: jsonFileURL)

} catch {
    print(error)
}

Import

let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let jsonFileURL = documentDirectoryURL.appendingPathComponent("events.json")

do {
    let data = try Data(contentsOf: jsonFileURL)
    let events = try JSONDecoder().decode([TouchEvent].self, from: data)
    self.events = events

} catch {
    print(error)
}

Example App

Example App for FakeTouch. See the Example directory.

Preview1

Author

Watanabe Toshinori – toshinori_watanabe@tiny.blue

License

This project is licensed under the MIT License. See the LICENSE file for details.

This project uses some KIF source code. They are under the KIF's License.

Acknowledgments

This project refers to the code of the following projects:

About

FakeTouch is a framework that simulates iOS touch events.

License:MIT License


Languages

Language:Swift 100.0%