-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppLogger.m
More file actions
99 lines (64 loc) · 2.2 KB
/
AppLogger.m
File metadata and controls
99 lines (64 loc) · 2.2 KB
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
98
99
//
// AppLogger.m
// TrackingFramework
//
// Created by Sylvain Malacria on 02/04/15.
// Copyright (c) 2015 Sylvain Malacria. All rights reserved.
//
#import "AppLogger.h"
@implementation AppLogger{
NSString* previousApp;
CFAbsoluteTime previousTime;
}
-(id)init{
self = [super init];
if(self){
[self registerNotificationListener];
previousApp=nil;
}
return self;
}
-(void)registerNotificationListener{
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(receiveAppChangeNotification:)
name:[NSString stringWithUTF8String:vnrAppChangeNotification]
object:nil];
}
-(void)receiveAppChangeNotification:(NSNotification *) notification{
NSDictionary* userInfo = notification.userInfo;
//retrieve app
NSString* appName =(NSString*)userInfo[@"name"] ;
//retrieve version
//NSString* version = [AppLogger getVersionOfApp:appName];
NSString* version = (NSString*)userInfo[@"version"];
// NSLog(@"version %@",version);
//retrieve language
NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0];
//retrieve time
CFAbsoluteTime time = [userInfo[@"time"] doubleValue] ;
if(previousApp!=nil){
[self writeAppChange:previousApp from:previousTime til:time];
}
previousApp = appName;
previousTime = time;
NSLog(@"changed app for %@",appName);
}
-(void)writeAppChange:(NSString*)app from:(CFAbsoluteTime)inTime til:(CFAbsoluteTime)outTime{
}
// uses applescript to retrieve version number
+(NSString*)getVersionOfApp:(NSString*)appName{
NSAppleEventDescriptor *eventDescriptor;
//NSAppleScript *script ;
NSString* source ;
// NSDictionary* errorDic ;
source = [NSString stringWithFormat:@"tell application \"%@\"\n"
@"set zeversion to version\n"
@"return zeversion\n"
@"end tell", appName];
//script = [[NSAppleScript alloc] initWithSource:source];
eventDescriptor = [[[NSAppleScript alloc] initWithSource:source] executeAndReturnError:nil];
NSString* frontUrl = [eventDescriptor stringValue];
return frontUrl;
}
@end