From 048dc6cb909b72092d9ba5036398345b3336a684 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Thu, 15 Sep 2016 13:31:21 +0300 Subject: [PATCH] [ios] Added marketing events sender to platform. --- .../jni/com/mapswithme/platform/Platform.cpp | 5 +++ iphone/Maps/main.mm | 39 ++++++++++++++----- platform/platform.hpp | 8 ++++ platform/platform_android.cpp | 1 + platform/platform_ios.mm | 6 +++ platform/platform_mac.mm | 4 ++ platform/platform_qt.cpp | 5 +++ 7 files changed, 58 insertions(+), 10 deletions(-) diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp index bc327c46eb..16793dcccc 100644 --- a/android/jni/com/mapswithme/platform/Platform.cpp +++ b/android/jni/com/mapswithme/platform/Platform.cpp @@ -84,6 +84,11 @@ void Platform::SendPushWooshTag(string const & tag, vector const & value android::Platform::Instance().SendPushWooshTag(tag, values); } +void Platform::SendMarketingEvent(string const & tag, map const & params) +{ + // TODO: Add implementation. +} + Platform::EConnectionType Platform::ConnectionStatus() { JNIEnv * env = jni::GetEnv(); diff --git a/iphone/Maps/main.mm b/iphone/Maps/main.mm index d0f07129c4..3a7407c695 100644 --- a/iphone/Maps/main.mm +++ b/iphone/Maps/main.mm @@ -1,6 +1,7 @@ #import #import "Common.h" #import "MapsAppDelegate.h" +#import #ifdef OMIM_PRODUCTION # include "fabric_logging.hpp" @@ -10,17 +11,9 @@ #include "platform/platform.hpp" #include "platform/settings.hpp" -int main(int argc, char * argv[]) +void setPushWooshSender() { -#ifdef MWM_LOG_TO_FILE - my::SetLogMessageFn(LogMessageFile); -#elif OMIM_PRODUCTION - my::SetLogMessageFn(platform::LogMessageFabric); -#endif - auto & p = GetPlatform(); - LOG(LINFO, ("maps.me started, detected CPU cores:", p.CpuCores())); - - p.SetPushWooshSender([](string const & tag, vector const & values) { + GetPlatform().SetPushWooshSender([](string const & tag, vector const & values) { if (values.empty() || tag.empty()) return; PushNotificationManager * pushManager = [PushNotificationManager pushManager]; @@ -36,6 +29,32 @@ int main(int argc, char * argv[]) [pushManager setTags:@{ @(tag.c_str()) : tags }]; } }); +} + +void setMarketingSender() +{ + GetPlatform().SetMarketingSender([](string const & tag, map const & params) { + if (tag.empty()) + return; + NSMutableDictionary * eventParams = [@{} mutableCopy]; + for(auto const & param : params) + eventParams[@(param.first.c_str())] = @(param.second.c_str()); + [MRMyTracker trackEvent:@(tag.c_str()) eventParams:eventParams]; + }); +} + +int main(int argc, char * argv[]) +{ +#ifdef MWM_LOG_TO_FILE + my::SetLogMessageFn(LogMessageFile); +#elif OMIM_PRODUCTION + my::SetLogMessageFn(platform::LogMessageFabric); +#endif + auto & p = GetPlatform(); + LOG(LINFO, ("maps.me started, detected CPU cores:", p.CpuCores())); + + setPushWooshSender(); + setMarketingSender(); int retVal; @autoreleasepool diff --git a/platform/platform.hpp b/platform/platform.hpp index 0e1c09f405..dbd7bf341f 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -8,6 +8,7 @@ #include "std/string.hpp" #include "std/vector.hpp" +#include "std/map.hpp" #include "std/utility.hpp" #include "std/function.hpp" #include "std/bitset.hpp" @@ -55,6 +56,7 @@ public: using TFilesWithType = vector>; using TPushWooshSenderFn = function const & values)>; + using TMarketingSenderFn = function const & params)>; protected: /// Usually read-only directory for application resources @@ -90,6 +92,9 @@ protected: /// Callback fucntion for setting PushWoosh tags. TPushWooshSenderFn m_pushwooshSender; + /// Callback fucntion for sending marketing events. + TMarketingSenderFn m_marketingSender; + public: Platform(); @@ -233,6 +238,9 @@ public: void SendPushWooshTag(string const & tag, string const & value); void SendPushWooshTag(string const & tag, vector const & values); + void SetMarketingSender(TMarketingSenderFn const & fn) { m_marketingSender = fn; } + void SendMarketingEvent(string const & tag, map const & params); + private: void GetSystemFontNames(FilesList & res) const; }; diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp index 3613a8fc5b..cb228962e1 100644 --- a/platform/platform_android.cpp +++ b/platform/platform_android.cpp @@ -265,6 +265,7 @@ void Platform::SetupMeasurementSystem() const //void Platform::SendPushWooshTag(string const & tag){} //void Platform::SendPushWooshTag(string const & tag, string const & value){} //void Platform::SendPushWooshTag(string const & tag, vector const & values){} +//void Platform::SendMarketingEvent(string const & tag, map const & params){} namespace { diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm index f494ead673..7173a8f653 100644 --- a/platform/platform_ios.mm +++ b/platform/platform_ios.mm @@ -229,6 +229,12 @@ void Platform::SendPushWooshTag(string const & tag, vector const & value m_pushwooshSender(tag, values); } +void Platform::SendMarketingEvent(string const & tag, map const & params) +{ + if (m_marketingSender) + m_marketingSender(tag, params); +} + //////////////////////////////////////////////////////////////////////// extern Platform & GetPlatform() { diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm index 48ca2925ae..a8fc30ec80 100644 --- a/platform/platform_mac.mm +++ b/platform/platform_mac.mm @@ -151,3 +151,7 @@ void Platform::SendPushWooshTag(string const & tag, string const & value) void Platform::SendPushWooshTag(string const & tag, vector const & values) { } + +void Platform::SendMarketingEvent(string const & tag, map const & params) +{ +} diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp index c951310ae9..3f3889d91b 100644 --- a/platform/platform_qt.cpp +++ b/platform/platform_qt.cpp @@ -107,6 +107,11 @@ void Platform::SendPushWooshTag(string const & tag, string const & value) void Platform::SendPushWooshTag(string const & tag, vector const & values) { } + +void Platform::SendMarketingEvent(string const & tag, map const & params) +{ +} + #endif // defined(OMIM_OS_LINUX) extern Platform & GetPlatform()