From 3ce52e56aa7369cd8b987378b1b0d7afced278ee Mon Sep 17 00:00:00 2001 From: zhangbin Date: Fri, 10 May 2013 13:54:11 +0800 Subject: [PATCH] Refactor the framework of plugin on iOS. --- .../flurry/platform/ios/AnalyticsFlurry.mm | 125 +++----- .../flurry/platform/ios/FlurryWrapper.h | 57 ++++ .../flurry/platform/ios/FlurryWrapper.m | 129 ++++++++ .../PluginFlurry.xcodeproj/project.pbxproj | 16 +- .../umeng/platform/ios/AnalyticsUmeng.mm | 284 +++++++++++------- .../plugins/umeng/platform/ios/UmengWrapper.h | 61 ++++ .../plugins/umeng/platform/ios/UmengWrapper.m | 170 +++++++++++ .../PluginUmeng.xcodeproj/project.pbxproj | 16 +- plugin/protocols/platform/ios/InterfaceAds.h | 36 +++ .../platform/ios/InterfaceAnalytics.h | 41 +++ plugin/protocols/platform/ios/InterfaceIAP.h | 34 +++ .../protocols/platform/ios/InterfaceSocial.h | 29 ++ .../protocols/platform/ios/PluginUtilsIOS.h | 61 ++++ .../protocols/platform/ios/PluginUtilsIOS.mm | 174 +++++++++++ plugin/protocols/platform/ios/ProtocolAds.cpp | 66 ---- plugin/protocols/platform/ios/ProtocolAds.mm | 91 ++++++ .../platform/ios/ProtocolAnalytics.cpp | 108 ------- .../platform/ios/ProtocolAnalytics.mm | 186 ++++++++++++ plugin/protocols/platform/ios/ProtocolIAP.cpp | 54 ---- plugin/protocols/platform/ios/ProtocolIAP.mm | 80 +++++ .../PluginProtocol.xcodeproj/project.pbxproj | 42 ++- .../HelloAnalytics/Classes/AppDelegate.cpp | 4 + .../HelloAnalytics.xcodeproj/project.pbxproj | 2 + 23 files changed, 1423 insertions(+), 443 deletions(-) create mode 100644 plugin/plugins/flurry/platform/ios/FlurryWrapper.h create mode 100644 plugin/plugins/flurry/platform/ios/FlurryWrapper.m create mode 100644 plugin/plugins/umeng/platform/ios/UmengWrapper.h create mode 100644 plugin/plugins/umeng/platform/ios/UmengWrapper.m create mode 100644 plugin/protocols/platform/ios/InterfaceAds.h create mode 100644 plugin/protocols/platform/ios/InterfaceAnalytics.h create mode 100644 plugin/protocols/platform/ios/InterfaceIAP.h create mode 100644 plugin/protocols/platform/ios/InterfaceSocial.h create mode 100644 plugin/protocols/platform/ios/PluginUtilsIOS.h create mode 100644 plugin/protocols/platform/ios/PluginUtilsIOS.mm delete mode 100644 plugin/protocols/platform/ios/ProtocolAds.cpp create mode 100644 plugin/protocols/platform/ios/ProtocolAds.mm delete mode 100644 plugin/protocols/platform/ios/ProtocolAnalytics.cpp create mode 100644 plugin/protocols/platform/ios/ProtocolAnalytics.mm delete mode 100644 plugin/protocols/platform/ios/ProtocolIAP.cpp create mode 100644 plugin/protocols/platform/ios/ProtocolIAP.mm diff --git a/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm b/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm index 943586e5ee..b9fbdf7ad8 100644 --- a/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm +++ b/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm @@ -23,6 +23,7 @@ THE SOFTWARE. ****************************************************************************/ #include "AnalyticsFlurry.h" #include "Flurry.h" +#include "PluginUtilsIOS.h" namespace cocos2d { namespace plugin { @@ -52,19 +53,14 @@ AnalyticsFlurry::~AnalyticsFlurry() bool AnalyticsFlurry::init() { - return true; + return PluginUtilsIOS::initOCPlugin(this, "FlurryWrapper"); } /** override methods of base class */ /** Start a new session. */ void AnalyticsFlurry::startSession(const char* appKey) { - if (NULL == appKey || strlen(appKey) == 0) { - FlurryLogD("appkey is invalid!"); - return; - } - NSString* pKey = [NSString stringWithUTF8String:appKey]; - [Flurry startSession:pKey]; + ProtocolAnalytics::startSession(appKey); } /** Stop a session. @@ -72,83 +68,43 @@ void AnalyticsFlurry::startSession(const char* appKey) */ void AnalyticsFlurry::stopSession() { + ProtocolAnalytics::stopSession(); } /** Set whether needs to output logs to console.*/ void AnalyticsFlurry::setDebugMode(bool debug) { s_bDebugable = debug; - [Flurry setDebugLogEnabled:debug]; + ProtocolAnalytics::setDebugMode(debug); } /** Set the timeout for expiring a session. */ void AnalyticsFlurry::setSessionContinueMillis(long millis) { - int seconds = (int)(millis / 1000); - [Flurry setSessionContinueSeconds:seconds]; + ProtocolAnalytics::setSessionContinueMillis(millis); } /** log an error */ void AnalyticsFlurry::logError(const char* errorId, const char* message) { - if (NULL == errorId || strlen(errorId) == 0) { - FlurryLogD("errorId is invalid!"); - return; - } - NSString* pId = [NSString stringWithUTF8String:errorId]; - NSString* msg = nil; - if (NULL == message) { - msg = @""; - } else { - msg = [NSString stringWithUTF8String:message]; - } - [Flurry logError:pId message:msg exception:nil]; + ProtocolAnalytics::logError(errorId, message); } /** log an event. */ void AnalyticsFlurry::logEvent(const char* eventId, LogEventParamMap* paramMap) { - if (NULL == eventId || strlen(eventId) == 0) { - FlurryLogD("eventId is invalid!"); - return; - } - - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == paramMap) { - [Flurry logEvent:pId]; - } else { - NSMutableDictionary* dict = [NSMutableDictionary dictionary]; - LogEventParamMap::iterator it; - for (it = paramMap->begin(); it != paramMap->end(); it++) { - std::string key = it->first; - std::string value = it->second; - NSString* pKey = [NSString stringWithUTF8String:key.c_str()]; - NSString* pValue = [NSString stringWithUTF8String:value.c_str()]; - [dict setObject:pValue forKey:pKey]; - } - [Flurry logEvent:pId withParameters:dict]; - } + ProtocolAnalytics::logEvent(eventId, paramMap); } void AnalyticsFlurry::logTimedEventBegin(const char* eventId) { - if (NULL == eventId || strlen(eventId) == 0) { - FlurryLogD("eventId is invalid!"); - return; - } - NSString* pId = [NSString stringWithUTF8String:eventId]; - [Flurry logEvent:pId timed:YES]; + ProtocolAnalytics::logTimedEventBegin(eventId); } /** end a timed event */ void AnalyticsFlurry::logTimedEventEnd(const char* eventId) { - if (NULL == eventId || strlen(eventId) == 0) { - FlurryLogD("eventId is invalid!"); - return; - } - NSString* pId = [NSString stringWithUTF8String:eventId]; - [Flurry endTimedEvent:pId withParameters:nil]; + ProtocolAnalytics::logTimedEventEnd(eventId); } /** Whether to catch uncaught exceptions to server. @@ -156,17 +112,18 @@ void AnalyticsFlurry::logTimedEventEnd(const char* eventId) */ void AnalyticsFlurry::setCaptureUncaughtException(bool enabled) { + ProtocolAnalytics::setCaptureUncaughtException(enabled); } const char* AnalyticsFlurry::getSDKVersion() { - NSString* ver = [Flurry getFlurryAgentVersion]; - return [ver UTF8String]; + return ProtocolAnalytics::getSDKVersion(); } void AnalyticsFlurry::setAge(int age) { - [Flurry setAge:age]; + NSNumber* numAge = [NSNumber numberWithInt:age]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "setAge:", numAge); } void AnalyticsFlurry::setGender(Gender gender) @@ -175,7 +132,7 @@ void AnalyticsFlurry::setGender(Gender gender) if (gender == FEMALE) { ret = @"f"; } - [Flurry setGender:ret]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "setGender:", ret); } void AnalyticsFlurry::setUserId(const char* userId) @@ -185,18 +142,18 @@ void AnalyticsFlurry::setUserId(const char* userId) return; } NSString* pUserID = [NSString stringWithUTF8String:userId]; - [Flurry setUserID:pUserID]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "setUserId:", pUserID); } void AnalyticsFlurry::logPageView() { - [Flurry logPageView]; + PluginUtilsIOS::callOCFunctionWithName(this, "logPageView"); } - + void AnalyticsFlurry::setVersionName(const char* versionName) { NSString* pVer = [NSString stringWithUTF8String:versionName]; - [Flurry setAppVersion:pVer]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "setVersionName:", pVer); } /** @@ -204,7 +161,7 @@ void AnalyticsFlurry::setVersionName(const char* versionName) */ void AnalyticsFlurry::setUseHttps(bool useHttps) { - + FlurryLogD("setUseHttps in flurry not available on iOS"); } /** @@ -212,7 +169,7 @@ void AnalyticsFlurry::setUseHttps(bool useHttps) */ void AnalyticsFlurry::setReportLocation(bool enabled) { - + FlurryLogD("setReportLocation in flurry not available on iOS"); } void AnalyticsFlurry::logTimedEventBegin(const char* eventId, LogEventParamMap* paramMap) @@ -221,21 +178,20 @@ void AnalyticsFlurry::logTimedEventBegin(const char* eventId, LogEventParamMap* FlurryLogD("eventId is invalid!"); return; } - + NSString* pId = [NSString stringWithUTF8String:eventId]; if (NULL == paramMap) { - [Flurry logEvent:pId timed:YES]; + this->logTimedEventBegin(eventId); } else { - NSMutableDictionary* dict = [NSMutableDictionary dictionary]; - LogEventParamMap::iterator it; - for (it = paramMap->begin(); it != paramMap->end(); it++) { - std::string key = it->first; - std::string value = it->second; - NSString* pKey = [NSString stringWithUTF8String:key.c_str()]; - NSString* pValue = [NSString stringWithUTF8String:value.c_str()]; - [dict setObject:pValue forKey:pKey]; + NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"logTimedEventBegin:withParam:"); + if ([pOCObj respondsToSelector:selector]) { + [pOCObj performSelector:selector withObject:pId withObject:dict]; + } } - [Flurry logEvent:pId withParameters:dict timed:YES]; } } @@ -248,18 +204,17 @@ void AnalyticsFlurry::logTimedEventEnd(const char* eventId, LogEventParamMap* pa NSString* pId = [NSString stringWithUTF8String:eventId]; if (NULL == paramMap) { - [Flurry endTimedEvent:pId withParameters:nil]; + this->logTimedEventEnd(eventId); } else { - NSMutableDictionary* dict = [NSMutableDictionary dictionary]; - LogEventParamMap::iterator it; - for (it = paramMap->begin(); it != paramMap->end(); it++) { - std::string key = it->first; - std::string value = it->second; - NSString* pKey = [NSString stringWithUTF8String:key.c_str()]; - NSString* pValue = [NSString stringWithUTF8String:value.c_str()]; - [dict setObject:pValue forKey:pKey]; + NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"logTimedEventEnd:withParam:"); + if ([pOCObj respondsToSelector:selector]) { + [pOCObj performSelector:selector withObject:pId withObject:dict]; + } } - [Flurry endTimedEvent:pId withParameters:dict]; } } diff --git a/plugin/plugins/flurry/platform/ios/FlurryWrapper.h b/plugin/plugins/flurry/platform/ios/FlurryWrapper.h new file mode 100644 index 0000000000..3a9da52a6f --- /dev/null +++ b/plugin/plugins/flurry/platform/ios/FlurryWrapper.h @@ -0,0 +1,57 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#import "InterfaceAnalytics.h" + +@interface FlurryWrapper : NSObject +{ + +} + +/** + interfaces of protocol : InterfaceAnalytics + */ +- (void) startSession: (NSString*) appKey; +- (void) stopSession; +- (void) setSessionContinueMillis: (NSNumber*) millis; +- (void) setCaptureUncaughtException: (NSNumber*) isEnabled; +- (void) setDebugMode: (NSNumber*) isDebugMode; +- (void) logError: (NSString*) errorId withMsg:(NSString*) message; +- (void) logEvent: (NSString*) eventId; +- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; +- (void) logTimedEventBegin: (NSString*) eventId; +- (void) logTimedEventEnd: (NSString*) eventId; +- (NSString*) getSDKVersion; + +/** + interfaces of flurry SDK + */ +- (void) setAge: (NSNumber*) age; +- (void) setGender: (NSString*) gender; +- (void) setUserId: (NSString*) userId; +- (void) logPageView; +- (void) setVersionName: (NSString*) versionName; +- (void) logTimedEventBegin: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; +- (void) logTimedEventEnd: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; + +@end diff --git a/plugin/plugins/flurry/platform/ios/FlurryWrapper.m b/plugin/plugins/flurry/platform/ios/FlurryWrapper.m new file mode 100644 index 0000000000..14ba8bda1b --- /dev/null +++ b/plugin/plugins/flurry/platform/ios/FlurryWrapper.m @@ -0,0 +1,129 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#import "FlurryWrapper.h" +#import "Flurry.h" + +@implementation FlurryWrapper + +- (void) startSession: (NSString*) appKey +{ + [Flurry startSession:appKey]; +} + +- (void) stopSession +{ + NSLog(@"stopSession in flurry not available on iOS"); +} + +- (void) setSessionContinueMillis: (NSNumber*) millis +{ + long lMillis = [millis longValue]; + int seconds = (int)(lMillis / 1000); + [Flurry setSessionContinueSeconds:seconds]; +} + +- (void) setCaptureUncaughtException: (NSNumber*) isEnabled +{ + NSLog(@"setCaptureUncaughtException in flurry not available on iOS"); +} + +- (void) setDebugMode: (NSNumber*) isDebugMode +{ + BOOL bDebug = [isDebugMode boolValue]; + [Flurry setDebugLogEnabled:bDebug]; +} + +- (void) logError: (NSString*) errorId withMsg:(NSString*) message +{ + NSString* msg = nil; + if (nil == message) { + msg = @""; + } else { + msg = message; + } + [Flurry logError:errorId message:msg exception:nil]; +} + +- (void) logEvent: (NSString*) eventId +{ + [Flurry logEvent:eventId]; +} + +- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap +{ + [Flurry logEvent:eventId withParameters:paramMap]; +} + +- (void) logTimedEventBegin: (NSString*) eventId +{ + [Flurry logEvent:eventId timed:YES]; +} + +- (void) logTimedEventEnd: (NSString*) eventId +{ + [Flurry endTimedEvent:eventId withParameters:nil]; +} + +- (NSString*) getSDKVersion +{ + return [Flurry getFlurryAgentVersion]; +} + +- (void) setAge: (NSNumber*) age +{ + int nAge = [age integerValue]; + [Flurry setAge:nAge]; +} + +- (void) setGender: (NSString*) gender +{ + [Flurry setGender:gender]; +} + +- (void) setUserId: (NSString*) userId +{ + [Flurry setUserID:userId]; +} + +- (void) logPageView +{ + [Flurry logPageView]; +} + +- (void) setVersionName: (NSString*) versionName +{ + [Flurry setAppVersion:versionName]; +} + +- (void) logTimedEventBegin: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap +{ + [Flurry logEvent:eventId withParameters:paramMap timed:YES]; +} + +- (void) logTimedEventEnd: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap +{ + [Flurry endTimedEvent:eventId withParameters:paramMap]; +} + +@end diff --git a/plugin/plugins/flurry/proj.ios/PluginFlurry.xcodeproj/project.pbxproj b/plugin/plugins/flurry/proj.ios/PluginFlurry.xcodeproj/project.pbxproj index 7663fcbda0..eb8e0bdb3b 100644 --- a/plugin/plugins/flurry/proj.ios/PluginFlurry.xcodeproj/project.pbxproj +++ b/plugin/plugins/flurry/proj.ios/PluginFlurry.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ FA09A376168AFD41008C1C7B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA09A375168AFD41008C1C7B /* Foundation.framework */; }; FA09A394168B00D4008C1C7B /* AnalyticsFlurry.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA09A393168B00D4008C1C7B /* AnalyticsFlurry.mm */; }; FA866509168BE0980073E055 /* libFlurry.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FA866508168BE0980073E055 /* libFlurry.a */; }; + FA8CC2241739EFF200464206 /* FlurryWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC2231739EFF200464206 /* FlurryWrapper.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -32,6 +33,8 @@ FA866507168BE0980073E055 /* Flurry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Flurry.h; sourceTree = ""; }; FA866508168BE0980073E055 /* libFlurry.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libFlurry.a; sourceTree = ""; }; FA86650E168BE22D0073E055 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; + FA8CC2221739EFF200464206 /* FlurryWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlurryWrapper.h; sourceTree = ""; }; + FA8CC2231739EFF200464206 /* FlurryWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlurryWrapper.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -86,6 +89,8 @@ FA09A392168AFD96008C1C7B /* ios */ = { isa = PBXGroup; children = ( + FA8CC2221739EFF200464206 /* FlurryWrapper.h */, + FA8CC2231739EFF200464206 /* FlurryWrapper.m */, FA866507168BE0980073E055 /* Flurry.h */, FA866508168BE0980073E055 /* libFlurry.a */, FA09A393168B00D4008C1C7B /* AnalyticsFlurry.mm */, @@ -146,6 +151,7 @@ buildActionMask = 2147483647; files = ( FA09A394168B00D4008C1C7B /* AnalyticsFlurry.mm in Sources */, + FA8CC2241739EFF200464206 /* FlurryWrapper.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -202,7 +208,10 @@ DSTROOT = /tmp/libPluginFlurry.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PluginFlurry-Prefix.pch"; - HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../protocols/include"; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/../../../protocols/include", + "$(SRCROOT)/../../../protocols/platform/ios", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/../platform/ios\"", @@ -219,7 +228,10 @@ DSTROOT = /tmp/libPluginFlurry.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PluginFlurry-Prefix.pch"; - HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../protocols/include"; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/../../../protocols/include", + "$(SRCROOT)/../../../protocols/platform/ios", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/../platform/ios\"", diff --git a/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm b/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm index 677e27c229..e4cd9d3ba4 100644 --- a/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm +++ b/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm @@ -23,6 +23,7 @@ THE SOFTWARE. ****************************************************************************/ #include "AnalyticsUmeng.h" #include "MobClick.h" +#include "PluginUtilsIOS.h" namespace cocos2d { namespace plugin { @@ -51,119 +52,96 @@ AnalyticsUmeng::~AnalyticsUmeng() bool AnalyticsUmeng::init() { - return true; + return PluginUtilsIOS::initOCPlugin(this, "UmengWrapper"); } /** Start a new session. */ void AnalyticsUmeng::startSession(const char* appKey) { - if (NULL == appKey || strlen(appKey) == 0) { - UmengLogD("appkey is invalid!"); - return; - } - NSString* pKey = [NSString stringWithUTF8String:appKey]; - [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"]; - [MobClick startWithAppkey:pKey]; + ProtocolAnalytics::startSession(appKey); } /** Stop a session. only worked on android */ void AnalyticsUmeng::stopSession() { + ProtocolAnalytics::stopSession(); } /** Set whether needs to output logs to console.*/ void AnalyticsUmeng::setDebugMode(bool debug) { s_bDebugable = debug; - [MobClick setLogEnabled:debug]; + ProtocolAnalytics::setDebugMode(debug); } /** Set the timeout for expiring a session. */ void AnalyticsUmeng::setSessionContinueMillis(long millis) { - + ProtocolAnalytics::setSessionContinueMillis(millis); } /** log an error */ void AnalyticsUmeng::logError(const char* errorId, const char* message) { - + ProtocolAnalytics::logError(errorId, message); } /** log an event. */ void AnalyticsUmeng::logEvent(const char* eventId, LogEventParamMap* paramMap) { - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid!"); - return; - } - - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == paramMap) { - [MobClick event:pId]; - } else { - NSMutableDictionary* dict = [NSMutableDictionary dictionary]; - LogEventParamMap::iterator it; - for (it = paramMap->begin(); it != paramMap->end(); it++) { - std::string key = it->first; - std::string value = it->second; - NSString* pKey = [NSString stringWithUTF8String:key.c_str()]; - NSString* pValue = [NSString stringWithUTF8String:value.c_str()]; - [dict setObject:pValue forKey:pKey]; - } - [MobClick event:pId attributes:dict]; - } + ProtocolAnalytics::logEvent(eventId, paramMap); } /** begin to log a timed event */ void AnalyticsUmeng::logTimedEventBegin(const char* eventId) { - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid!"); - return; - } - - NSString* pEvent = [NSString stringWithUTF8String:eventId]; - [MobClick beginEvent:pEvent]; + ProtocolAnalytics::logTimedEventBegin(eventId); } /** end a timed event */ void AnalyticsUmeng::logTimedEventEnd(const char* eventId) { - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid!"); - return; - } - - NSString* pEvent = [NSString stringWithUTF8String:eventId]; - [MobClick endEvent:pEvent]; + ProtocolAnalytics::logTimedEventEnd(eventId); } /** Whether to catch uncaught exceptions to server.*/ void AnalyticsUmeng::setCaptureUncaughtException(bool enabled) { - [MobClick setCrashReportEnabled:enabled]; + ProtocolAnalytics::setCaptureUncaughtException(enabled); } const char* AnalyticsUmeng::getSDKVersion() { - return "UMeng no version info"; + return ProtocolAnalytics::getSDKVersion(); } void AnalyticsUmeng::updateOnlineConfig() { - [MobClick updateOnlineConfig]; + PluginUtilsIOS::callOCFunctionWithName(this, "updateOnlineConfig"); } const char* AnalyticsUmeng::getConfigParams(const char* key) { + NSString* strKey = [NSString stringWithUTF8String:key]; + return [[MobClick getConfigParams:strKey] UTF8String]; + + if (NULL == key || strlen(key) == 0) { UmengLogD("The key is invalid!"); return ""; } NSString* pKey = [NSString stringWithUTF8String:key]; - NSString* ret = [MobClick getConfigParams:pKey]; + NSString* ret = nil; + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"getConfigParams:"); + if ([pOCObj respondsToSelector:selector]) { + ret = [pOCObj performSelector:selector withObject:pKey]; + } + } + const char* pRet = (nil == ret) ? NULL : [ret UTF8String]; return pRet; } @@ -181,12 +159,15 @@ void AnalyticsUmeng::logEventWithLabel(const char* eventId, const char* label) return; } - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == label) { - [MobClick event:pId]; - } else { - NSString* pLabel = [NSString stringWithUTF8String:label]; - [MobClick event:pId label:pLabel]; + NSString* strEvent = [NSString stringWithUTF8String:eventId]; + NSString* strLabel = [NSString stringWithUTF8String:label]; + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"logEvent:withLabel:"); + if ([pOCObj respondsToSelector:selector]) { + [pOCObj performSelector:selector withObject:strEvent withObject:strLabel]; + } } } @@ -197,13 +178,33 @@ void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, co return; } - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == label) { - [MobClick event:pId durations:(int)duration]; - } else { - NSString* pLabel = [NSString stringWithUTF8String:label]; - [MobClick event:pId label:pLabel durations:(int)duration]; - } + do { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + + if (! pData) break; + + id pOCObj = pData->obj; + NSString* className = [NSString stringWithUTF8String:pData->className.c_str()]; + SEL selector = NSSelectorFromString(@"logEvent:withDuration:withLabel:"); + + if (! [pOCObj respondsToSelector:selector]) { + break; + } + + NSString* strEventId = [NSString stringWithUTF8String:eventId]; + NSString* strLabel = [NSString stringWithUTF8String:label]; + NSNumber* numDur = [NSNumber numberWithLong:duration]; + + NSMethodSignature *sig= [NSClassFromString(className) instanceMethodSignatureForSelector:selector]; + NSInvocation *invocation=[NSInvocation invocationWithMethodSignature:sig]; + [invocation setTarget:pOCObj]; + [invocation setSelector:selector]; + [invocation setArgument:&strEventId atIndex:2]; + [invocation setArgument:&numDur atIndex:3]; + [invocation setArgument:&strLabel atIndex:4]; + [invocation retainArguments]; + [invocation invoke]; + } while (0); } void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, LogEventParamMap* paramMap) @@ -213,21 +214,33 @@ void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, Lo return; } - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == paramMap) { - [MobClick event:pId durations:(int)duration]; - } else { - NSMutableDictionary* dict = [NSMutableDictionary dictionary]; - LogEventParamMap::iterator it; - for (it = paramMap->begin(); it != paramMap->end(); it++) { - std::string key = it->first; - std::string value = it->second; - NSString* pKey = [NSString stringWithUTF8String:key.c_str()]; - NSString* pValue = [NSString stringWithUTF8String:value.c_str()]; - [dict setObject:pValue forKey:pKey]; + do { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + + if (! pData) break; + + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"logEvent:withDuration:withParam:"); + + if (! [pOCObj respondsToSelector:selector]) { + break; } - [MobClick event:pId attributes:dict durations:(int)duration]; - } + + NSString* strEventId = [NSString stringWithUTF8String:eventId]; + NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); + NSNumber* numDur = [NSNumber numberWithLong:duration]; + + NSMethodSignature *sig = [[pOCObj class] instanceMethodSignatureForSelector:selector]; + NSInvocation *invocation =[NSInvocation invocationWithMethodSignature:sig]; + + [invocation setSelector:selector]; + [invocation setTarget:pOCObj]; + [invocation setArgument:&strEventId atIndex:2]; + [invocation setArgument:&numDur atIndex:3]; + [invocation setArgument:&dict atIndex:4]; + [invocation retainArguments]; + [invocation invoke]; + } while (0); } void AnalyticsUmeng::logTimedEventWithLabelBegin(const char* eventId, const char* label) @@ -237,12 +250,15 @@ void AnalyticsUmeng::logTimedEventWithLabelBegin(const char* eventId, const char return; } - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == label) { - [MobClick beginEvent:pId]; - } else { - NSString* pLabel = [NSString stringWithUTF8String:label]; - [MobClick beginEvent:pId label:pLabel]; + NSString* strEvent = [NSString stringWithUTF8String:eventId]; + NSString* strLabel = [NSString stringWithUTF8String:label]; + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"logTimedEventBegin:withLabel:"); + if ([pOCObj respondsToSelector:selector]) { + [pOCObj performSelector:selector withObject:strEvent withObject:strLabel]; + } } } @@ -253,12 +269,15 @@ void AnalyticsUmeng::logTimedEventWithLabelEnd(const char* eventId, const char* return; } - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == label) { - [MobClick endEvent:pId]; - } else { - NSString* pLabel = [NSString stringWithUTF8String:label]; - [MobClick endEvent:pId label:pLabel]; + NSString* strEvent = [NSString stringWithUTF8String:eventId]; + NSString* strLabel = [NSString stringWithUTF8String:label]; + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"logTimedEventEnd:withLabel:"); + if ([pOCObj respondsToSelector:selector]) { + [pOCObj performSelector:selector withObject:strEvent withObject:strLabel]; + } } } @@ -269,22 +288,33 @@ void AnalyticsUmeng::logTimedKVEventBegin(const char* eventId, const char* label return; } - NSString* pId = [NSString stringWithUTF8String:eventId]; - NSString* primary = [NSString stringWithUTF8String:label]; - if (NULL == paramMap || NULL == label) { - [MobClick beginEvent:pId]; - } else { - NSMutableDictionary* dict = [NSMutableDictionary dictionary]; - LogEventParamMap::iterator it; - for (it = paramMap->begin(); it != paramMap->end(); it++) { - std::string key = it->first; - std::string value = it->second; - NSString* pKey = [NSString stringWithUTF8String:key.c_str()]; - NSString* pValue = [NSString stringWithUTF8String:value.c_str()]; - [dict setObject:pValue forKey:pKey]; + do { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + + if (! pData) break; + + id pOCObj = pData->obj; + NSString* className = [NSString stringWithUTF8String:pData->className.c_str()]; + SEL selector = NSSelectorFromString(@"logTimedKVEventBegin:withLabel:withParam:"); + + if (! [pOCObj respondsToSelector:selector]) { + break; } - [MobClick beginEvent:pId primarykey:primary attributes:dict]; - } + + NSString* strEventId = [NSString stringWithUTF8String:eventId]; + NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); + NSString* strLabel = [NSString stringWithUTF8String:label]; + + NSMethodSignature *sig= [NSClassFromString(className) instanceMethodSignatureForSelector:selector]; + NSInvocation *invocation=[NSInvocation invocationWithMethodSignature:sig]; + [invocation setTarget:pOCObj]; + [invocation setSelector:selector]; + [invocation setArgument:&strEventId atIndex:2]; + [invocation setArgument:&strLabel atIndex:3]; + [invocation setArgument:&dict atIndex:4]; + [invocation retainArguments]; + [invocation invoke]; + } while (0); } void AnalyticsUmeng::logTimedKVEventEnd(const char* eventId, const char* label) @@ -294,12 +324,15 @@ void AnalyticsUmeng::logTimedKVEventEnd(const char* eventId, const char* label) return; } - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == label) { - [MobClick endEvent:pId]; - } else { - NSString* primary = [NSString stringWithUTF8String:label]; - [MobClick endEvent:pId primarykey:primary]; + NSString* strEvent = [NSString stringWithUTF8String:eventId]; + NSString* strLabel = [NSString stringWithUTF8String:label]; + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"logTimedKVEventEnd:withLabel:"); + if ([pOCObj respondsToSelector:selector]) { + [pOCObj performSelector:selector withObject:strEvent withObject:strLabel]; + } } } @@ -310,15 +343,38 @@ void AnalyticsUmeng::startSession(const char* appKey, UmengReportPolicy policy, return; } - NSString* key = [NSString stringWithUTF8String:appKey]; - NSString* channel = [NSString stringWithUTF8String:channelId]; - [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"]; - [MobClick startWithAppkey:key reportPolicy:(ReportPolicy)policy channelId:channel]; + do { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + + if (! pData) break; + + id pOCObj = pData->obj; + NSString* className = [NSString stringWithUTF8String:pData->className.c_str()]; + SEL selector = NSSelectorFromString(@"logTimedKVEventBegin:withLabel:withParam:"); + + if (! [pOCObj respondsToSelector:selector]) { + break; + } + + NSString* strKey = [NSString stringWithUTF8String:appKey]; + NSNumber* numPolicy = [NSNumber numberWithInt:policy]; + NSString* strChannel = [NSString stringWithUTF8String:channelId]; + + NSMethodSignature *sig= [NSClassFromString(className) instanceMethodSignatureForSelector:selector]; + NSInvocation *invocation=[NSInvocation invocationWithMethodSignature:sig]; + [invocation setTarget:pOCObj]; + [invocation setSelector:selector]; + [invocation setArgument:&strKey atIndex:2]; + [invocation setArgument:&numPolicy atIndex:3]; + [invocation setArgument:&strChannel atIndex:4]; + [invocation retainArguments]; + [invocation invoke]; + } while (0); } void AnalyticsUmeng::checkUpdate() { - [MobClick checkUpdate]; + PluginUtilsIOS::callOCFunctionWithName(this, "checkUpdate"); } }} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/umeng/platform/ios/UmengWrapper.h b/plugin/plugins/umeng/platform/ios/UmengWrapper.h new file mode 100644 index 0000000000..e44671079d --- /dev/null +++ b/plugin/plugins/umeng/platform/ios/UmengWrapper.h @@ -0,0 +1,61 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#import "InterfaceAnalytics.h" + +@interface UmengWrapper : NSObject +{ + +} + +/** + interfaces of protocol : InterfaceAnalytics + */ +- (void) startSession: (NSString*) appKey; +- (void) stopSession; +- (void) setSessionContinueMillis: (NSNumber*) millis; +- (void) setCaptureUncaughtException: (NSNumber*) isEnabled; +- (void) setDebugMode: (NSNumber*) isDebugMode; +- (void) logError: (NSString*) errorId withMsg:(NSString*) message; +- (void) logEvent: (NSString*) eventId; +- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; +- (void) logTimedEventBegin: (NSString*) eventId; +- (void) logTimedEventEnd: (NSString*) eventId; +- (NSString*) getSDKVersion; + +/** + interfaces of umeng SDK + */ +- (void) updateOnlineConfig; +- (NSString*) getConfigParams: (NSString*) key; +- (void) logEvent: (NSString*) eventId withLabel:(NSString*) label; +- (void) logEvent: (NSString*) eventId withDuration: (NSNumber*) duration withLabel:(NSString*) label; +- (void) logEvent: (NSString*) eventId withDuration: (NSNumber*) duration withParam:(NSMutableDictionary*) paramMap; +- (void) logTimedEventBegin: (NSString*) eventId withLabel:(NSString*) label; +- (void) logTimedEventEnd: (NSString*) eventId withLabel:(NSString*) label; +- (void) logTimedKVEventBegin: (NSString*) eventId withLabel:(NSString*) label withParam:(NSMutableDictionary*) paramMap; +- (void) logTimedKVEventEnd: (NSString*) eventId withLabel:(NSString*) label; +- (void) startSession: (NSString*) appKey withPolicy:(NSNumber*) policy withChannel:(NSString*) channelId; +- (void) checkUpdate; + +@end diff --git a/plugin/plugins/umeng/platform/ios/UmengWrapper.m b/plugin/plugins/umeng/platform/ios/UmengWrapper.m new file mode 100644 index 0000000000..d01990a15f --- /dev/null +++ b/plugin/plugins/umeng/platform/ios/UmengWrapper.m @@ -0,0 +1,170 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#import "UmengWrapper.h" +#import "MobClick.h" + +@implementation UmengWrapper + +- (void) startSession: (NSString*) appKey +{ + [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"]; + [MobClick startWithAppkey:appKey]; +} + +- (void) stopSession +{ + NSLog(@"stopSession in umeng not available on iOS"); +} + +- (void) setSessionContinueMillis: (NSNumber*) millis +{ + NSLog(@"setSessionContinueMillis in umeng not available on iOS"); +} + +- (void) setCaptureUncaughtException: (NSNumber*) isEnabled +{ + BOOL bEnabled = [isEnabled boolValue]; + [MobClick setCrashReportEnabled:bEnabled]; +} + +- (void) setDebugMode: (NSNumber*) isDebugMode +{ + BOOL bDebug = [isDebugMode boolValue]; + [MobClick setLogEnabled:bDebug]; +} + +- (void) logError: (NSString*) errorId withMsg:(NSString*) message +{ + NSLog(@"logError in umeng not available on iOS"); +} + +- (void) logEvent: (NSString*) eventId +{ + [MobClick event:eventId]; +} + +- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap +{ + [MobClick event:eventId attributes:paramMap]; +} + +- (void) logTimedEventBegin: (NSString*) eventId +{ + [MobClick beginEvent:eventId]; +} + +- (void) logTimedEventEnd: (NSString*) eventId +{ + [MobClick endEvent:eventId]; +} + +- (NSString*) getSDKVersion +{ + return @"UMeng no version info"; +} + +- (void) updateOnlineConfig +{ + [MobClick updateOnlineConfig]; +} + +- (NSString*) getConfigParams: (NSString*) key +{ + return [MobClick getConfigParams:key]; +} + +- (void) logEvent: (NSString*) eventId withLabel:(NSString*) label +{ + [MobClick event:eventId label:label]; +} + +- (void) logEvent: (NSString*) eventId withDuration: (NSNumber*) duration withLabel:(NSString*) label +{ + long numDur = [duration longValue]; + if (! label) { + [MobClick event:eventId durations:numDur]; + } else { + [MobClick event:eventId label:label durations:numDur]; + } +} + +- (void) logEvent: (NSString*) eventId withDuration:(NSNumber*) duration withParam:(NSMutableDictionary*) paramMap +{ + long numDur = [duration longValue]; + if (! paramMap) { + [MobClick event:eventId durations:(int)numDur]; + } else { + [MobClick event:eventId attributes:paramMap durations:(int)numDur]; + } +} + +- (void) logTimedEventBegin: (NSString*) eventId withLabel:(NSString*) label +{ + if (! label) { + [MobClick beginEvent:eventId]; + } else { + [MobClick beginEvent:eventId label:label]; + } +} + +- (void) logTimedEventEnd: (NSString*) eventId withLabel:(NSString*) label +{ + if (! label) { + [MobClick endEvent:eventId]; + } else { + [MobClick endEvent:eventId label:label]; + } +} + +- (void) logTimedKVEventBegin: (NSString*) eventId withLabel:(NSString*) label withParam:(NSMutableDictionary*) paramMap +{ + if (! label || ! paramMap) { + [MobClick beginEvent:eventId]; + } else { + [MobClick beginEvent:eventId primarykey:label attributes:paramMap]; + } +} + +- (void) logTimedKVEventEnd: (NSString*) eventId withLabel:(NSString*) label +{ + if (! label) { + [MobClick endEvent:eventId]; + } else { + [MobClick endEvent:eventId primarykey:label]; + } +} + +- (void) startSession: (NSString*) appKey withPolicy:(NSNumber*) policy withChannel:(NSString*) channelId +{ + int nPolicy = [policy intValue]; + [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"]; + [MobClick startWithAppkey:appKey reportPolicy:(ReportPolicy)nPolicy channelId:channelId]; +} + +- (void) checkUpdate +{ + [MobClick checkUpdate]; +} + +@end diff --git a/plugin/plugins/umeng/proj.ios/PluginUmeng.xcodeproj/project.pbxproj b/plugin/plugins/umeng/proj.ios/PluginUmeng.xcodeproj/project.pbxproj index 2a8b7ba8d8..c3ce573636 100644 --- a/plugin/plugins/umeng/proj.ios/PluginUmeng.xcodeproj/project.pbxproj +++ b/plugin/plugins/umeng/proj.ios/PluginUmeng.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ FA09A305168ADAEC008C1C7B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA09A304168ADAEC008C1C7B /* Foundation.framework */; }; FA09A352168ADCA6008C1C7B /* AnalyticsUmeng.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA09A350168ADCA6008C1C7B /* AnalyticsUmeng.mm */; }; + FA42959E173A4B6500462EF7 /* UmengWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = FA42959D173A4B6500462EF7 /* UmengWrapper.m */; }; FA866506168BE06A0073E055 /* libMobClickLibrary.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FA866505168BE06A0073E055 /* libMobClickLibrary.a */; }; /* End PBXBuildFile section */ @@ -30,6 +31,8 @@ FA09A34E168ADC97008C1C7B /* AnalyticsUmeng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnalyticsUmeng.h; sourceTree = ""; }; FA09A350168ADCA6008C1C7B /* AnalyticsUmeng.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AnalyticsUmeng.mm; sourceTree = ""; }; FA09A351168ADCA6008C1C7B /* MobClick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MobClick.h; sourceTree = ""; }; + FA42959C173A4B6500462EF7 /* UmengWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UmengWrapper.h; sourceTree = ""; }; + FA42959D173A4B6500462EF7 /* UmengWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UmengWrapper.m; sourceTree = ""; }; FA866505168BE06A0073E055 /* libMobClickLibrary.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libMobClickLibrary.a; sourceTree = ""; }; /* End PBXFileReference section */ @@ -84,6 +87,8 @@ FA09A34F168ADCA6008C1C7B /* ios */ = { isa = PBXGroup; children = ( + FA42959C173A4B6500462EF7 /* UmengWrapper.h */, + FA42959D173A4B6500462EF7 /* UmengWrapper.m */, FA866505168BE06A0073E055 /* libMobClickLibrary.a */, FA09A350168ADCA6008C1C7B /* AnalyticsUmeng.mm */, FA09A351168ADCA6008C1C7B /* MobClick.h */, @@ -144,6 +149,7 @@ buildActionMask = 2147483647; files = ( FA09A352168ADCA6008C1C7B /* AnalyticsUmeng.mm in Sources */, + FA42959E173A4B6500462EF7 /* UmengWrapper.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -200,7 +206,10 @@ DSTROOT = /tmp/libPluginUmeng.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PluginUmeng-Prefix.pch"; - HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../protocols/include"; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/../../../protocols/include", + "$(SRCROOT)/../../../protocols/platform/ios", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)\"", @@ -218,7 +227,10 @@ DSTROOT = /tmp/libPluginUmeng.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PluginUmeng-Prefix.pch"; - HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../protocols/include"; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/../../../protocols/include", + "$(SRCROOT)/../../../protocols/platform/ios", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)\"", diff --git a/plugin/protocols/platform/ios/InterfaceAds.h b/plugin/protocols/platform/ios/InterfaceAds.h new file mode 100644 index 0000000000..d6e3645ef9 --- /dev/null +++ b/plugin/protocols/platform/ios/InterfaceAds.h @@ -0,0 +1,36 @@ +/**************************************************************************** +Copyright (c) 2012+2013 cocos2d+x.org + +http://www.cocos2d+x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#import + +@protocol InterfaceAds + +- (void) configDeveloperInfo: (NSMutableDictionary*) devInfo; +- (void) showAds: (int) type size:(int) sizeEnum position:(int) pos; +- (void) hideAds: (NSNumber*) type; +- (void) spendPoints: (NSNumber*) points; +- (void) setDebugMode: (NSNumber*) debug; +- (NSString*) getSDKVersion; + +@end diff --git a/plugin/protocols/platform/ios/InterfaceAnalytics.h b/plugin/protocols/platform/ios/InterfaceAnalytics.h new file mode 100644 index 0000000000..239b7f97c7 --- /dev/null +++ b/plugin/protocols/platform/ios/InterfaceAnalytics.h @@ -0,0 +1,41 @@ +/**************************************************************************** +Copyright (c) 2012+2013 cocos2d+x.org + +http://www.cocos2d+x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#import + +@protocol InterfaceAnalytics + +- (void) startSession: (NSString*) appKey; +- (void) stopSession; +- (void) setSessionContinueMillis: (NSNumber*) millis; +- (void) setCaptureUncaughtException: (NSNumber*) isEnabled; +- (void) setDebugMode: (NSNumber*) isDebugMode; +- (void) logError: (NSString*) errorId withMsg:(NSString*) message; +- (void) logEvent: (NSString*) eventId; +- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; +- (void) logTimedEventBegin: (NSString*) eventId; +- (void) logTimedEventEnd: (NSString*) eventId; +- (NSString*) getSDKVersion; + +@end diff --git a/plugin/protocols/platform/ios/InterfaceIAP.h b/plugin/protocols/platform/ios/InterfaceIAP.h new file mode 100644 index 0000000000..6c1cb2da20 --- /dev/null +++ b/plugin/protocols/platform/ios/InterfaceIAP.h @@ -0,0 +1,34 @@ +/**************************************************************************** +Copyright (c) 2012+2013 cocos2d+x.org + +http://www.cocos2d+x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#import + +@protocol InterfaceIAP + +- (void) configDeveloperInfo: (NSMutableDictionary*) cpInfo; +- (void) payForProduct: (NSMutableDictionary*) profuctInfo; +- (void) setDebugMode: (NSNumber*) debug; +- (NSString*) getSDKVersion; + +@end diff --git a/plugin/protocols/platform/ios/InterfaceSocial.h b/plugin/protocols/platform/ios/InterfaceSocial.h new file mode 100644 index 0000000000..b98eb8827e --- /dev/null +++ b/plugin/protocols/platform/ios/InterfaceSocial.h @@ -0,0 +1,29 @@ +/**************************************************************************** +Copyright (c) 2012+2013 cocos2d+x.org + +http://www.cocos2d+x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +@protocol InterfaceSocial + + + +@end diff --git a/plugin/protocols/platform/ios/PluginUtilsIOS.h b/plugin/protocols/platform/ios/PluginUtilsIOS.h new file mode 100644 index 0000000000..4933575de8 --- /dev/null +++ b/plugin/protocols/platform/ios/PluginUtilsIOS.h @@ -0,0 +1,61 @@ +/**************************************************************************** +Copyright (c) 2012+2013 cocos2d+x.org + +http://www.cocos2d+x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef __PLUGIN_UTILS_IOS_H__ +#define __PLUGIN_UTILS_IOS_H__ + +#include "PluginProtocol.h" +#include +#include + +namespace cocos2d { namespace plugin { + +#define return_if_fails(cond) if (!(cond)) return; +#define return_val_if_fails(cond, ret) if(!(cond)) return (ret); + +typedef struct _PluginOCData +{ + id obj; + std::string className; +} PluginOCData; + +class PluginUtilsIOS +{ +public: + static bool initOCPlugin(PluginProtocol* pPlugin, const char* className); + + static PluginOCData* getPluginOCData(PluginProtocol* pKeyObj); + static void setPluginOCData(PluginProtocol* pKeyObj, PluginOCData* pData); + static void erasePluginOCData(PluginProtocol* pKeyObj); + + static PluginProtocol* getPluginPtr(id obj); + + static NSMutableDictionary* createDictFromMap(std::map* paramMap); + static void callOCFunctionWithName(PluginProtocol* pPlugin, const char* funcName); + static void callOCFunctionWithName_Object(PluginProtocol* pPlugin, const char* funcName, id obj); +}; + +}} // namespace cocos2d { namespace plugin { + +#endif //__PLUGIN_UTILS_IOS_H__ diff --git a/plugin/protocols/platform/ios/PluginUtilsIOS.mm b/plugin/protocols/platform/ios/PluginUtilsIOS.mm new file mode 100644 index 0000000000..2236ba1858 --- /dev/null +++ b/plugin/protocols/platform/ios/PluginUtilsIOS.mm @@ -0,0 +1,174 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "PluginUtilsIOS.h" +#include +#import + +namespace cocos2d { namespace plugin { + +static PluginProtocol* s_pPluginInstance = NULL; + +bool PluginUtilsIOS::initOCPlugin(PluginProtocol* pPlugin, const char* className) +{ + return_val_if_fails(className != NULL && strlen(className) > 0, false); + bool bRet = false; + + NSString* name = [NSString stringWithUTF8String:className]; + id obj = [[NSClassFromString(name) alloc] init]; + if (obj != nil) + { + PluginOCData* pData = new PluginOCData(); + pData->obj = obj; + pData->className = className; + PluginUtilsIOS::setPluginOCData(pPlugin, pData); + bRet = true; + } + + return bRet; +} + +std::map s_PluginOCObjMap; +std::map s_OCObjPluginMap; + +typedef std::map::iterator OCObjMapIter; +typedef std::map::iterator OCObjPluginMapIter; + +PluginOCData* PluginUtilsIOS::getPluginOCData(PluginProtocol* pKeyObj) +{ + PluginOCData* ret = NULL; + OCObjMapIter it = s_PluginOCObjMap.find(pKeyObj); + if (it != s_PluginOCObjMap.end()) { + ret = it->second; + } + + return ret; +} + +PluginProtocol* PluginUtilsIOS::getPluginPtr(id obj) +{ + PluginProtocol* ret = NULL; + OCObjPluginMapIter it = s_OCObjPluginMap.find(obj); + if (it != s_OCObjPluginMap.end()) { + ret = it->second; + } + + return ret; +} + +void PluginUtilsIOS::setPluginOCData(PluginProtocol* pKeyObj, PluginOCData* pData) +{ + erasePluginOCData(pKeyObj); + s_PluginOCObjMap.insert(std::pair(pKeyObj, pData)); + s_OCObjPluginMap.insert(std::pair(pData->obj, pKeyObj)); +} + +void PluginUtilsIOS::erasePluginOCData(PluginProtocol* pKeyObj) +{ + OCObjMapIter it = s_PluginOCObjMap.find(pKeyObj); + if (it != s_PluginOCObjMap.end()) { + PluginOCData* pData = it->second; + if (pData != NULL) + { + id jobj = pData->obj; + + OCObjPluginMapIter pluginIt = s_OCObjPluginMap.find(jobj); + if (pluginIt != s_OCObjPluginMap.end()) + { + s_OCObjPluginMap.erase(pluginIt); + } + + [jobj release]; + delete pData; + } + s_PluginOCObjMap.erase(it); + } +} + +NSMutableDictionary* PluginUtilsIOS::createDictFromMap(std::map* paramMap) +{ + if (NULL == paramMap) + { + return nil; + } + + NSMutableDictionary* dict = [NSMutableDictionary dictionary]; + std::map::const_iterator it; + for (it = paramMap->begin(); it != paramMap->end(); ++it) + { + NSString* pKey = [NSString stringWithUTF8String:it->first.c_str()]; + NSString* pValue = [NSString stringWithUTF8String:it->second.c_str()]; + [dict setValue:pValue forKey:pKey]; + } + + return dict; +} + +void PluginUtilsIOS::callOCFunctionWithName(PluginProtocol* pPlugin, const char* funcName) +{ + return_if_fails(funcName != NULL && strlen(funcName) > 0); + + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(pPlugin); + if (pData) { + id pOCObj = pData->obj; + NSString* strFuncName = [NSString stringWithUTF8String:funcName]; + SEL selector = NSSelectorFromString(strFuncName); + + const char* className = class_getName([pOCObj class]); + NSString* strClassName = [NSString stringWithUTF8String:className]; + if ([pOCObj respondsToSelector:selector]) { + [pOCObj performSelector:selector]; + NSLog(@"Function '%@' in class '%@' invoked", strFuncName, strClassName); + } else { + NSLog(@"Can't find function '%@' in class '%@'", strFuncName, strClassName); + } + } else { + printf("Can't find function '%s' in plugin %p", funcName, pPlugin); + } +} + +void PluginUtilsIOS::callOCFunctionWithName_Object(PluginProtocol* pPlugin, const char* funcName, id obj) +{ + return_if_fails(funcName != NULL && strlen(funcName) > 0); + + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(pPlugin); + if (pData) { + id pOCObj = pData->obj; + NSString* strFuncName = [NSString stringWithUTF8String:funcName]; + SEL selector = NSSelectorFromString(strFuncName); + + const char* className = class_getName([pOCObj class]); + NSString* strClassName = [NSString stringWithUTF8String:className]; + if ([pOCObj respondsToSelector:selector]) { + [pOCObj performSelector:selector withObject:obj]; + NSLog(@"Function '%@' in class '%@' invoked", strFuncName, strClassName); + } else { + NSLog(@"Can't find function '%@' in class '%@'", strFuncName, strClassName); + } + } else { + printf("Can't find function '%s' in plugin %p", funcName, pPlugin); + } +} + +}}// namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolAds.cpp b/plugin/protocols/platform/ios/ProtocolAds.cpp deleted file mode 100644 index 73c14f97dd..0000000000 --- a/plugin/protocols/platform/ios/ProtocolAds.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "ProtocolAds.h" - -namespace cocos2d { namespace plugin { - -ProtocolAds::ProtocolAds() -: m_pListener(NULL) -{ -} - -ProtocolAds::~ProtocolAds() -{ -} - -bool ProtocolAds::init() -{ - return true; -} - -void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo) -{ -} - -void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos) -{ -} - -void ProtocolAds::hideAds(AdsType type) -{ -} - -void ProtocolAds::spendPoints(int points) -{ -} - -void ProtocolAds::setDebugMode(bool debug) -{ -} - -// For the callbak methods -void ProtocolAds::setAdsListener(AdsListener* pListener) -{ - m_pListener = pListener; -} - -void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg) -{ - if (m_pListener != NULL) - { - m_pListener->onAdsResult(code, msg); - } -} - -void ProtocolAds::onPlayerGetPoints(int points) -{ - if (m_pListener != NULL) - { - m_pListener->onPlayerGetPoints(this, points); - } -} - -const char* ProtocolAds::getSDKVersion() -{ - return "Subclass should override this interface"; -} - -}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolAds.mm b/plugin/protocols/platform/ios/ProtocolAds.mm new file mode 100644 index 0000000000..0e9a2cb85c --- /dev/null +++ b/plugin/protocols/platform/ios/ProtocolAds.mm @@ -0,0 +1,91 @@ +/**************************************************************************** + Copyright (c) 2012+2013 cocos2d+x.org + + http://www.cocos2d+x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "ProtocolAds.h" +#import "InterfaceAds.h" + +namespace cocos2d { namespace plugin { + +ProtocolAds::ProtocolAds() +: m_pListener(NULL) +{ +} + +ProtocolAds::~ProtocolAds() +{ +} + +bool ProtocolAds::init() +{ + return true; +} + +void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo) +{ +} + +void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos) +{ +} + +void ProtocolAds::hideAds(AdsType type) +{ +} + +void ProtocolAds::spendPoints(int points) +{ +} + +void ProtocolAds::setDebugMode(bool debug) +{ +} + +// For the callbak methods +void ProtocolAds::setAdsListener(AdsListener* pListener) +{ + m_pListener = pListener; +} + +void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg) +{ + if (m_pListener != NULL) + { + m_pListener->onAdsResult(code, msg); + } +} + +void ProtocolAds::onPlayerGetPoints(int points) +{ + if (m_pListener != NULL) + { + m_pListener->onPlayerGetPoints(this, points); + } +} + +const char* ProtocolAds::getSDKVersion() +{ + return "Subclass should override this interface"; +} + +}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolAnalytics.cpp b/plugin/protocols/platform/ios/ProtocolAnalytics.cpp deleted file mode 100644 index 86946fd553..0000000000 --- a/plugin/protocols/platform/ios/ProtocolAnalytics.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "ProtocolAnalytics.h" - -namespace cocos2d { namespace plugin { - -ProtocolAnalytics::ProtocolAnalytics() -{ -} - -ProtocolAnalytics::~ProtocolAnalytics() -{ -} - -bool ProtocolAnalytics::init() -{ - return true; -} - -/** - @brief Start a new session. - @param appKey The identity of the application. - */ -void ProtocolAnalytics::startSession(const char* appKey) -{ - -} - -/** - @brief Stop a session. - @warning This interface only worked on android - */ -void ProtocolAnalytics::stopSession() -{ - -} - -/** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - @note It must be invoked before calling startSession. - */ -void ProtocolAnalytics::setDebugMode(bool debug) -{ - -} - -/** - @brief Set the timeout for expiring a session. - @param millis In milliseconds as the unit of time. - @note It must be invoked before calling startSession. - */ -void ProtocolAnalytics::setSessionContinueMillis(long millis) -{ - -} - -/** - @brief log an error - @param errorId The identity of error - @param message Extern message for the error - */ -void ProtocolAnalytics::logError(const char* errorId, const char* message) -{ - -} - -/** - @brief log an event. - @param eventId The identity of event - @param paramMap Extern parameters of the event, use NULL if not needed. - */ -void ProtocolAnalytics::logEvent(const char* eventId, LogEventParamMap* paramMap) -{ - -} - -/** - @brief Track an event begin. - @param eventId The identity of event - */ -void ProtocolAnalytics::logTimedEventBegin(const char* eventId) -{ - -} - -/** - @brief Track an event end. - @param eventId The identity of event - */ -void ProtocolAnalytics::logTimedEventEnd(const char* eventId) -{ - -} - -/** - @brief Whether to catch uncaught exceptions to server. - @warning This interface only worked on android. - */ -void ProtocolAnalytics::setCaptureUncaughtException(bool enabled) -{ - -} - -const char* ProtocolAnalytics::getSDKVersion() -{ - return "Subclass should override this interface"; -} - -}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolAnalytics.mm b/plugin/protocols/platform/ios/ProtocolAnalytics.mm new file mode 100644 index 0000000000..ae04635971 --- /dev/null +++ b/plugin/protocols/platform/ios/ProtocolAnalytics.mm @@ -0,0 +1,186 @@ +/**************************************************************************** + Copyright (c) 2012+2013 cocos2d+x.org + + http://www.cocos2d+x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#include "ProtocolAnalytics.h" +#import "InterfaceAnalytics.h" +#include "PluginUtilsIOS.h" + +namespace cocos2d { namespace plugin { + +ProtocolAnalytics::ProtocolAnalytics() +{ +} + +ProtocolAnalytics::~ProtocolAnalytics() +{ + PluginUtilsIOS::erasePluginOCData(this); +} + +bool ProtocolAnalytics::init() +{ + return true; +} + +/** + @brief Start a new session. + @param appKey The identity of the application. + */ +void ProtocolAnalytics::startSession(const char* appKey) +{ + NSString* pStrKey = [NSString stringWithUTF8String:appKey]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "startSession:", pStrKey); +} + +/** + @brief Stop a session. + @warning This interface only worked on android + */ +void ProtocolAnalytics::stopSession() +{ + PluginUtilsIOS::callOCFunctionWithName(this, "stopSession"); +} + +/** + @brief Set whether needs to output logs to console. + @param debug if true debug mode enabled, or debug mode disabled. + @note It must be invoked before calling startSession. + */ +void ProtocolAnalytics::setDebugMode(bool debug) +{ + NSNumber* bDebug = [NSNumber numberWithBool:debug]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "setDebugMode:", bDebug); +} + +/** + @brief Set the timeout for expiring a session. + @param millis In milliseconds as the unit of time. + @note It must be invoked before calling startSession. + */ +void ProtocolAnalytics::setSessionContinueMillis(long millis) +{ + NSNumber* lMillis = [NSNumber numberWithLong:millis]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "setSessionContinueMillis:", lMillis); +} + +/** + @brief log an error + @param errorId The identity of error + @param message Extern message for the error + */ +void ProtocolAnalytics::logError(const char* errorId, const char* message) +{ + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (! pData) { + return; + } + + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"logError:withMsg:"); + if ([pOCObj respondsToSelector:selector]) { + + NSString* strErrID = [NSString stringWithUTF8String:errorId]; + NSString* strMsg = [NSString stringWithUTF8String:message]; + [pOCObj logError:strErrID withMsg:strMsg]; + NSLog(@"logError withMsg in OC class invoked!"); + } +} + +/** + @brief log an event. + @param eventId The identity of event + @param paramMap Extern parameters of the event, use NULL if not needed. + */ +void ProtocolAnalytics::logEvent(const char* eventId, LogEventParamMap* paramMap) +{ + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (! pData) { + return; + } + + id pOCObj = pData->obj; + NSString* strEventID = [NSString stringWithUTF8String:eventId]; + + if (paramMap == NULL) { + PluginUtilsIOS::callOCFunctionWithName_Object(this, "logEvent:", strEventID); + NSLog(@"logEvent(no paramsters) in OC class invoked!"); + } else { + SEL selector = NSSelectorFromString(@"logEvent:withParam:"); + if ([pOCObj respondsToSelector:selector]) { + + NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); + [pOCObj logEvent:strEventID withParam:dict]; + NSLog(@"logEvent(with parameters) in OC class invoked!"); + } + } +} + +/** + @brief Track an event begin. + @param eventId The identity of event + */ +void ProtocolAnalytics::logTimedEventBegin(const char* eventId) +{ + NSString* pStrID = [NSString stringWithUTF8String:eventId]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "logTimedEventBegin:", pStrID); +} + +/** + @brief Track an event end. + @param eventId The identity of event + */ +void ProtocolAnalytics::logTimedEventEnd(const char* eventId) +{ + NSString* pStrID = [NSString stringWithUTF8String:eventId]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "logTimedEventEnd:", pStrID); +} + +/** + @brief Whether to catch uncaught exceptions to server. + @warning This interface only worked on android. + */ +void ProtocolAnalytics::setCaptureUncaughtException(bool enabled) +{ + NSNumber* bEnable = [NSNumber numberWithBool:enabled]; + PluginUtilsIOS::callOCFunctionWithName_Object(this, "setCaptureUncaughtException:", bEnable); +} + +const char* ProtocolAnalytics::getSDKVersion() +{ + const char* pRet = ""; + + do { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (! pData) break; + + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"getSDKVersion"); + if ([pOCObj respondsToSelector:selector]) { + NSString* strRet = [pOCObj performSelector:selector]; + pRet = [strRet UTF8String]; + } + } while (0); + + return pRet; +} + +}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolIAP.cpp b/plugin/protocols/platform/ios/ProtocolIAP.cpp deleted file mode 100644 index 2c11ed0d72..0000000000 --- a/plugin/protocols/platform/ios/ProtocolIAP.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "ProtocolIAP.h" - -namespace cocos2d { namespace plugin { - -bool ProtocolIAP::m_bPaying = false; - -ProtocolIAP::ProtocolIAP() -: m_pListener(NULL) -{ -} - -ProtocolIAP::~ProtocolIAP() -{ -} - -bool ProtocolIAP::init() -{ - return true; -} - -void ProtocolIAP::configDeveloperInfo(TIAPDeveloperInfo devInfo) -{ -} - -void ProtocolIAP::payForProduct(TProductInfo info) -{ -} - -void ProtocolIAP::setResultListener(PayResultListener* pListener) -{ - m_pListener = pListener; -} - -void ProtocolIAP::onPayResult(PayResultCode ret, const char* msg) -{ - m_bPaying = false; - if (m_pListener) - { - m_pListener->onPayResult(ret, msg, m_curInfo); - } - - m_curInfo.clear(); -} - -const char* ProtocolIAP::getSDKVersion() -{ - return "Subclass should override this interface"; -} - -void ProtocolIAP::setDebugMode(bool debug) -{ -} - -}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolIAP.mm b/plugin/protocols/platform/ios/ProtocolIAP.mm new file mode 100644 index 0000000000..d142c880c0 --- /dev/null +++ b/plugin/protocols/platform/ios/ProtocolIAP.mm @@ -0,0 +1,80 @@ +/**************************************************************************** + Copyright (c) 2012-2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#include "ProtocolIAP.h" +#include "PluginUtilsIOS.h" +#import "InterfaceIAP.h" + +namespace cocos2d { namespace plugin { + +bool ProtocolIAP::m_bPaying = false; + +ProtocolIAP::ProtocolIAP() +: m_pListener(NULL) +{ +} + +ProtocolIAP::~ProtocolIAP() +{ + PluginUtilsIOS::erasePluginOCData(this); +} + +bool ProtocolIAP::init() +{ + return true; +} + +void ProtocolIAP::configDeveloperInfo(TIAPDeveloperInfo devInfo) +{ +} + +void ProtocolIAP::payForProduct(TProductInfo info) +{ +} + +void ProtocolIAP::setResultListener(PayResultListener* pListener) +{ + m_pListener = pListener; +} + +void ProtocolIAP::onPayResult(PayResultCode ret, const char* msg) +{ + m_bPaying = false; + if (m_pListener) + { + m_pListener->onPayResult(ret, msg, m_curInfo); + } + + m_curInfo.clear(); +} + +const char* ProtocolIAP::getSDKVersion() +{ + return "Subclass should override this interface"; +} + +void ProtocolIAP::setDebugMode(bool debug) +{ +} + +}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj b/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj index 4f7fdaa3ae..289b40e67c 100644 --- a/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj +++ b/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj @@ -10,9 +10,11 @@ FA09A325168ADBC2008C1C7B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA09A324168ADBC2008C1C7B /* Foundation.framework */; }; FA09A33E168ADC1F008C1C7B /* PluginManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA09A33C168ADC1F008C1C7B /* PluginManager.cpp */; }; FA09A33F168ADC1F008C1C7B /* RegisterPlugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA09A33D168ADC1F008C1C7B /* RegisterPlugin.cpp */; }; - FA0CB8B7168D3CC200E36B11 /* ProtocolAnalytics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0CB8B6168D3CC200E36B11 /* ProtocolAnalytics.cpp */; }; - FA7C6C9B1724E51C008A0ECC /* ProtocolAds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA7C6C991724E51C008A0ECC /* ProtocolAds.cpp */; }; - FA7C6C9C1724E51C008A0ECC /* ProtocolIAP.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA7C6C9A1724E51C008A0ECC /* ProtocolIAP.cpp */; }; + FA8CC1E6173754CF00464206 /* PluginUtilsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC1E5173754CF00464206 /* PluginUtilsIOS.mm */; }; + FA8CC2041737A3CE00464206 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA8CC2031737A3CE00464206 /* CoreFoundation.framework */; }; + FA8CC208173894F000464206 /* ProtocolAds.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC205173894F000464206 /* ProtocolAds.mm */; }; + FA8CC209173894F000464206 /* ProtocolAnalytics.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC206173894F000464206 /* ProtocolAnalytics.mm */; }; + FA8CC20A173894F000464206 /* ProtocolIAP.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC207173894F000464206 /* ProtocolIAP.mm */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -37,11 +39,18 @@ FA09A33B168ADC05008C1C7B /* RegisterPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegisterPlugin.h; sourceTree = ""; }; FA09A33C168ADC1F008C1C7B /* PluginManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PluginManager.cpp; path = ../PluginManager.cpp; sourceTree = ""; }; FA09A33D168ADC1F008C1C7B /* RegisterPlugin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RegisterPlugin.cpp; path = ../RegisterPlugin.cpp; sourceTree = ""; }; - FA0CB8B6168D3CC200E36B11 /* ProtocolAnalytics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProtocolAnalytics.cpp; sourceTree = ""; }; FA4E3033172BD02800A3E673 /* ProtocolSocial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolSocial.h; sourceTree = ""; }; FA7C6C971724E4DD008A0ECC /* ProtocolAds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolAds.h; sourceTree = ""; }; - FA7C6C991724E51C008A0ECC /* ProtocolAds.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProtocolAds.cpp; sourceTree = ""; }; - FA7C6C9A1724E51C008A0ECC /* ProtocolIAP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProtocolIAP.cpp; sourceTree = ""; }; + FA8CC1E4173754CF00464206 /* PluginUtilsIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginUtilsIOS.h; sourceTree = ""; }; + FA8CC1E5173754CF00464206 /* PluginUtilsIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginUtilsIOS.mm; sourceTree = ""; }; + FA8CC2031737A3CE00464206 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; + FA8CC205173894F000464206 /* ProtocolAds.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProtocolAds.mm; sourceTree = ""; }; + FA8CC206173894F000464206 /* ProtocolAnalytics.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProtocolAnalytics.mm; sourceTree = ""; }; + FA8CC207173894F000464206 /* ProtocolIAP.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProtocolIAP.mm; sourceTree = ""; }; + FA8CC21B1739E86E00464206 /* InterfaceAds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceAds.h; sourceTree = ""; }; + FA8CC21C1739E86E00464206 /* InterfaceAnalytics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceAnalytics.h; sourceTree = ""; }; + FA8CC21D1739E86E00464206 /* InterfaceIAP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceIAP.h; sourceTree = ""; }; + FA8CC21E1739E86E00464206 /* InterfaceSocial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceSocial.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -49,6 +58,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + FA8CC2041737A3CE00464206 /* CoreFoundation.framework in Frameworks */, FA09A325168ADBC2008C1C7B /* Foundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -59,6 +69,7 @@ FA09A316168ADBC2008C1C7B = { isa = PBXGroup; children = ( + FA8CC2031737A3CE00464206 /* CoreFoundation.framework */, FA0CB8B5168D3CC200E36B11 /* ios */, FA09A33C168ADC1F008C1C7B /* PluginManager.cpp */, FA09A33D168ADC1F008C1C7B /* RegisterPlugin.cpp */, @@ -102,9 +113,15 @@ FA0CB8B5168D3CC200E36B11 /* ios */ = { isa = PBXGroup; children = ( - FA7C6C991724E51C008A0ECC /* ProtocolAds.cpp */, - FA7C6C9A1724E51C008A0ECC /* ProtocolIAP.cpp */, - FA0CB8B6168D3CC200E36B11 /* ProtocolAnalytics.cpp */, + FA8CC21B1739E86E00464206 /* InterfaceAds.h */, + FA8CC21C1739E86E00464206 /* InterfaceAnalytics.h */, + FA8CC21D1739E86E00464206 /* InterfaceIAP.h */, + FA8CC21E1739E86E00464206 /* InterfaceSocial.h */, + FA8CC205173894F000464206 /* ProtocolAds.mm */, + FA8CC206173894F000464206 /* ProtocolAnalytics.mm */, + FA8CC207173894F000464206 /* ProtocolIAP.mm */, + FA8CC1E4173754CF00464206 /* PluginUtilsIOS.h */, + FA8CC1E5173754CF00464206 /* PluginUtilsIOS.mm */, ); name = ios; path = ../platform/ios; @@ -163,9 +180,10 @@ files = ( FA09A33E168ADC1F008C1C7B /* PluginManager.cpp in Sources */, FA09A33F168ADC1F008C1C7B /* RegisterPlugin.cpp in Sources */, - FA0CB8B7168D3CC200E36B11 /* ProtocolAnalytics.cpp in Sources */, - FA7C6C9B1724E51C008A0ECC /* ProtocolAds.cpp in Sources */, - FA7C6C9C1724E51C008A0ECC /* ProtocolIAP.cpp in Sources */, + FA8CC1E6173754CF00464206 /* PluginUtilsIOS.mm in Sources */, + FA8CC208173894F000464206 /* ProtocolAds.mm in Sources */, + FA8CC209173894F000464206 /* ProtocolAnalytics.mm in Sources */, + FA8CC20A173894F000464206 /* ProtocolIAP.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp b/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp index 328db0e615..d964b52fc3 100644 --- a/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp +++ b/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp @@ -86,6 +86,10 @@ bool AppDelegate::applicationDidFinishLaunching() g_pAnalytics->setDebugMode(true); g_pAnalytics->startSession(s_strAppKey.c_str()); g_pAnalytics->setCaptureUncaughtException(true); + g_pAnalytics->setSessionContinueMillis(10000); + + const char* sdkVer = g_pAnalytics->getSDKVersion(); + CCLog("SDK version : %s", sdkVer); AnalyticsUmeng* pUmeng = dynamic_cast(g_pAnalytics); AnalyticsFlurry* pFlurry = dynamic_cast(g_pAnalytics); diff --git a/plugin/samples/HelloAnalytics/proj.ios/HelloAnalytics.xcodeproj/project.pbxproj b/plugin/samples/HelloAnalytics/proj.ios/HelloAnalytics.xcodeproj/project.pbxproj index 1869f2a4ad..76e7e6adca 100755 --- a/plugin/samples/HelloAnalytics/proj.ios/HelloAnalytics.xcodeproj/project.pbxproj +++ b/plugin/samples/HelloAnalytics/proj.ios/HelloAnalytics.xcodeproj/project.pbxproj @@ -465,6 +465,7 @@ "\"$(SRCROOT)/../../../plugins/flurry/platform/ios\"", "\"$(SRCROOT)/../../../plugins/umeng/platform/ios\"", ); + "OTHER_LDFLAGS[arch=*]" = "-ObjC"; PRODUCT_NAME = HelloAnalytics; PROVISIONING_PROFILE = ""; SDKROOT = iphoneos; @@ -508,6 +509,7 @@ "\"$(SRCROOT)/../../../plugins/flurry/platform/ios\"", "\"$(SRCROOT)/../../../plugins/umeng/platform/ios\"", ); + "OTHER_LDFLAGS[arch=*]" = "-ObjC"; PRODUCT_NAME = HelloAnalytics; PROVISIONING_PROFILE = ""; SDKROOT = iphoneos;