ProtocolAds.mm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /****************************************************************************
  2. Copyright (c) 2012+2013 cocos2d+x.org
  3. http://www.cocos2d+x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #include "ProtocolAds.h"
  21. #include "PluginUtilsIOS.h"
  22. #import "InterfaceAds.h"
  23. namespace cocos2d { namespace plugin {
  24. ProtocolAds::ProtocolAds()
  25. : _listener(NULL)
  26. {
  27. }
  28. ProtocolAds::~ProtocolAds()
  29. {
  30. }
  31. void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo)
  32. {
  33. if (devInfo.empty())
  34. {
  35. PluginUtilsIOS::outputLog("The developer info is empty for %s!", this->getPluginName());
  36. return;
  37. }
  38. else
  39. {
  40. PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this);
  41. assert(pData != NULL);
  42. id ocObj = pData->obj;
  43. if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) {
  44. NSObject<InterfaceAds>* curObj = ocObj;
  45. NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(&devInfo);
  46. [curObj configDeveloperInfo:dict];
  47. }
  48. }
  49. }
  50. void ProtocolAds::showAds(TAdsInfo info, AdsPos pos)
  51. {
  52. PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this);
  53. assert(pData != NULL);
  54. id ocObj = pData->obj;
  55. if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) {
  56. NSObject<InterfaceAds>* curObj = ocObj;
  57. NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(&info);
  58. [curObj showAds:dict position:pos];
  59. }
  60. }
  61. void ProtocolAds::hideAds(TAdsInfo info)
  62. {
  63. PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this);
  64. assert(pData != NULL);
  65. id ocObj = pData->obj;
  66. if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) {
  67. NSObject<InterfaceAds>* curObj = ocObj;
  68. NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(&info);
  69. [curObj hideAds:dict];
  70. }
  71. }
  72. void ProtocolAds::queryPoints()
  73. {
  74. PluginUtilsIOS::callOCFunctionWithName(this, "queryPoints");
  75. }
  76. void ProtocolAds::spendPoints(int points)
  77. {
  78. PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this);
  79. assert(pData != NULL);
  80. id ocObj = pData->obj;
  81. if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) {
  82. NSObject<InterfaceAds>* curObj = ocObj;
  83. [curObj spendPoints:points];
  84. }
  85. }
  86. }} //namespace cocos2d { namespace plugin {