-
Notifications
You must be signed in to change notification settings - Fork 244
/
CountlyViewData.m
48 lines (38 loc) · 1.19 KB
/
CountlyViewData.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
// CountlyViewData.m
//
// This code is provided under the MIT License.
//
// Please visit www.count.ly for more information.
#import "CountlyViewData.h"
#import "CountlyCommon.h"
@implementation CountlyViewData
- (instancetype)initWithID:(NSString *)viewID viewName:(NSString *)viewName
{
if (self = [super init])
{
self.viewID = viewID;
self.viewName = viewName;
self.viewStartTime = CountlyCommon.sharedInstance.uniqueTimestamp;
self.isAutoStoppedView = false;
self.willStartAgain = false;
}
return self;
}
- (NSInteger)duration
{
NSTimeInterval duration = NSDate.date.timeIntervalSince1970 - self.viewStartTime;
return (NSInteger)round(duration); // Rounds to the nearest integer, to fix long value converted to 0 on server side.
}
- (void)pauseView
{
if (self.viewStartTime)
{
// For safe side we have set the value to current time stamp instead of 0 when pausing the view, as setting it to 0 could result in an invalid duration value.
self.viewStartTime = CountlyCommon.sharedInstance.uniqueTimestamp;
}
}
- (void)resumeView
{
self.viewStartTime = CountlyCommon.sharedInstance.uniqueTimestamp;
}
@end