-
-
Save deszip/a0cf877b07cc2877129e0aaef2fed1e4 to your computer and use it in GitHub Desktop.
Building MXMetricPayload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
Please tell how to integrate this file in any other framework?