Skip to content

Commit d51186c

Browse files
committed
adding copy and delete recording utilities
1 parent 319f8e9 commit d51186c

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

ios/RNReactNativeReplaykit.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ - (dispatch_queue_t)methodQueue
4444
}];
4545
}
4646

47+
RCT_EXPORT_METHOD(deleteRecording:(NSString *)path callback:(RCTResponseSenderBlock)callback)
48+
{
49+
[self.screenRecordCoordinator removeRecordingWithFilePath:path];
50+
callback(@[path]);
51+
}
52+
53+
RCT_EXPORT_METHOD(copyRecording:(NSString *)path callback:(RCTResponseSenderBlock)callback)
54+
{
55+
static NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
56+
NSMutableString *randomString = [NSMutableString stringWithCapacity: 15];
57+
for (int i=0; i<15; i++) {
58+
[randomString appendFormat: @"%C", [letters characterAtIndex: arc4random() % [letters length]]];
59+
}
60+
61+
NSString *newPath = [[NSString stringWithFormat:@"%@/%@",
62+
[path stringByDeletingLastPathComponent], letters]
63+
stringByAppendingPathExtension:[path pathExtension]];
64+
65+
[self.screenRecordCoordinator copyRecordingWithFilePath:path destFileURL:newPath];
66+
NSArray *recordings = [self.screenRecordCoordinator listAllReplays];
67+
68+
callback(@[recordings, newPath]);
69+
}
70+
4771
RCT_EXPORT_METHOD(getRecordings:(RCTResponseSenderBlock)callback)
4872
{
4973
NSArray *recordings = [self.screenRecordCoordinator listAllReplays];

ios/ScreenRecord/FileUtil.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ import Foundation
5454
}
5555
}
5656
}
57+
58+
class func deleteItem(at url: URL) {
59+
do {
60+
try FileManager.default.removeItem(at: url)
61+
} catch let error as NSError {
62+
print("Error deleting file!")
63+
}
64+
}
5765

5866
class func filePath(_ fileName: String) -> String
5967
{

ios/ScreenRecord/ScreenRecordCoordinator.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ import AVKit
4646
}
4747
}
4848

49+
func removeRecording(withFilePath fileURL: String)
50+
{
51+
ReplayFileUtil.deleteItem(at: URL(fileURLWithPath: fileURL))
52+
}
53+
54+
func copyRecording(withFilePath fileURL: String, destFileURL: String)
55+
{
56+
ReplayFileUtil.copyItem(at: URL(fileURLWithPath: fileURL), to: URL(fileURLWithPath: destFileURL))
57+
}
58+
4959
func previewRecording (withFileName fileURL: String) {
5060
if UIVideoEditorController.canEditVideo(atPath: fileURL) {
5161
previewDelegateView.setCoordinator(coordinator: self)

0 commit comments

Comments
 (0)