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.
- Simulates Touch Event.
- Recorder / Player class for Touch Event.
- iOS 12.0+
- Xcode 10.0+
- Swift 4.2+
pod "FakeTouch", :git => 'https://github.com/watanabetoshinori/FakeTouch.git', :branch => 'master'
Start by importing the package in the file you want to use it.
import FakeTouch
Record the touch event and make it available later.
let recorder = TouchRecorder.shared
// 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()
Play a touch event captured with the recorder.
let player = TouchPlayer(events: events)
// Keeping instance
self.player = player
// Start simulation
player.play(finishPlayHandler: { [weak self] (error) in
if let error = error {
print(error.localizedDescription)
return
}
})
// Stop simulation
player.stop()
Touch event supported JSON Codable protocol. You can export / import touch events.
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)
}
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 for FakeTouch. See the Example directory.
Watanabe Toshinori – [email protected]
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.
This project refers to the code of the following projects: