Skip to content

Instantly share code, notes, and snippets.

@haxpor
Last active Dec 16, 2015
Embed
What would you like to do?
TestFlight Wrapper for C++ coder See README.md

TestFlightWrapper

Created as a C++ wrapper for TestFlight SDK v.1.2.4 with the aim to clear cut using Objective-C from C++ code.
I tested with cocos2d-x v.2.0.3 (which is adhered to cocos2d v.2.0) on iOS platform.
The test includes uploading build to TestFlight and play-through testing functionality of TestFlight.

Testing

Tested

  • setDeviceIdentifier()
  • takeOff()
  • TFLog() via log()
  • passCheckpoint()

Functions left to test

  • openFeedbackView()
  • submitFeedback()

Functions not yet implement

  • setOptions()

HOW TO

  1. Follow the instruction to integrate SDK via https://testflightapp.com/sdk/doc/1.2.4/ or more advanced via http://justatheory.com/computers/os/ios/integrate-testflight-sdk.html. I recommend the latter one.
  2. Use TestFlightWrapper class (both .mm and .h) instead of directly use from SDK. Just call some thing like the following in any place you want.

TestFlightWrapper::TestFlightWrapper::sharedWrapper()->passCheckpoint("Killed all enemies!!");

or

TestFlightWrapper::TestFlightWrapper::sharedWrapper()->log("User bypass the tutorial."); TestFlightWrapper::TestFlightWrapper::sharedWrapper()->log("Go kill %d", enemiesArray->count());

haxpor

//
// TestFlightWrapper.h
//
// Created by haxpor on 4/9/13.
//
//
#ifndef __TestFlightWrapper__
#define __TestFlightWrapper__
#include <typeinfo>
#include <string>
namespace TestFlightWrapper {
/* As SimpleAudioEngine in cocos2d-x has it, so this class should have. It makes no harm. */
class TypeInfo
{
public:
virtual long getClassTypeInfo() = 0;
};
static inline unsigned int getHashCodeByString(const char *key)
{
unsigned int len = strlen(key);
const char *end=key+len;
unsigned int hash;
for (hash = 0; key < end; key++)
{
hash *= 16777619;
hash ^= (unsigned int) (unsigned char) toupper(*key);
}
return (hash);
}
/* -- */
class TestFlightWrapper : public TypeInfo
{
public:
TestFlightWrapper();
~TestFlightWrapper();
virtual long getClassTypeInfo() {
return getHashCodeByString(typeid(TestFlightWrapper::TestFlightWrapper).name());
}
static TestFlightWrapper* sharedWrapper();
void addCustomEnvironmentInformation(const char* information, const char* key);
void takeOff(const char* applicationToken);
/* void setOptions(NSDictionary* options); */ // we don't support yet!
void passCheckpoint(const char* checkpointName);
void openFeedbackView();
void submitFeedback(const char* feedback);
void setDeviceIdentifier(const char* deviceIdentifier);
void log(const char *strFormat, ...);
// -- key of options (will be used when setOptions() function is finally supported) ---
static const char* TFOptionAttachBacktraceToFeedback_utf8String;
static const char* TFOptionDisableInAppUpdates_utf8String;
static const char* TFOptionLogToConsole_utf8String;
static const char* TFOptionLogToSTDERR_utf8String;
static const char* TFOptionReinstallCrashHandlers_utf8String;
static const char* TFOptionSendLogOnlyOnCrash_utf8String;
};
}; // end of namespace
#endif /* defined(__TestFlightWrapper__) */
//
// TestFlightWrapper.mm
//
// Created by haxpor on 4/9/13.
//
//
#include "TestFlightWrapper.h"
#include "TestFlight.h"
namespace TestFlightWrapper {
static const char* TFOptionAttachBacktraceToFeedback_utf8String = [TFOptionAttachBacktraceToFeedback UTF8String];
static const char* TFOptionDisableInAppUpdates_utf8String = [TFOptionDisableInAppUpdates UTF8String];
static const char* TFOptionLogToConsole_utf8String = [TFOptionLogToConsole UTF8String];
static const char* TFOptionLogToSTDERR_utf8String = [TFOptionLogToSTDERR UTF8String];
static const char* TFOptionReinstallCrashHandlers_utf8String = [TFOptionReinstallCrashHandlers UTF8String];
static const char* TFOptionSendLogOnlyOnCrash_utf8String = [TFOptionSendLogOnlyOnCrash UTF8String];
static TestFlightWrapper *s_testFlightWrapper;
TestFlightWrapper::TestFlightWrapper()
{
}
TestFlightWrapper::~TestFlightWrapper()
{
}
TestFlightWrapper* TestFlightWrapper::sharedWrapper()
{
if(!s_testFlightWrapper)
{
s_testFlightWrapper = new TestFlightWrapper();
}
return s_testFlightWrapper;
}
void TestFlightWrapper::addCustomEnvironmentInformation(const char *information, const char *key)
{
[TestFlight addCustomEnvironmentInformation:[NSString stringWithUTF8String:information] forKey:[NSString stringWithUTF8String:key]];
}
void TestFlightWrapper::takeOff(const char* checkpointName)
{
[TestFlight takeOff:[NSString stringWithUTF8String:checkpointName]];
}
void TestFlightWrapper::passCheckpoint(const char* checkpointName)
{
[TestFlight passCheckpoint:[NSString stringWithUTF8String:checkpointName]];
}
void TestFlightWrapper::openFeedbackView()
{
[TestFlight openFeedbackView];
}
void TestFlightWrapper::submitFeedback(const char* feedback)
{
[TestFlight submitFeedback:[NSString stringWithUTF8String:feedback]];
}
void TestFlightWrapper::setDeviceIdentifier(const char* deviceIdentifier)
{
[TestFlight setDeviceIdentifier:[NSString stringWithUTF8String:deviceIdentifier]];
}
void TestFlightWrapper::log(const char *strFormat, ...)
{
va_list ap;
va_start(ap, strFormat);
TFLog([NSString stringWithUTF8String:strFormat], ap);
va_end(ap);
}
} // end of TestFlightWrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment