diff --git a/platforms/ios/TDA Connect.xcodeproj/project.pbxproj b/platforms/ios/TDA Connect.xcodeproj/project.pbxproj index 2d0906b..1598a0c 100644 --- a/platforms/ios/TDA Connect.xcodeproj/project.pbxproj +++ b/platforms/ios/TDA Connect.xcodeproj/project.pbxproj @@ -5,7 +5,6 @@ }; objectVersion = 46; objects = { - /* Begin PBXBuildFile section */ 171DACF61AEAD2420089C97D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 171DACF51AEAD2420089C97D /* Images.xcassets */; }; 1D3623260D0F684500981E51 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* AppDelegate.m */; }; @@ -16,6 +15,10 @@ 302D95F214D2391D003F00A1 /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 302D95F014D2391D003F00A1 /* MainViewController.xib */; }; 305D5FD1115AB8F900A74A75 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 305D5FD0115AB8F900A74A75 /* MobileCoreServices.framework */; }; 5B1594DD16A7569C00FEF299 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B1594DC16A7569C00FEF299 /* AssetsLibrary.framework */; }; + 322E5881BAA6461A971E79DA /* CDVPluginExt.m in Sources */ = {isa = PBXBuildFile; fileRef = 58ABDD5E8EA84B678A3604A8 /* CDVPluginExt.m */; }; + C7A453660D404592BF127830 /* libCordovaGenericAd.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8FC27066CE4A4781B78B173F /* libCordovaGenericAd.a */; }; + 3F2DCB07BE944265AB83F073 /* iAdPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = A670D767EB784D57A2A0D4FB /* iAdPlugin.m */; }; + C3A0B0B99A064F1BB97947F2 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75063882C45E4F30B0C4834B /* iAd.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -55,6 +58,14 @@ EB87FDF31871DA8E0020F90C /* www */ = {isa = PBXFileReference; lastKnownFileType = folder; name = www; path = ../../www; sourceTree = ""; }; EB87FDF41871DAF40020F90C /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = ../../config.xml; sourceTree = ""; }; F840E1F0165FE0F500CFE078 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = "TDA Connect/config.xml"; sourceTree = ""; }; + 58ABDD5E8EA84B678A3604A8 /* CDVPluginExt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "CDVPluginExt.m"; path = "com.rjfun.cordova.extension/CDVPluginExt.m"; sourceTree = ""; fileEncoding = 4; }; + 8FC27066CE4A4781B78B173F /* libCordovaGenericAd.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libCordovaGenericAd.a"; path = "TDA Connect/Plugins/com.rjfun.cordova.extension/libCordovaGenericAd.a"; sourceTree = ""; fileEncoding = 4; }; + 11D4B158E0F54804989AD641 /* PluginAdapterDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "PluginAdapterDelegate.h"; path = "com.rjfun.cordova.extension/PluginAdapterDelegate.h"; sourceTree = ""; fileEncoding = 4; }; + 92653B8B09D4402ABF14132E /* CDVPluginExt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "CDVPluginExt.h"; path = "com.rjfun.cordova.extension/CDVPluginExt.h"; sourceTree = ""; fileEncoding = 4; }; + D053F63B68F344C09BE035D5 /* GenericAdPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "GenericAdPlugin.h"; path = "com.rjfun.cordova.extension/GenericAdPlugin.h"; sourceTree = ""; fileEncoding = 4; }; + A670D767EB784D57A2A0D4FB /* iAdPlugin.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "iAdPlugin.m"; path = "com.rjfun.cordova.iad/iAdPlugin.m"; sourceTree = ""; fileEncoding = 4; }; + 603CE0630DA54B1D91EA7864 /* iAdPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "iAdPlugin.h"; path = "com.rjfun.cordova.iad/iAdPlugin.h"; sourceTree = ""; fileEncoding = 4; }; + 75063882C45E4F30B0C4834B /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "iAd.framework"; path = "System/Library/Frameworks/iAd.framework"; sourceTree = SDKROOT; fileEncoding = 4; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -66,6 +77,8 @@ 301BF552109A68D80062928A /* libCordova.a in Frameworks */, 288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */, 305D5FD1115AB8F900A74A75 /* MobileCoreServices.framework in Frameworks */, + C7A453660D404592BF127830 /* libCordovaGenericAd.a in Frameworks */, + C3A0B0B99A064F1BB97947F2 /* iAd.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -137,6 +150,8 @@ 5B1594DC16A7569C00FEF299 /* AssetsLibrary.framework */, 288765FC0DF74451002DB57D /* CoreGraphics.framework */, 305D5FD0115AB8F900A74A75 /* MobileCoreServices.framework */, + 8FC27066CE4A4781B78B173F /* libCordovaGenericAd.a */, + 75063882C45E4F30B0C4834B /* iAd.framework */, ); name = Frameworks; sourceTree = ""; @@ -152,6 +167,12 @@ 307C750510C5A3420062BCA9 /* Plugins */ = { isa = PBXGroup; children = ( + 58ABDD5E8EA84B678A3604A8 /* CDVPluginExt.m */, + 11D4B158E0F54804989AD641 /* PluginAdapterDelegate.h */, + 92653B8B09D4402ABF14132E /* CDVPluginExt.h */, + D053F63B68F344C09BE035D5 /* GenericAdPlugin.h */, + A670D767EB784D57A2A0D4FB /* iAdPlugin.m */, + 603CE0630DA54B1D91EA7864 /* iAdPlugin.h */, ); name = Plugins; path = "TDA Connect/Plugins"; @@ -194,7 +215,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0510; + LastUpgradeCheck = 510; TargetAttributes = { 1D6058900D05DD3D006BFB54 = { DevelopmentTeam = 5TFUK958NL; @@ -278,6 +299,8 @@ 1D60589B0D05DD56006BFB54 /* main.m in Sources */, 1D3623260D0F684500981E51 /* AppDelegate.m in Sources */, 302D95F114D2391D003F00A1 /* MainViewController.m in Sources */, + 322E5881BAA6461A971E79DA /* CDVPluginExt.m in Sources */, + 3F2DCB07BE944265AB83F073 /* iAdPlugin.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -323,6 +346,10 @@ ); PRODUCT_NAME = "TDA Connect"; TARGETED_DEVICE_FAMILY = 2; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/TDA Connect/Plugins/com.rjfun.cordova.extension\"", + ); }; name = Debug; }; @@ -355,6 +382,10 @@ ); PRODUCT_NAME = "TDA Connect"; TARGETED_DEVICE_FAMILY = 2; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/TDA Connect/Plugins/com.rjfun.cordova.extension\"", + ); }; name = Release; }; diff --git a/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/CDVPluginExt.h b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/CDVPluginExt.h new file mode 100644 index 0000000..46f4eac --- /dev/null +++ b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/CDVPluginExt.h @@ -0,0 +1,20 @@ +// +// CDVPluginExt.h +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-28. +// +// + +#import "PluginAdapterDelegate.h" + +@interface CDVPluginExt : CDVPlugin + +@property(nonatomic, retain) id adapter; + +- (UIView*) getView; +- (UIViewController*) getViewController; +- (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr; +- (void) sendPluginResult:(CDVPluginResult *)result to:(NSString *)callbackId; + +@end diff --git a/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/CDVPluginExt.m b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/CDVPluginExt.m new file mode 100644 index 0000000..b397747 --- /dev/null +++ b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/CDVPluginExt.m @@ -0,0 +1,51 @@ +// +// CDVPluginExt.m +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-28. +// +// + +#import "CDVPluginExt.h" + +@implementation CDVPluginExt + +- (UIView*) getView +{ + if(self.adapter) return [self.adapter getView]; + else return self.webView; +} + +- (UIViewController*) getViewController +{ + if(self.adapter) return [self.adapter getViewController]; + else return self.viewController; +} + +- (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr +{ + NSLog(@"%@, %@, %@", obj, eventName, jsonStr?jsonStr:@""); + + if(self.adapter) [self.adapter fireEvent:obj event:eventName withData:jsonStr]; + else { + NSString* js; + if(obj && [obj isEqualToString:@"window"]) { + js = [NSString stringWithFormat:@"var evt=document.createEvent(\"UIEvents\");evt.initUIEvent(\"%@\",true,false,window,0);window.dispatchEvent(evt);", eventName]; + } else if(jsonStr && [jsonStr length]>0) { + js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@',%@);", eventName, jsonStr]; + } else { + js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@');", eventName]; + } + [self.commandDelegate evalJs:js]; + } +} + +- (void) sendPluginResult:(CDVPluginResult *)result to:(NSString *)callbackId +{ + if(self.adapter) [self.adapter sendPluginResult:result to:callbackId]; + else { + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; + } +} + +@end diff --git a/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/GenericAdPlugin.h b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/GenericAdPlugin.h new file mode 100644 index 0000000..f59a629 --- /dev/null +++ b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/GenericAdPlugin.h @@ -0,0 +1,133 @@ +// +// GenericAdPlugin.h +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-28. +// +// + +#import "CDVPluginExt.h" + +#define OPT_LICENSE @"license" +#define OPT_IS_TESTING @"isTesting" +#define OPT_LOG_VERBOSE @"logVerbose" + +#define OPT_ADID @"adId" +#define OPT_AUTO_SHOW @"autoShow" + +#define OPT_AD_SIZE @"adSize" +#define OPT_AD_WIDTH @"width" +#define OPT_AD_HEIGHT @"height" +#define OPT_OVERLAP @"overlap" +#define OPT_ORIENTATION_RENEW @"orientationRenew" +#define OPT_OFFSET_TOPBAR @"offsetTopBar" + +#define OPT_POSITION @"position" +#define OPT_X @"x" +#define OPT_Y @"y" + +#define OPT_AD_EXTRAS @"adExtras" + +enum { + POS_NO_CHANGE = 0, + POS_TOP_LEFT = 1, + POS_TOP_CENTER = 2, + POS_TOP_RIGHT = 3, + POS_LEFT = 4, + POS_CENTER = 5, + POS_RIGHT = 6, + POS_BOTTOM_LEFT = 7, + POS_BOTTOM_CENTER = 8, + POS_BOTTOM_RIGHT = 9, + POS_XY = 10 +}; + +#define EVENT_AD_LOADED @"onAdLoaded" +#define EVENT_AD_FAILLOAD @"onAdFailLoad" +#define EVENT_AD_PRESENT @"onAdPresent" +#define EVENT_AD_LEAVEAPP @"onAdLeaveApp" +#define EVENT_AD_DISMISS @"onAdDismiss" +#define EVENT_AD_WILLPRESENT @"onAdWillPresent" +#define EVENT_AD_WILLDISMISS @"onAdWillDismiss" + +#define ADTYPE_BANNER @"banner" +#define ADTYPE_INTERSTITIAL @"interstitial" +#define ADTYPE_NATIVE @"native" + +@interface GenericAdPlugin : CDVPluginExt + +- (void) setOptions:(CDVInvokedUrlCommand *)command; + +- (void)createBanner:(CDVInvokedUrlCommand *)command; +- (void)showBanner:(CDVInvokedUrlCommand *)command; +- (void)showBannerAtXY:(CDVInvokedUrlCommand *)command; +- (void)hideBanner:(CDVInvokedUrlCommand *)command; +- (void)removeBanner:(CDVInvokedUrlCommand *)command; + +- (void)prepareInterstitial:(CDVInvokedUrlCommand *)command; +- (void)showInterstitial:(CDVInvokedUrlCommand *)command; +- (void)removeInterstitial:(CDVInvokedUrlCommand *)command; + +@property (assign) BOOL testTraffic; +@property (assign) BOOL licenseValidated; +@property (assign) BOOL isTesting; +@property (assign) BOOL logVerbose; + +@property (nonatomic, retain) NSString* bannerId; +@property (nonatomic, retain) NSString* interstitialId; + +@property (assign) int adWidth; +@property (assign) int adHeight; +@property (assign) BOOL overlap; +@property (assign) BOOL orientationRenew; +@property (assign) BOOL offsetTopBar; + +@property (assign) int adPosition; +@property (assign) int posX; +@property (assign) int posY; + +@property (assign) BOOL autoShowBanner; +@property (assign) BOOL autoShowInterstitial; + +@property (assign) int widthOfView; + +@property (nonatomic, retain) UIView *banner; +@property (nonatomic, retain) NSObject *interstitial; + +@property (assign) BOOL bannerInited; +@property (assign) BOOL bannerVisible; + +#pragma mark virtual methods + +- (void)pluginInitialize; + +- (void) parseOptions:(NSDictionary*) options; +- (NSString*) md5:(NSString*) s; + +- (void) onOrientationChange; + +- (CGRect)statusBarFrameViewRect:(UIView*)view; +- (bool) __isLandscape; +- (void) __showBanner:(int) position atX:(int)x atY:(int)y; + +- (NSString*) __getProductShortName; +- (NSString*) __getTestBannerId; +- (NSString*) __getTestInterstitialId; + +- (UIView*) __createAdView:(NSString*)adId; +- (int) __getAdViewWidth:(UIView*)view; +- (int) __getAdViewHeight:(UIView*)view; +- (void) __loadAdView:(UIView*)view; +- (void) __pauseAdView:(UIView*)view; +- (void) __resumeAdView:(UIView*)view; +- (void) __destroyAdView:(UIView*)view; + +- (NSObject*) __createInterstitial:(NSString*)adId; +- (void) __loadInterstitial:(NSObject*)interstitial; +- (void) __showInterstitial:(NSObject*)interstitial; +- (void) __destroyInterstitial:(NSObject*)interstitial; + +- (void) fireAdEvent:(NSString*)event withType:(NSString*)adType; +- (void) fireAdErrorEvent:(NSString*)event withCode:(int)errCode withMsg:(NSString*)errMsg withType:(NSString*)adType; + +@end diff --git a/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/PluginAdapterDelegate.h b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/PluginAdapterDelegate.h new file mode 100644 index 0000000..2061d9e --- /dev/null +++ b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/PluginAdapterDelegate.h @@ -0,0 +1,22 @@ +// +// PluginAdapterDelegate.h +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-20. +// +// + +#import +#import + +@protocol PluginAdapterDelegate + +- (UIView*) getView; + +- (UIViewController*) getViewController; + +- (void) fireEvent:(NSString*)obj event:(NSString*)eventName withData:(NSString*)jsonStr; + +- (void) sendPluginResult:(CDVPluginResult*)result to:(NSString*)callbackId; + +@end diff --git a/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/libCordovaGenericAd.a b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/libCordovaGenericAd.a new file mode 100644 index 0000000..8eba1d0 Binary files /dev/null and b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.extension/libCordovaGenericAd.a differ diff --git a/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.iad/iAdPlugin.h b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.iad/iAdPlugin.h new file mode 100644 index 0000000..c04880b --- /dev/null +++ b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.iad/iAdPlugin.h @@ -0,0 +1,34 @@ +// +// iAdPlugin.h +// TestAdPlugins +// +// Created by Xie Liming on 14-11-12. +// +// + +#import "GenericAdPlugin.h" + +@interface iAdPlugin : GenericAdPlugin + +- (void)pluginInitialize; + +- (void) parseOptions:(NSDictionary *)options; + +- (NSString*) __getProductShortName; +- (NSString*) __getTestBannerId; +- (NSString*) __getTestInterstitialId; + +- (UIView*) __createAdView:(NSString*)adId; +- (int) __getAdViewWidth:(UIView*)view; +- (int) __getAdViewHeight:(UIView*)view; +- (void) __loadAdView:(UIView*)view; +- (void) __pauseAdView:(UIView*)view; +- (void) __resumeAdView:(UIView*)view; +- (void) __destroyAdView:(UIView*)view; + +- (NSObject*) __createInterstitial:(NSString*)adId; +- (void) __loadInterstitial:(NSObject*)interstitial; +- (void) __showInterstitial:(NSObject*)interstitial; +- (void) __destroyInterstitial:(NSObject*)interstitial; + +@end diff --git a/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.iad/iAdPlugin.m b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.iad/iAdPlugin.m new file mode 100644 index 0000000..6c6fba1 --- /dev/null +++ b/platforms/ios/TDA Connect/Plugins/com.rjfun.cordova.iad/iAdPlugin.m @@ -0,0 +1,197 @@ +// +// iAdPlugin.m +// TestAdPlugins +// +// Created by Xie Liming on 14-11-12. +// +// + +#import "iAdPlugin.h" + +#import + +@interface iAdPlugin() + +@end + +@implementation iAdPlugin + +- (void)pluginInitialize +{ + [super pluginInitialize]; + + // other init task here +} + +- (void) parseOptions:(NSDictionary *)options +{ + [super parseOptions:options]; + +} + +- (NSString*) __getProductShortName +{ + return @"iAd"; +} + +- (NSString*) __getDefaultBannerId +{ + return @""; +} + +- (NSString*) __getDefaultInterstitialId +{ + return @""; +} + +- (UIView*) __createAdView:(NSString*)adId +{ + ADBannerView *ad = [[ADBannerView alloc] initWithFrame:CGRectZero]; + ad.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierLandscape,ADBannerContentSizeIdentifierPortrait,nil]; + ad.currentContentSizeIdentifier = [self __isLandscape] ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait; + ad.delegate = self; + return ad; +} + +- (int) __getAdViewWidth:(UIView*)view +{ + return view.frame.size.width; +} + +- (int) __getAdViewHeight:(UIView*)view +{ + return view.frame.size.height; +} + +- (void) __loadAdView:(UIView*)view +{ + // nothing to do +} + +- (void) __pauseAdView:(UIView*)view +{ + // nothing to do +} + +- (void) __resumeAdView:(UIView*)view +{ + // nothing to do +} + +- (void) __destroyAdView:(UIView*)view +{ + // nothing to do +} + +- (NSObject*) __createInterstitial:(NSString*)adId +{ + ADInterstitialAd* ad = [[ADInterstitialAd alloc] init]; + ad.delegate = self; + return ad; +} + +- (void) __loadInterstitial:(NSObject*)interstitial +{ + // nothong to do +} + +- (void) __showInterstitial:(NSObject*)interstitial +{ + if([interstitial isKindOfClass:[ADInterstitialAd class]]) { + ADInterstitialAd* ad = (ADInterstitialAd*) interstitial; + if(ad.loaded) { + [ad presentFromViewController:[self getViewController]]; + + // no callback event, so we fire event here + [self fireAdEvent:EVENT_AD_PRESENT withType:ADTYPE_INTERSTITIAL]; + } + } +} + +- (void) __destroyInterstitial:(NSObject*)interstitial +{ + // nothing to do +} + +- (void) onOrientationChange +{ + if([self.banner isKindOfClass:[ADBannerView class]]) { + ADBannerView* ad = (ADBannerView*) self.banner; + if ([self __isLandscape]) + ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; + else + ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; + } + + [super onOrientationChange]; +} + +#pragma mark banner events + +- (void)bannerViewWillLoadAd:(ADBannerView *)banner +{ + // nothing to do +} + +- (void)bannerViewDidLoadAd:(ADBannerView *)banner +{ + [self fireAdEvent:EVENT_AD_LOADED withType:ADTYPE_BANNER]; + + if((! self.bannerVisible) && self.autoShowBanner) { + [self __showBanner:self.adPosition atX:self.posX atY:self.posY]; + } +} + +- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error +{ + [self fireAdErrorEvent:EVENT_AD_FAILLOAD withCode:(int)error.code withMsg:[error localizedDescription] withType:ADTYPE_BANNER]; +} + +- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave { + [self fireAdEvent:EVENT_AD_LEAVEAPP withType:ADTYPE_BANNER]; + return YES; +} + +- (void)bannerViewActionDidFinish:(ADBannerView *)banner +{ + [self fireAdEvent:EVENT_AD_DISMISS withType:ADTYPE_BANNER]; +} + +#pragma mark interstitial events + +- (void)interstitialAdWillLoad:(ADInterstitialAd *)interstitialAd +{ + // nothing to do +} + +- (void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd +{ + [self fireAdEvent:EVENT_AD_LOADED withType:ADTYPE_INTERSTITIAL]; + + if(self.autoShowInterstitial) { + [self __showInterstitial:self.interstitial]; + } +} + +- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error +{ + [self fireAdErrorEvent:EVENT_AD_FAILLOAD withCode:(int)error.code withMsg:[error localizedDescription] withType:ADTYPE_INTERSTITIAL]; +} + +- (BOOL)interstitialAdActionShouldBegin:(ADInterstitialAd *)banner willLeaveApplication:(BOOL)willLeave +{ + [self fireAdEvent:EVENT_AD_LEAVEAPP withType:ADTYPE_INTERSTITIAL]; + return YES; +} + +- (void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd +{ + [self fireAdEvent:EVENT_AD_DISMISS withType:ADTYPE_INTERSTITIAL]; +} + +- (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd +{ + // nonthing to do +} + +@end diff --git a/platforms/ios/TDA Connect/config.xml b/platforms/ios/TDA Connect/config.xml index 126a696..500e4cb 100755 --- a/platforms/ios/TDA Connect/config.xml +++ b/platforms/ios/TDA Connect/config.xml @@ -14,6 +14,9 @@ + + + TDA Connect Thomas Deacon Academy Desktop Connection App diff --git a/plugins/com.rjfun.cordova.extension/README.md b/plugins/com.rjfun.cordova.extension/README.md new file mode 100644 index 0000000..ec7df2c --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/README.md @@ -0,0 +1,116 @@ + +# Cordova Plugin Common Extension # + +Extend the Cordova plugin base class with adapter interface. + +Plugin written based on this interface, may also be reused for Unity, Cocos2d-X, and other frameworks. + +# Purpose # + +Make Cordova Plugins reusable. + +To use mobile device native functionalities and integrate 3rd-party SDKs, mobile developers are writting hundreds plugins for Cordova, Unity, Cocos2d-X, and other frameworks. + +Can they be reused? Yes, it's possible. + +Cordova plugin manager is bridging function call between javascript and native languages, actually, it can be ported to bridge with C, C++, C#, then it can be reused for Unity, Cocos2d-X and other frameworks. + +See: +* Adapter for Cordova, (implemented as default, [Android](https://github.com/floatinghotpot/cordova-plugin-ext/blob/master/src/android/CordovaPluginExt.java) / [iOS](https://github.com/floatinghotpot/cordova-extension/blob/master/src/ios/CDVPluginExt.m) ) +* [Adapter for Unity](https://github.com/floatinghotpot/cordova-extension/tree/master/unity) +* [Adapter for Cocos2d-X](https://github.com/floatinghotpot/cordova-extension/tree/master/cocos2dx) + +# How it works ? # + +Android implementation: + +```java +public interface PluginAdapterDelegate { + // context + public Activity getActivity(); + public View getView(); + // send message from plugin to container on events + public void fireEvent(String obj, String eventName, String jsonData); + // send call result + public void sendPluginResult(PluginResult result, CallbackContext context); +} + +public class CordovaPluginExt extends CordovaPlugin implements PluginAdapterDelegate { + protected PluginAdapterDelegate adapter = null; +} + + +``` + +iOS implementation: + +```objective-c +@protocol PluginAdapterDelegate + // context +- (UIView*) getView; +- (UIViewController*) getViewController; + // send message from plugin to container on events +- (void) fireEvent:(NSString*)obj event:(NSString*)eventName withData:(NSString*)jsonStr; + // send call result +- (void) sendPluginResult:(CDVPluginResult*)result to:(NSString*)callbackId; +@end + +@interface CDVPluginExt : CDVPlugin +@property(nonatomic, retain) id adapter; +@end + + +``` + +Other platform: + +Not implemented yet. + +# How to Use? # + +This plugin is used as dependency of other plugins, for plugin developers only. + +In your plugin.xml, add it as dependency: + +```xml + +``` + +Inherit Cordova Plugin Ext: + +Plugin for Android: + +```java +import com.rjfun.cordova.ext.*; + +// your plugin class +public class YourPluginClass extends CordovaPluginExt { + // implement the method, call the API defined in PluginAdapterDelegate + public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException; +} +``` + +Plugin for iOS: +```objective-c +#import "CDVCordovaExt.h" + +// your plugin class +@interface YourPluginClass : CDVPluginExt + // implement the method, call the API defined in PluginAdapterDelegate +- (void) your_method:(CDVInvokedUrlCommand *)command; +@end +``` + +# Related Projects # + +To use the plugin in other frameworks, following plugin managers are required. + +* [Cordova Plugin Manager for Unity](https://github.com/floatinghotpot/cordova-for-unity) +* [Cordova Plugin Manager for Cocos2d-X](https://github.com/floatinghotpot/cordova-for-cocos2dx) + +# Credit # + +This project is created by Raymond Xie. + +If you are interested in this project, welcome to join and contribute. + diff --git a/plugins/com.rjfun.cordova.extension/cocos2dx/TODO b/plugins/com.rjfun.cordova.extension/cocos2dx/TODO new file mode 100644 index 0000000..e69de29 diff --git a/plugins/com.rjfun.cordova.extension/package.json b/plugins/com.rjfun.cordova.extension/package.json new file mode 100644 index 0000000..567a40c --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/package.json @@ -0,0 +1,22 @@ +{ + "version": "1.0.6", + "name": "com.rjfun.cordova.extension", + "cordova_name": "Cordova Plugin Extension", + "description": "Common interface and reusable code, as dependency of other plugins", + "license": "MIT", + "repo": "https://github.com/floatinghotpot/cordova-extension.git", + "issue": "https://github.com/floatinghotpot/cordova-extension/issues", + "keywords": [ + "rjfun" + ], + "platforms": [ + "android", + "ios" + ], + "engines": [ + { + "name": "cordova", + "version": ">=3.0" + } + ] +} \ No newline at end of file diff --git a/plugins/com.rjfun.cordova.extension/plugin.xml b/plugins/com.rjfun.cordova.extension/plugin.xml new file mode 100644 index 0000000..87b03c0 --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/plugin.xml @@ -0,0 +1,36 @@ + + + + + Cordova Plugin Extension + Common interface and reusable code, as dependency of other plugins + Liming Xie + MIT + rjfun + https://github.com/floatinghotpot/cordova-extension.git + https://github.com/floatinghotpot/cordova-extension/issues + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/com.rjfun.cordova.extension/src/android/CordovaPluginExt.java b/plugins/com.rjfun.cordova.extension/src/android/CordovaPluginExt.java new file mode 100644 index 0000000..65c85dd --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/src/android/CordovaPluginExt.java @@ -0,0 +1,80 @@ +package com.rjfun.cordova.ext; + +import java.lang.reflect.Method; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.PluginResult; + +import android.app.Activity; +import android.view.View; + +public class CordovaPluginExt extends CordovaPlugin implements PluginAdapterDelegate { + + protected PluginAdapterDelegate adapter = null; + + public void setAdapter(PluginAdapterDelegate theAdapter) { + adapter = theAdapter; + } + + public PluginAdapterDelegate getAdapter() { + return adapter; + } + + @Override + public View getView() { + if(adapter != null) return adapter.getView(); + else { + // Cordova 3.x, class CordovaWebView extends WebView, -> AbsoluteLayout -> ViewGroup -> View -> Object + if(View.class.isAssignableFrom(CordovaWebView.class)) { + return (View) webView; + } + + // Cordova 4.0.0-dev, interface CordovaWebView { View getView(); } + try { + Method getViewMethod = CordovaWebView.class.getMethod("getView", (Class[]) null); + if(getViewMethod != null) { + Object[] args = {}; + return (View) getViewMethod.invoke(webView, args); + } + } catch (Exception e) { + } + + // or else we return the root view, but this should not happen + return getActivity().getWindow().getDecorView().findViewById(android.R.id.content); + } + } + + @Override + public Activity getActivity() { + if(adapter != null) return adapter.getActivity(); + return cordova.getActivity(); + } + + @Override + public void fireEvent(String obj, String eventName, String jsonData) { + if(adapter != null) adapter.fireEvent(obj, eventName, jsonData); + else { + String js; + if("window".equals(obj)) { + js = "var evt=document.createEvent('UIEvents');evt.initUIEvent('" + eventName + "',true,false,window,0);window.dispatchEvent(evt);"; + } else { + js = "javascript:cordova.fireDocumentEvent('" + eventName + "'"; + if(jsonData != null) { + js += "," + jsonData; + } + js += ");"; + } + webView.loadUrl(js); + } + } + + @Override + public void sendPluginResult(PluginResult result, CallbackContext context) { + if(adapter != null) adapter.sendPluginResult(result, context); + else { + context.sendPluginResult(result); + } + } +} diff --git a/plugins/com.rjfun.cordova.extension/src/android/PluginAdapterDelegate.java b/plugins/com.rjfun.cordova.extension/src/android/PluginAdapterDelegate.java new file mode 100644 index 0000000..0398043 --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/src/android/PluginAdapterDelegate.java @@ -0,0 +1,20 @@ +package com.rjfun.cordova.ext; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.PluginResult; + +import android.app.Activity; +import android.view.View; + +public interface PluginAdapterDelegate { + // context + public Activity getActivity(); + public View getView(); + + // send message from plugin to container on events + public void fireEvent(String obj, String eventName, String jsonData); + + // send call result + public void sendPluginResult(PluginResult result, CallbackContext context); +} + diff --git a/plugins/com.rjfun.cordova.extension/src/android/cordova-generic-ad.jar b/plugins/com.rjfun.cordova.extension/src/android/cordova-generic-ad.jar new file mode 100644 index 0000000..aa24215 Binary files /dev/null and b/plugins/com.rjfun.cordova.extension/src/android/cordova-generic-ad.jar differ diff --git a/plugins/com.rjfun.cordova.extension/src/ios/CDVPluginExt.h b/plugins/com.rjfun.cordova.extension/src/ios/CDVPluginExt.h new file mode 100644 index 0000000..46f4eac --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/src/ios/CDVPluginExt.h @@ -0,0 +1,20 @@ +// +// CDVPluginExt.h +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-28. +// +// + +#import "PluginAdapterDelegate.h" + +@interface CDVPluginExt : CDVPlugin + +@property(nonatomic, retain) id adapter; + +- (UIView*) getView; +- (UIViewController*) getViewController; +- (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr; +- (void) sendPluginResult:(CDVPluginResult *)result to:(NSString *)callbackId; + +@end diff --git a/plugins/com.rjfun.cordova.extension/src/ios/CDVPluginExt.m b/plugins/com.rjfun.cordova.extension/src/ios/CDVPluginExt.m new file mode 100644 index 0000000..b397747 --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/src/ios/CDVPluginExt.m @@ -0,0 +1,51 @@ +// +// CDVPluginExt.m +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-28. +// +// + +#import "CDVPluginExt.h" + +@implementation CDVPluginExt + +- (UIView*) getView +{ + if(self.adapter) return [self.adapter getView]; + else return self.webView; +} + +- (UIViewController*) getViewController +{ + if(self.adapter) return [self.adapter getViewController]; + else return self.viewController; +} + +- (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr +{ + NSLog(@"%@, %@, %@", obj, eventName, jsonStr?jsonStr:@""); + + if(self.adapter) [self.adapter fireEvent:obj event:eventName withData:jsonStr]; + else { + NSString* js; + if(obj && [obj isEqualToString:@"window"]) { + js = [NSString stringWithFormat:@"var evt=document.createEvent(\"UIEvents\");evt.initUIEvent(\"%@\",true,false,window,0);window.dispatchEvent(evt);", eventName]; + } else if(jsonStr && [jsonStr length]>0) { + js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@',%@);", eventName, jsonStr]; + } else { + js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@');", eventName]; + } + [self.commandDelegate evalJs:js]; + } +} + +- (void) sendPluginResult:(CDVPluginResult *)result to:(NSString *)callbackId +{ + if(self.adapter) [self.adapter sendPluginResult:result to:callbackId]; + else { + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; + } +} + +@end diff --git a/plugins/com.rjfun.cordova.extension/src/ios/GenericAdPlugin.h b/plugins/com.rjfun.cordova.extension/src/ios/GenericAdPlugin.h new file mode 100644 index 0000000..f59a629 --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/src/ios/GenericAdPlugin.h @@ -0,0 +1,133 @@ +// +// GenericAdPlugin.h +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-28. +// +// + +#import "CDVPluginExt.h" + +#define OPT_LICENSE @"license" +#define OPT_IS_TESTING @"isTesting" +#define OPT_LOG_VERBOSE @"logVerbose" + +#define OPT_ADID @"adId" +#define OPT_AUTO_SHOW @"autoShow" + +#define OPT_AD_SIZE @"adSize" +#define OPT_AD_WIDTH @"width" +#define OPT_AD_HEIGHT @"height" +#define OPT_OVERLAP @"overlap" +#define OPT_ORIENTATION_RENEW @"orientationRenew" +#define OPT_OFFSET_TOPBAR @"offsetTopBar" + +#define OPT_POSITION @"position" +#define OPT_X @"x" +#define OPT_Y @"y" + +#define OPT_AD_EXTRAS @"adExtras" + +enum { + POS_NO_CHANGE = 0, + POS_TOP_LEFT = 1, + POS_TOP_CENTER = 2, + POS_TOP_RIGHT = 3, + POS_LEFT = 4, + POS_CENTER = 5, + POS_RIGHT = 6, + POS_BOTTOM_LEFT = 7, + POS_BOTTOM_CENTER = 8, + POS_BOTTOM_RIGHT = 9, + POS_XY = 10 +}; + +#define EVENT_AD_LOADED @"onAdLoaded" +#define EVENT_AD_FAILLOAD @"onAdFailLoad" +#define EVENT_AD_PRESENT @"onAdPresent" +#define EVENT_AD_LEAVEAPP @"onAdLeaveApp" +#define EVENT_AD_DISMISS @"onAdDismiss" +#define EVENT_AD_WILLPRESENT @"onAdWillPresent" +#define EVENT_AD_WILLDISMISS @"onAdWillDismiss" + +#define ADTYPE_BANNER @"banner" +#define ADTYPE_INTERSTITIAL @"interstitial" +#define ADTYPE_NATIVE @"native" + +@interface GenericAdPlugin : CDVPluginExt + +- (void) setOptions:(CDVInvokedUrlCommand *)command; + +- (void)createBanner:(CDVInvokedUrlCommand *)command; +- (void)showBanner:(CDVInvokedUrlCommand *)command; +- (void)showBannerAtXY:(CDVInvokedUrlCommand *)command; +- (void)hideBanner:(CDVInvokedUrlCommand *)command; +- (void)removeBanner:(CDVInvokedUrlCommand *)command; + +- (void)prepareInterstitial:(CDVInvokedUrlCommand *)command; +- (void)showInterstitial:(CDVInvokedUrlCommand *)command; +- (void)removeInterstitial:(CDVInvokedUrlCommand *)command; + +@property (assign) BOOL testTraffic; +@property (assign) BOOL licenseValidated; +@property (assign) BOOL isTesting; +@property (assign) BOOL logVerbose; + +@property (nonatomic, retain) NSString* bannerId; +@property (nonatomic, retain) NSString* interstitialId; + +@property (assign) int adWidth; +@property (assign) int adHeight; +@property (assign) BOOL overlap; +@property (assign) BOOL orientationRenew; +@property (assign) BOOL offsetTopBar; + +@property (assign) int adPosition; +@property (assign) int posX; +@property (assign) int posY; + +@property (assign) BOOL autoShowBanner; +@property (assign) BOOL autoShowInterstitial; + +@property (assign) int widthOfView; + +@property (nonatomic, retain) UIView *banner; +@property (nonatomic, retain) NSObject *interstitial; + +@property (assign) BOOL bannerInited; +@property (assign) BOOL bannerVisible; + +#pragma mark virtual methods + +- (void)pluginInitialize; + +- (void) parseOptions:(NSDictionary*) options; +- (NSString*) md5:(NSString*) s; + +- (void) onOrientationChange; + +- (CGRect)statusBarFrameViewRect:(UIView*)view; +- (bool) __isLandscape; +- (void) __showBanner:(int) position atX:(int)x atY:(int)y; + +- (NSString*) __getProductShortName; +- (NSString*) __getTestBannerId; +- (NSString*) __getTestInterstitialId; + +- (UIView*) __createAdView:(NSString*)adId; +- (int) __getAdViewWidth:(UIView*)view; +- (int) __getAdViewHeight:(UIView*)view; +- (void) __loadAdView:(UIView*)view; +- (void) __pauseAdView:(UIView*)view; +- (void) __resumeAdView:(UIView*)view; +- (void) __destroyAdView:(UIView*)view; + +- (NSObject*) __createInterstitial:(NSString*)adId; +- (void) __loadInterstitial:(NSObject*)interstitial; +- (void) __showInterstitial:(NSObject*)interstitial; +- (void) __destroyInterstitial:(NSObject*)interstitial; + +- (void) fireAdEvent:(NSString*)event withType:(NSString*)adType; +- (void) fireAdErrorEvent:(NSString*)event withCode:(int)errCode withMsg:(NSString*)errMsg withType:(NSString*)adType; + +@end diff --git a/plugins/com.rjfun.cordova.extension/src/ios/PluginAdapterDelegate.h b/plugins/com.rjfun.cordova.extension/src/ios/PluginAdapterDelegate.h new file mode 100644 index 0000000..2061d9e --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/src/ios/PluginAdapterDelegate.h @@ -0,0 +1,22 @@ +// +// PluginAdapterDelegate.h +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-20. +// +// + +#import +#import + +@protocol PluginAdapterDelegate + +- (UIView*) getView; + +- (UIViewController*) getViewController; + +- (void) fireEvent:(NSString*)obj event:(NSString*)eventName withData:(NSString*)jsonStr; + +- (void) sendPluginResult:(CDVPluginResult*)result to:(NSString*)callbackId; + +@end diff --git a/plugins/com.rjfun.cordova.extension/src/ios/libCordovaGenericAd.a b/plugins/com.rjfun.cordova.extension/src/ios/libCordovaGenericAd.a new file mode 100644 index 0000000..8eba1d0 Binary files /dev/null and b/plugins/com.rjfun.cordova.extension/src/ios/libCordovaGenericAd.a differ diff --git a/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.h b/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.h new file mode 100644 index 0000000..b7afc73 --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.h @@ -0,0 +1,21 @@ +// +// PluginAdapterUnity.h +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-31. +// +// + +#import "PluginAdapterDelegate.h" + +@interface PluginAdapterUnity : NSObject + +- (UIView*) getView; + +- (UIViewController*) getViewController; + +- (void) fireEvent:(NSString*)obj event:(NSString*)eventName withData:(NSString*)jsonStr; + +- (void) sendPluginResult:(CDVPluginResult*)result to:(NSString*)callbackId; + +@end diff --git a/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.java b/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.java new file mode 100644 index 0000000..9991059 --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.java @@ -0,0 +1,55 @@ +package com.rjfun.cordova.unity; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.PluginResult; + +import android.app.Activity; +import android.view.View; +import android.view.ViewGroup.LayoutParams; +import android.widget.RelativeLayout; + +import com.rjfun.cordova.ext.PluginAdapterDelegate; +import com.unity3d.player.UnityPlayer; + +public class PluginAdapterUnity implements PluginAdapterDelegate { + + private static RelativeLayout rootLayout = null; + private static View mainView = null; + + @Override + public Activity getActivity() { + return UnityPlayer.currentActivity; + } + + @Override + public View getView() { + Activity act = getActivity(); + // mock Cordova's webView and the layout container + if(rootLayout == null) { + rootLayout = new RelativeLayout(act); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + getActivity().addContentView(rootLayout, params); + } + if(mainView == null) { + mainView = new RelativeLayout(act); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + rootLayout.addView(mainView, params); + } + return mainView; + } + + @Override + public void fireEvent(String obj, String eventName, String jsonData) { + UnityPlayer.UnitySendMessage(obj, eventName, jsonData); + } + + @Override + public void sendPluginResult(PluginResult result, CallbackContext context) { + String jsonData = "{\"callbackId\":\"" + context.getCallbackId() + + "\",\"status\":" + result.getStatus() + + ",\"keepCallback\":" + (result.getKeepCallback()?1:0) + + ",\"data\":" + result.getMessage() + + "}"; + UnityPlayer.UnitySendMessage("Cordova", "onExecuteCallback", jsonData); + } +} diff --git a/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.m b/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.m new file mode 100644 index 0000000..dee2c24 --- /dev/null +++ b/plugins/com.rjfun.cordova.extension/unity/PluginAdapterUnity.m @@ -0,0 +1,50 @@ +// +// PluginAdapterUnity.m +// TestAdMobCombo +// +// Created by Xie Liming on 14-10-31. +// +// + +#import "PluginAdapterUnity.h" +/* +void UnityPause( bool pause ); + +void UnitySendMessage( const char * className, const char * methodName, const char * param ); + +UIViewController *UnityGetGLViewController(); + +@implementation PluginAdapterUnity + +- (UIView*) getView +{ + return [self getViewController].view; +} + +- (UIViewController*) getViewController +{ + return UnityGetGLViewController(); +} + +- (void) fireEvent:(NSString*)obj event:(NSString*)eventName withData:(NSString*)jsonStr +{ + const char * className = obj ? obj.UTF8String : "Cordova"; + const char * methodName = eventName ? eventName.UTF8String : "onEvent"; + const char * param = jsonStr ? jsonStr.UTF8String : ""; + + UnitySendMessage(className, methodName, param); +} + +- (void) sendPluginResult:(CDVPluginResult*)result to:(NSString*)callbackId +{ + NSMutableString* jsonData = [NSMutableString string]; + [jsonData appendFormat: @"{\"callbackId\":\"%@\",\"status\":%d, \"keepCallback\":%d", callbackId, (int)result.status, (int)result.keepCallback ]; + [jsonData appendString: @",\"data\":"]; + [jsonData appendString: [result argumentsAsJSON]]; + [jsonData appendString: @"}"]; + + UnitySendMessage("Cordova", "onExecuteCallback", jsonData.UTF8String); +} + +@end +*/ \ No newline at end of file diff --git a/plugins/com.rjfun.cordova.iad/README.md b/plugins/com.rjfun.cordova.iad/README.md new file mode 100644 index 0000000..25c3ce6 --- /dev/null +++ b/plugins/com.rjfun.cordova.iad/README.md @@ -0,0 +1,136 @@ +# iAd Plugin Pro # + +Present Apple iAd in Mobile App/Games natively from JavaScript. + +Highlights: +- [x] Easy-to-use APIs. Display Ad with single line of Js code. +- [x] Support Banner, Interstitial Ad. +- [x] Multiple banner size, also support custom size. +- [x] Fixed and overlapped mode. +- [x] Auto fit on orientation change. +- [x] Same API with other RjFun Ad plugins, easily switch to other Ad networks. + +Compatible with: + +* Cordova CLI, v3.5+ +* Intel XDK and Crosswalk, r1095+ +* IBM Worklight, v6.2+ + +## How to use? ## + +If use with Cordova CLI: +``` +cordova plugin add com.rjfun.cordova.iad +``` + +If use with Intel XDK: +Project -> CORDOVA 3.X HYBRID MOBILE APP SETTINGS -> PLUGINS AND PERMISSIONS -> Third-Party Plugins -> +Add a Third-Party Plugin -> Get Plugin from the Web, input: +``` +Name: iAdPluginPro +Plugin ID: com.rjfun.cordova.iad +[x] Plugin is located in the Apache Cordova Plugins Registry +``` +## Quick Start ## + +Before using the plugin in your project, please verify the plugin by build the demo index.html coming with the plugin: + +```bash +cordova create test1 com.rjfun.test1 test1; +cd test1; +cordova platform add ios; +cordova plugin add com.rjfun.cordova.iad; +rm -r www/*; +cp -r plugins/com.rjfun.cordova.iad/test/* www/; +cordova prepare; +cordova run ios; +``` + +## Quick Start Example Code ## + +Step 1: Create a banner with single line of javascript + +```javascript +// it will display smart banner at top center, using the default options +if(iAd) iAd.createBanner( { autoShow:true } ); +``` + +Or, show the banner Ad in some other way: + +```javascript +// or, show a default banner at bottom +if(iAd) iAd.createBanner( { + position:iAd.AD_POSITION.BOTTOM_CENTER, + autoShow:true +} ); +``` + +Step 2: Prepare an interstitial, and show it when needed + +** Notice: iAd interstitial Ad only supports iPad. + +```javascript +// preppare and load ad resource in background, e.g. at begining of game level +if(iAd) iAd.prepareInterstitial( { autoShow:false } ); + +// show the interstitial later, e.g. at end of game level +if(iAd) iAd.showInterstitial(); +``` + +## Javascript API Overview ## + +Methods: +```javascript +// set default value for other methods +setOptions(options, success, fail); +// for banner +createBanner(options, success, fail); +removeBanner(); +showBanner(position); +showBannerAtXY(x, y); +hideBanner(); +// for interstitial +prepareInterstitial(options, success, fail); +showInterstitial(); +``` + +## Detailed Documentation ## + +The APIs, Events and Options are detailed documented. + +Read the detailed API Reference Documentation [English](https://github.com/floatinghotpot/cordova-iad-pro/wiki). + +## FAQ ## + +If encounter problem when using the plugin, please read the [FAQ](https://github.com/floatinghotpot/cordova-iad-pro/wiki/FAQ) first. + +## Full Example Code ## + +This MobFox Plugin Pro offers the most flexibility and many options. + +Check the [test/index.html] (https://github.com/floatinghotpot/cordova-iad-pro/blob/master/test/index.html). + +## Screenshots ## + +iPhone Portrait | iPhone Landscape +-------|---------- +![ScreenShot](docs/iphone_portrait.jpg) | ![ScreenShot](docs/iphone_landscape.jpg) + iPad Banner | iPad Interstitial +![ScreenShot](docs/ipad_banner.jpg) | ![ScreenShot](docs/ipad_interstitial.jpg) + +Ad PluginPro series for the world leading Mobile Ad services: + +* [GoogleAds PluginPro](https://github.com/floatinghotpot/cordova-admob-pro), for Google AdMob/DoubleClick. +* [iAd PluginPro](https://github.com/floatinghotpot/cordova-iad-pro), for Apple iAd. +* [FacebookAds PluginPro](https://github.com/floatinghotpot/cordova-plugin-facebookads), for Facebook Audience Network. +* [FlurryAds PluginPro](https://github.com/floatinghotpot/cordova-plugin-flurry), for Flurry Ads. +* [mMedia PluginPro](https://github.com/floatinghotpot/cordova-plugin-mmedia), for Millennial Meida. +* [MobFox PluginPro](https://github.com/floatinghotpot/cordova-mobfox-pro), for MobFox. +* [MoPub PluginPro](https://github.com/floatinghotpot/cordova-plugin-mopub), for MoPub. + +More Cordova/PhoneGap plugins by Raymond Xie, [find them in plugin registry](http://plugins.cordova.io/#/search?search=rjfun). + +If use in commercial project or need prompt support, please [buy a license](http://rjfun.github.io/), you will be served with high priority. + +Project outsourcing and consulting service is also available. Please [contact us](mailto:rjfun.mobile@gmail.com) if you have the business needs. + diff --git a/plugins/com.rjfun.cordova.iad/docs/ipad_banner.jpg b/plugins/com.rjfun.cordova.iad/docs/ipad_banner.jpg new file mode 100644 index 0000000..43a8a05 Binary files /dev/null and b/plugins/com.rjfun.cordova.iad/docs/ipad_banner.jpg differ diff --git a/plugins/com.rjfun.cordova.iad/docs/ipad_interstitial.jpg b/plugins/com.rjfun.cordova.iad/docs/ipad_interstitial.jpg new file mode 100644 index 0000000..c28e6d5 Binary files /dev/null and b/plugins/com.rjfun.cordova.iad/docs/ipad_interstitial.jpg differ diff --git a/plugins/com.rjfun.cordova.iad/docs/iphone_landscape.jpg b/plugins/com.rjfun.cordova.iad/docs/iphone_landscape.jpg new file mode 100644 index 0000000..daedc76 Binary files /dev/null and b/plugins/com.rjfun.cordova.iad/docs/iphone_landscape.jpg differ diff --git a/plugins/com.rjfun.cordova.iad/docs/iphone_portrait.jpg b/plugins/com.rjfun.cordova.iad/docs/iphone_portrait.jpg new file mode 100644 index 0000000..7d801e5 Binary files /dev/null and b/plugins/com.rjfun.cordova.iad/docs/iphone_portrait.jpg differ diff --git a/plugins/com.rjfun.cordova.iad/iAdPlugin.h b/plugins/com.rjfun.cordova.iad/iAdPlugin.h new file mode 100644 index 0000000..c04880b --- /dev/null +++ b/plugins/com.rjfun.cordova.iad/iAdPlugin.h @@ -0,0 +1,34 @@ +// +// iAdPlugin.h +// TestAdPlugins +// +// Created by Xie Liming on 14-11-12. +// +// + +#import "GenericAdPlugin.h" + +@interface iAdPlugin : GenericAdPlugin + +- (void)pluginInitialize; + +- (void) parseOptions:(NSDictionary *)options; + +- (NSString*) __getProductShortName; +- (NSString*) __getTestBannerId; +- (NSString*) __getTestInterstitialId; + +- (UIView*) __createAdView:(NSString*)adId; +- (int) __getAdViewWidth:(UIView*)view; +- (int) __getAdViewHeight:(UIView*)view; +- (void) __loadAdView:(UIView*)view; +- (void) __pauseAdView:(UIView*)view; +- (void) __resumeAdView:(UIView*)view; +- (void) __destroyAdView:(UIView*)view; + +- (NSObject*) __createInterstitial:(NSString*)adId; +- (void) __loadInterstitial:(NSObject*)interstitial; +- (void) __showInterstitial:(NSObject*)interstitial; +- (void) __destroyInterstitial:(NSObject*)interstitial; + +@end diff --git a/plugins/com.rjfun.cordova.iad/iAdPlugin.m b/plugins/com.rjfun.cordova.iad/iAdPlugin.m new file mode 100644 index 0000000..6c6fba1 --- /dev/null +++ b/plugins/com.rjfun.cordova.iad/iAdPlugin.m @@ -0,0 +1,197 @@ +// +// iAdPlugin.m +// TestAdPlugins +// +// Created by Xie Liming on 14-11-12. +// +// + +#import "iAdPlugin.h" + +#import + +@interface iAdPlugin() + +@end + +@implementation iAdPlugin + +- (void)pluginInitialize +{ + [super pluginInitialize]; + + // other init task here +} + +- (void) parseOptions:(NSDictionary *)options +{ + [super parseOptions:options]; + +} + +- (NSString*) __getProductShortName +{ + return @"iAd"; +} + +- (NSString*) __getDefaultBannerId +{ + return @""; +} + +- (NSString*) __getDefaultInterstitialId +{ + return @""; +} + +- (UIView*) __createAdView:(NSString*)adId +{ + ADBannerView *ad = [[ADBannerView alloc] initWithFrame:CGRectZero]; + ad.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierLandscape,ADBannerContentSizeIdentifierPortrait,nil]; + ad.currentContentSizeIdentifier = [self __isLandscape] ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait; + ad.delegate = self; + return ad; +} + +- (int) __getAdViewWidth:(UIView*)view +{ + return view.frame.size.width; +} + +- (int) __getAdViewHeight:(UIView*)view +{ + return view.frame.size.height; +} + +- (void) __loadAdView:(UIView*)view +{ + // nothing to do +} + +- (void) __pauseAdView:(UIView*)view +{ + // nothing to do +} + +- (void) __resumeAdView:(UIView*)view +{ + // nothing to do +} + +- (void) __destroyAdView:(UIView*)view +{ + // nothing to do +} + +- (NSObject*) __createInterstitial:(NSString*)adId +{ + ADInterstitialAd* ad = [[ADInterstitialAd alloc] init]; + ad.delegate = self; + return ad; +} + +- (void) __loadInterstitial:(NSObject*)interstitial +{ + // nothong to do +} + +- (void) __showInterstitial:(NSObject*)interstitial +{ + if([interstitial isKindOfClass:[ADInterstitialAd class]]) { + ADInterstitialAd* ad = (ADInterstitialAd*) interstitial; + if(ad.loaded) { + [ad presentFromViewController:[self getViewController]]; + + // no callback event, so we fire event here + [self fireAdEvent:EVENT_AD_PRESENT withType:ADTYPE_INTERSTITIAL]; + } + } +} + +- (void) __destroyInterstitial:(NSObject*)interstitial +{ + // nothing to do +} + +- (void) onOrientationChange +{ + if([self.banner isKindOfClass:[ADBannerView class]]) { + ADBannerView* ad = (ADBannerView*) self.banner; + if ([self __isLandscape]) + ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; + else + ad.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; + } + + [super onOrientationChange]; +} + +#pragma mark banner events + +- (void)bannerViewWillLoadAd:(ADBannerView *)banner +{ + // nothing to do +} + +- (void)bannerViewDidLoadAd:(ADBannerView *)banner +{ + [self fireAdEvent:EVENT_AD_LOADED withType:ADTYPE_BANNER]; + + if((! self.bannerVisible) && self.autoShowBanner) { + [self __showBanner:self.adPosition atX:self.posX atY:self.posY]; + } +} + +- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error +{ + [self fireAdErrorEvent:EVENT_AD_FAILLOAD withCode:(int)error.code withMsg:[error localizedDescription] withType:ADTYPE_BANNER]; +} + +- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave { + [self fireAdEvent:EVENT_AD_LEAVEAPP withType:ADTYPE_BANNER]; + return YES; +} + +- (void)bannerViewActionDidFinish:(ADBannerView *)banner +{ + [self fireAdEvent:EVENT_AD_DISMISS withType:ADTYPE_BANNER]; +} + +#pragma mark interstitial events + +- (void)interstitialAdWillLoad:(ADInterstitialAd *)interstitialAd +{ + // nothing to do +} + +- (void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd +{ + [self fireAdEvent:EVENT_AD_LOADED withType:ADTYPE_INTERSTITIAL]; + + if(self.autoShowInterstitial) { + [self __showInterstitial:self.interstitial]; + } +} + +- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error +{ + [self fireAdErrorEvent:EVENT_AD_FAILLOAD withCode:(int)error.code withMsg:[error localizedDescription] withType:ADTYPE_INTERSTITIAL]; +} + +- (BOOL)interstitialAdActionShouldBegin:(ADInterstitialAd *)banner willLeaveApplication:(BOOL)willLeave +{ + [self fireAdEvent:EVENT_AD_LEAVEAPP withType:ADTYPE_INTERSTITIAL]; + return YES; +} + +- (void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd +{ + [self fireAdEvent:EVENT_AD_DISMISS withType:ADTYPE_INTERSTITIAL]; +} + +- (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd +{ + // nonthing to do +} + +@end diff --git a/plugins/com.rjfun.cordova.iad/libCordovaiAd.a b/plugins/com.rjfun.cordova.iad/libCordovaiAd.a new file mode 100644 index 0000000..2345549 Binary files /dev/null and b/plugins/com.rjfun.cordova.iad/libCordovaiAd.a differ diff --git a/plugins/com.rjfun.cordova.iad/package.json b/plugins/com.rjfun.cordova.iad/package.json new file mode 100644 index 0000000..9a9dbc6 --- /dev/null +++ b/plugins/com.rjfun.cordova.iad/package.json @@ -0,0 +1,23 @@ +{ + "version": "2.0.4", + "name": "com.rjfun.cordova.iad", + "cordova_name": "iAd PluginPro", + "description": "Single line javascript to show iAd banner and interstitial", + "license": "MIT", + "repo": "https://github.com/floatinghotpot/cordova-iad-pro.git", + "issue": "https://github.com/floatinghotpot/cordova-iad-pro/issues", + "keywords": [ + "rjfun", + "ad", + "iad" + ], + "platforms": [ + "ios" + ], + "engines": [ + { + "name": "cordova", + "version": ">=3.0" + } + ] +} \ No newline at end of file diff --git a/plugins/com.rjfun.cordova.iad/plugin.xml b/plugins/com.rjfun.cordova.iad/plugin.xml new file mode 100644 index 0000000..6117275 --- /dev/null +++ b/plugins/com.rjfun.cordova.iad/plugin.xml @@ -0,0 +1,38 @@ + + + + + iAd PluginPro + Single line javascript to show iAd banner and interstitial + Liming Xie + MIT + rjfun,ad,iad + https://github.com/floatinghotpot/cordova-iad-pro.git + https://github.com/floatinghotpot/cordova-iad-pro/issues + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/com.rjfun.cordova.iad/test/index.html b/plugins/com.rjfun.cordova.iad/test/index.html new file mode 100644 index 0000000..af88d8e --- /dev/null +++ b/plugins/com.rjfun.cordova.iad/test/index.html @@ -0,0 +1,154 @@ + + + + + + +Hello World + + + + + +
+

Demo for iAd Plugin

+ Banner
overlap
+ + + +
+ + +
(,) + +
+ + +
+ +

Interstitial

+ auto show when ready
+ + +
+
+ + diff --git a/plugins/com.rjfun.cordova.iad/www/iAd.js b/plugins/com.rjfun.cordova.iad/www/iAd.js new file mode 100644 index 0000000..1e4b221 --- /dev/null +++ b/plugins/com.rjfun.cordova.iad/www/iAd.js @@ -0,0 +1,106 @@ + +var argscheck = require('cordova/argscheck'), + exec = require('cordova/exec'); + +var iadExport = {}; + +iadExport.AD_SIZE = { + SMART_BANNER: 'SMART_BANNER', + BANNER: 'BANNER', + MEDIUM_RECTANGLE: 'MEDIUM_RECTANGLE', + FULL_BANNER: 'FULL_BANNER', + LEADERBOARD: 'LEADERBOARD', + SKYSCRAPER: 'SKYSCRAPER' +}; + +iadExport.AD_POSITION = { + NO_CHANGE: 0, + TOP_LEFT: 1, + TOP_CENTER: 2, + TOP_RIGHT: 3, + LEFT: 4, + CENTER: 5, + RIGHT: 6, + BOTTOM_LEFT: 7, + BOTTOM_CENTER: 8, + BOTTOM_RIGHT: 9, + POS_XY: 10 +}; + +/* + * set options: + * { + * position: integer, // default position + * x: integer, // default X of banner + * y: integer, // default Y of banner + * isTesting: boolean, // if set to true, to receive test ads + * autoShow: boolean, // if set to true, no need call showBanner or showInterstitial + * } + */ +iadExport.setOptions = function(options, successCallback, failureCallback) { + if(typeof options === 'object') { + cordova.exec( successCallback, failureCallback, 'iAd', 'setOptions', [options] ); + } else { + if(typeof failureCallback === 'function') { + failureCallback('options should be specified.'); + } + } + }; + +iadExport.createBanner = function(args, successCallback, failureCallback) { + var options = {}; + if(typeof args === 'object') { + for(var k in args) { + if(k === 'success') { if(args[k] === 'function') successCallback = args[k]; } + else if(k === 'error') { if(args[k] === 'function') failureCallback = args[k]; } + else { + options[k] = args[k]; + } + } + } else if(typeof args === 'string') { + options = { adId: args }; + } + cordova.exec( successCallback, failureCallback, 'iAd', 'createBanner', [ options ] ); +}; + +iadExport.removeBanner = function(successCallback, failureCallback) { + cordova.exec( successCallback, failureCallback, 'iAd', 'removeBanner', [] ); +}; + +iadExport.hideBanner = function(successCallback, failureCallback) { + cordova.exec( successCallback, failureCallback, 'iAd', 'hideBanner', [] ); +}; + +iadExport.showBanner = function(position, successCallback, failureCallback) { + if(typeof position === 'undefined') position = 0; + cordova.exec( successCallback, failureCallback, 'iAd', 'showBanner', [ position ] ); +}; + +iadExport.showBannerAtXY = function(x, y, successCallback, failureCallback) { + if(typeof x === 'undefined') x = 0; + if(typeof y === 'undefined') y = 0; + cordova.exec( successCallback, failureCallback, 'iAd', 'showBannerAtXY', [{x:x, y:y}] ); +}; + +iadExport.prepareInterstitial = function(args, successCallback, failureCallback) { + var options = {}; + if(typeof args === 'object') { + for(var k in args) { + if(k === 'success') { if(args[k] === 'function') successCallback = args[k]; } + else if(k === 'error') { if(args[k] === 'function') failureCallback = args[k]; } + else { + options[k] = args[k]; + } + } + } else if(typeof args === 'string') { + options = { adId: args }; + } + cordova.exec( successCallback, failureCallback, 'iAd', 'prepareInterstitial', [ args ] ); +}; + +iadExport.showInterstitial = function(successCallback, failureCallback) { + cordova.exec( successCallback, failureCallback, 'iAd', 'showInterstitial', [] ); +}; + +module.exports = iadExport; + diff --git a/plugins/fetch.json b/plugins/fetch.json new file mode 100644 index 0000000..17002bf --- /dev/null +++ b/plugins/fetch.json @@ -0,0 +1,18 @@ +{ + "com.rjfun.cordova.iad": { + "source": { + "type": "registry", + "id": "com.rjfun.cordova.iad" + }, + "is_top_level": true, + "variables": {} + }, + "com.rjfun.cordova.extension": { + "source": { + "type": "registry", + "id": "com.rjfun.cordova.extension" + }, + "is_top_level": false, + "variables": {} + } +} \ No newline at end of file diff --git a/plugins/ios.json b/plugins/ios.json index 07c3697..e5fe794 100644 --- a/plugins/ios.json +++ b/plugins/ios.json @@ -4,8 +4,37 @@ "uninstalled": [] }, "config_munge": { - "files": {} + "files": { + "framework": { + "parents": { + "iAd.framework": [ + { + "xml": true, + "count": 1 + } + ] + } + }, + "config.xml": { + "parents": { + "/*": [ + { + "xml": "", + "count": 1 + } + ] + } + } + } }, - "installed_plugins": {}, - "dependent_plugins": {} + "installed_plugins": { + "com.rjfun.cordova.iad": { + "PACKAGE_NAME": "com.georgegarside.tdaconnect" + } + }, + "dependent_plugins": { + "com.rjfun.cordova.extension": { + "PACKAGE_NAME": "com.georgegarside.tdaconnect" + } + } } \ No newline at end of file diff --git a/www/script.js b/www/script.js index c989364..06dfb0f 100644 --- a/www/script.js +++ b/www/script.js @@ -35,6 +35,7 @@ $(document).ready(function() { }, 500); // Connect button $(myframe).find('#conn').bind('touchstart', function() { + iAd.removeBanner(); $('iframe').hide(); var paceload = window.setInterval(function(){ Pace.restart(); @@ -49,5 +50,10 @@ $(document).ready(function() { $('iframe').fadeIn('slow'); }, 10000); }); + if (iAd) iAd.createBanner({ + overlap: true, + position: iAd.AD_POSITION.BOTTOM_CENTER, + autoShow: true + }); }); });