Building MXMetricPayload
// Build payload | |
MXMetricPayload *payload = [MXMetricPayload alloc]; | |
SEL selector = @selector(initWithAppVersion:withMutipleAppVersions:withTimeStampBegin:withTimeStampEnd:); | |
NSMethodSignature *signature = [MXMetricPayload instanceMethodSignatureForSelector:selector]; | |
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; | |
[invocation setTarget:payload]; | |
[invocation setSelector:selector]; | |
NSString *appVersion = @"10"; | |
NSArray *appVersions = @[appVersion]; | |
NSDate *startDate = [NSDate date]; | |
NSDate *endDate = [NSDate date]; | |
[invocation setArgument:&appVersion atIndex:2]; | |
[invocation setArgument:&appVersions atIndex:3]; | |
[invocation setArgument:&startDate atIndex:4]; | |
[invocation setArgument:&endDate atIndex:5]; | |
[invocation invoke]; | |
// Add metrics | |
MXCPUMetric *cpuMetric = [MXCPUMetric alloc]; | |
[cpuMetric performSelector:@selector(initWithCumulativeCPUTimeMeasurement:) withObject:[NSNumber numberWithDouble:42]]; | |
[payload performSelector:@selector(setCpuMetrics:) withObject:cpuMetric]; | |
// Put payload to caches | |
NSString *path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0]; | |
path = [path stringByAppendingPathComponent:@"Caches/MetricKit/Reports"]; | |
NSError *error = nil; | |
if(![[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) { | |
NSLog(@"Failed to create directory \"%@\". Error: %@", path, error); | |
return; | |
} | |
NSString *filePath = [path stringByAppendingPathComponent:@"report"]; | |
[NSKeyedArchiver archiveRootObject:payload toFile:filePath]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Please tell how to integrate this file in any other framework?