-
Notifications
You must be signed in to change notification settings - Fork 0
/
LPRecorder.m
97 lines (70 loc) · 2.08 KB
/
LPRecorder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#import <UIKit/UIKit.h>
#import "LPRecorder.h"
@interface UIApplication (Recording)
-(void)_addRecorder:(id)recorder;
-(void)_removeRecorder:(id)recorder;
-(void)_playbackEvents:(NSArray*)events atPlaybackRate:(float)playbackRate messageWhenDone:(id)target withSelector:(SEL)selector;
@end
static LPRecorder *sharedRecorder = nil;
@implementation LPRecorder
@synthesize isRecording=_isRecording;
+(LPRecorder *)sharedRecorder {
if (sharedRecorder == nil) {
sharedRecorder = [[super allocWithZone:NULL] init];
}
return sharedRecorder;
}
-(id)init {
self = [super init];
eventList = [[NSMutableArray alloc] init];
return self;
}
-(void)dealloc {
[eventList release];
[super dealloc];
}
-(void)record {
[eventList removeAllObjects];
NSLog(@"Starting recording");
_isRecording = YES;
[[UIApplication sharedApplication] _addRecorder: self];
}
-(NSArray*)events {
return eventList;
}
-(void)saveToFile:(NSString*)path {
NSLog(@"Saving events to file: %@", path);
if ([eventList writeToFile: path atomically: YES]) {
NSLog(@"succeeded");
}
}
-(void)stop {
NSLog(@"Stopping recording");
_isRecording = NO;
[[UIApplication sharedApplication] _removeRecorder: self];
}
-(void)recordApplicationEvent:(NSDictionary*)event {
NSLog(@"Recorded event: %@", event);
[eventList addObject:event];
}
-(void)load:(NSArray*)events {
NSLog(@"Loading events");
[eventList setArray: events];
}
-(void)loadFromFile:(NSString*)path {
NSLog(@"Loading events from file: %@", path);
[eventList setArray: [NSMutableArray arrayWithContentsOfFile: path]];
}
-(void)playbackWithDelegate: (id)delegate doneSelector:(SEL)doneSelector {
NSLog(@"Playback");
playbackDelegate = [delegate retain];
playbackDoneSelector = doneSelector;
[[UIApplication sharedApplication] _playbackEvents: eventList atPlaybackRate: 1.0f messageWhenDone: self withSelector: @selector(playbackDone:)];
}
-(void)playbackDone:(NSDictionary *)details {
NSLog(@"Playback complete");
[playbackDelegate performSelector: playbackDoneSelector];
[playbackDelegate autorelease];
playbackDelegate=nil;
}
@end