AdsFlurry.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #import "AdsFlurry.h"
  21. #import "Flurry.h"
  22. #import "FlurryAds.h"
  23. #import "AdsWrapper.h"
  24. #define OUTPUT_LOG(...) if (self.debug) NSLog(__VA_ARGS__);
  25. @implementation AdsFlurry
  26. @synthesize debug = __debug;
  27. #pragma mark Interfaces for ProtocolAds impl
  28. - (void) configDeveloperInfo: (NSMutableDictionary*) devInfo
  29. {
  30. NSString* appKey = [devInfo objectForKey:@"FlurryAppKey"];
  31. if (appKey) {
  32. [Flurry startSession:appKey];
  33. }
  34. [FlurryAds initialize:[AdsWrapper getCurrentRootViewController]];
  35. [FlurryAds setAdDelegate:self];
  36. }
  37. - (void) showAds: (NSMutableDictionary*) info position:(int) pos
  38. {
  39. NSString* strSpaceID = [info objectForKey:@"FlurryAdsID"];
  40. if (! strSpaceID || [strSpaceID length] == 0) {
  41. OUTPUT_LOG(@"Value of 'FlurryAdsID' should not be empty");
  42. return;
  43. }
  44. NSString* strSize = [info objectForKey:@"FlurryAdsSize"];
  45. int size = [strSize intValue];
  46. if (size != 1 && size != 2 && size != 3) {
  47. OUTPUT_LOG(@"Value of 'FlurryAdsSize' should be one of '1', '2', '3' ");
  48. return;
  49. }
  50. UIViewController* controller = [AdsWrapper getCurrentRootViewController];
  51. if (controller) {
  52. [FlurryAds fetchAndDisplayAdForSpace:strSpaceID view:controller.view size:size];
  53. }
  54. }
  55. - (void) hideAds: (NSMutableDictionary*) info
  56. {
  57. NSString* strSpaceID = [info objectForKey:@"FlurryAdsID"];
  58. if (! strSpaceID || [strSpaceID length] == 0) {
  59. OUTPUT_LOG(@"Value of 'FlurryAdsID' should not be empty");
  60. return;
  61. }
  62. [FlurryAds removeAdFromSpace:strSpaceID];
  63. }
  64. - (void) queryPoints
  65. {
  66. }
  67. - (void) spendPoints: (int) points
  68. {
  69. }
  70. - (void) setDebugMode: (BOOL) isDebugMode
  71. {
  72. OUTPUT_LOG(@"Flurry setDebugMode invoked(%d)", isDebugMode);
  73. self.debug = isDebugMode;
  74. [Flurry setDebugLogEnabled:isDebugMode];
  75. if (self.debug) {
  76. [FlurryAds enableTestAds:YES];
  77. }
  78. }
  79. - (NSString*) getSDKVersion
  80. {
  81. return @"4.2.1";
  82. }
  83. - (NSString*) getPluginVersion
  84. {
  85. return @"0.2.0";
  86. }
  87. #pragma mark Interfaces for FlurryAdDelegate impl
  88. - (void) spaceDidReceiveAd:(NSString*)adSpace
  89. {
  90. [AdsWrapper onAdsResult:self withRet:kAdsReceived withMsg:@"Ads of flurry received"];
  91. }
  92. - (void) spaceDidFailToReceiveAd:(NSString*)adSpace error:(NSError *)error
  93. {
  94. NSString* strMsg = [[error userInfo] objectForKey:@"NSLocalizedDescription"];
  95. if (! strMsg) {
  96. strMsg = @"Failed to receive ads";
  97. }
  98. [AdsWrapper onAdsResult:self withRet:kUnknownError withMsg:strMsg];
  99. }
  100. - (BOOL) spaceShouldDisplay:(NSString*)adSpace interstitial:(BOOL)interstitial
  101. {
  102. [AdsWrapper onAdsResult:self withRet:kAdsShown withMsg:@"Ads will be shown"];
  103. return YES;
  104. }
  105. - (void) spaceWillDismiss:(NSString *)adSpace
  106. {
  107. [AdsWrapper onAdsResult:self withRet:kAdsDismissed withMsg:@"Ads will be dismissed"];
  108. }
  109. @end