From b0dc11a1aa543167176eae5197578d61324c5c1c Mon Sep 17 00:00:00 2001 From: Masahiro Hayashi Date: Wed, 29 Apr 2015 20:55:48 +0900 Subject: [PATCH] fix: add cpp --- cpp/ReproCpp.h | 50 ++++++++++++++++++++++++++ cpp/ReproCpp.mm | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 cpp/ReproCpp.h create mode 100644 cpp/ReproCpp.mm diff --git a/cpp/ReproCpp.h b/cpp/ReproCpp.h new file mode 100644 index 0000000..d642e9f --- /dev/null +++ b/cpp/ReproCpp.h @@ -0,0 +1,50 @@ +// +// ReproCpp.h +// +// Created by jollyjoester_pro on 10/31/14. +// Copyright (c) 2014 Repro Inc. All rights reserved. +// + +#ifndef __REPRO_CPP_H__ +#define __REPRO_CPP_H__ + +class ReproCpp { + +public: + + // Setup + static void setup(const char* token); + + // Log Level + static void setLogLevel(const char* logLevel); + + // Screen Recording + static void startRecording(); + static void stopRecording(); + static void pauseRecording(); + static void resumeRecording(); + + // UIView Masking + static void maskWithRect(float x, float y, float width, float height, const char* key); + static void unmaskWithRect(const char* key); + + // User ID + static void setUserID(const char* userId); + + // Track Events + static void track(const char*eventName); + static void trackWithProperties(const char* eventName, const char* jsonDictionary); + + // Crash Reporting + static void enableCrashReporting(); + + // Survey + static void survey(); + + // Usablity Testing + static void enableUsabilityTesting(); + +}; + +#endif + diff --git a/cpp/ReproCpp.mm b/cpp/ReproCpp.mm new file mode 100644 index 0000000..4615a48 --- /dev/null +++ b/cpp/ReproCpp.mm @@ -0,0 +1,96 @@ +// +// ReproCpp.mm +// +// Created by jollyjoester_pro on 10/31/14. +// Copyright (c) 2014 Repro Inc. All rights reserved. +// + +#include "ReproCpp.h" +#import + +static NSString* convertCStringToNSString(const char* string) { + if (string) { + return [NSString stringWithUTF8String:string]; + } else { + return @""; + } +} + +static NSDictionary* convertCStringJSONToNSDictionary(const char* string) { + if (string) { + NSString* json = convertCStringToNSString(string); + NSData* data = [json dataUsingEncoding:NSUTF8StringEncoding]; + return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; + } else { + return nil; + } +} + +void ReproCpp::setup(const char* token) { + [Repro setup:convertCStringToNSString(token)]; +} + +void ReproCpp::setLogLevel(const char* logLevel) { + if ([convertCStringToNSString(logLevel) isEqualToString:@"Debug"]) { + [Repro setLogLevel:RPRLogLevelDebug]; + } else if ([convertCStringToNSString(logLevel) isEqualToString:@"Info"]) { + [Repro setLogLevel:RPRLogLevelInfo]; + } else if ([convertCStringToNSString(logLevel) isEqualToString:@"Warn"]) { + [Repro setLogLevel:RPRLogLevelWarn]; + } else if ([convertCStringToNSString(logLevel) isEqualToString:@"Error"]) { + [Repro setLogLevel:RPRLogLevelError]; + } else if ([convertCStringToNSString(logLevel) isEqualToString:@"None"]) { + [Repro setLogLevel:RPRLogLevelNone]; + } +} + +void ReproCpp::startRecording() { + [Repro startRecording]; +} + +void ReproCpp::stopRecording() { + [Repro stopRecording]; +} + +void ReproCpp::pauseRecording() { + [Repro pauseRecording]; +} + +void ReproCpp::resumeRecording() { + [Repro resumeRecording]; +} + +void ReproCpp::maskWithRect(float x, float y, float width, float height, const char* key) { + [Repro maskWithRect:CGRectMake(x,y,width,height) key:convertCStringToNSString(key)]; +} + +void ReproCpp::unmaskWithRect(const char* key) { + [Repro unmaskForKey:convertCStringToNSString(key)]; +} + +void ReproCpp::setUserID(const char* userId) { + [Repro setUserID:convertCStringToNSString(userId)]; +} + +void ReproCpp::track(const char* eventName) { + [Repro track:convertCStringToNSString(eventName) properties:nil]; +} + +void ReproCpp::trackWithProperties(const char* eventName, const char* jsonDictionary) { + [Repro track:convertCStringToNSString(eventName) properties:convertCStringJSONToNSDictionary(jsonDictionary)]; +} + +void ReproCpp::enableCrashReporting() { + [Repro enableCrashReporting]; +} + +// Survey +void ReproCpp::survey() { + NSError *error = nil; + [Repro survey:&error]; +} + +// Usablity Testing +void ReproCpp::enableUsabilityTesting() { + [Repro enableUsabilityTesting]; +}