Skip to content

Commit

Permalink
experimental google ads support
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Nov 21, 2016
1 parent 0319737 commit 36bb9b5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
37 changes: 20 additions & 17 deletions Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ else ifeq ($(TARGET_PLATFORM),ios32)
XCODE_PATH = $(shell xcode-select --print-path)
SDK_VERSION = $(shell xcodebuild -showsdks | grep iphoneos | sed "s/.*iphoneos//")
SDK_PATH = $(XCODE_PATH)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$(SDK_VERSION).sdk
TARGET_CFLAGS += -arch armv7 -isysroot $(SDK_PATH) -miphoneos-version-min=5.1.1
TARGET_CFLAGS += -Fthird_party -arch armv7 -isysroot $(SDK_PATH) -miphoneos-version-min=6.0
XCFLAGS += -ObjC++
XLDFLAGS = $(TARGET_CFLAGS) -lm -liconv -Wl,-framework,OpenGLES -lobjc \
-Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox \
-Wl,-framework,UIKit -Wl,-framework,QuartzCore \
-Wl,-framework,CoreMotion -Wl,-framework,Foundation \
-Wl,-framework,AVFoundation \
-Wl,-framework,GLKit -Wl,-framework,GameKit
-Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,MediaPlayer -Wl,-framework,MobileCoreServices \
-Wl,-framework,CFNetwork -Wl,-framework,CoreGraphics -Wl,-framework,SystemConfiguration \
-Wl,-framework,UIKit -Wl,-framework,QuartzCore -Wl,-framework,SpriteKit -Wl,-framework,StoreKit -Wl,-framework,CoreMedia \
-Wl,-framework,CoreMotion -Wl,-framework,Foundation -Wl,-framework,CoreTelephony \
-Wl,-framework,AVFoundation -Wl,-framework,CoreVideo -Wl,-framework,MessageUI -Wl,-framework,AdSupport \
-Wl,-framework,GLKit -Wl,-framework,GameKit -Wl,-framework,GoogleMobileAds
LUA_CFLAGS += -DLUA_USE_POSIX
IOS = 1
else ifeq ($(TARGET_PLATFORM),ios64)
Expand All @@ -160,14 +161,15 @@ else ifeq ($(TARGET_PLATFORM),ios64)
XCODE_PATH = $(shell xcode-select --print-path)
SDK_VERSION = $(shell xcodebuild -showsdks | grep iphoneos | sed "s/.*iphoneos//")
SDK_PATH = $(XCODE_PATH)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$(SDK_VERSION).sdk
TARGET_CFLAGS += -arch arm64 -isysroot $(SDK_PATH) -miphoneos-version-min=5.1.1
TARGET_CFLAGS += -Fthird_party -arch arm64 -isysroot $(SDK_PATH) -miphoneos-version-min=6.0
XCFLAGS += -ObjC++
XLDFLAGS = $(TARGET_CFLAGS) -lm -liconv -Wl,-framework,OpenGLES -lobjc \
-Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox \
-Wl,-framework,UIKit -Wl,-framework,QuartzCore \
-Wl,-framework,CoreMotion -Wl,-framework,Foundation \
-Wl,-framework,AVFoundation \
-Wl,-framework,GLKit -Wl,-framework,GameKit
-Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,MediaPlayer -Wl,-framework,MobileCoreServices \
-Wl,-framework,CFNetwork -Wl,-framework,CoreGraphics -Wl,-framework,SystemConfiguration \
-Wl,-framework,UIKit -Wl,-framework,QuartzCore -Wl,-framework,SpriteKit -Wl,-framework,StoreKit -Wl,-framework,CoreMedia \
-Wl,-framework,CoreMotion -Wl,-framework,Foundation -Wl,-framework,CoreTelephony -Wl,-framework,MessageUI -Wl,-framework,AdSupport \
-Wl,-framework,AVFoundation -Wl,-framework,CoreVideo \
-Wl,-framework,GLKit -Wl,-framework,GameKit -Wl,-framework,GoogleMobileAds
LUA_CFLAGS += -DLUA_USE_POSIX
IOS = 1
else ifeq ($(TARGET_PLATFORM),iossim)
Expand All @@ -177,13 +179,14 @@ else ifeq ($(TARGET_PLATFORM),iossim)
XCODE_PATH = $(shell xcode-select --print-path)
SDK_VERSION = $(shell xcodebuild -showsdks | grep iphoneos | sed "s/.*iphoneos//")
SDK_PATH = $(XCODE_PATH)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$(SDK_VERSION).sdk
TARGET_CFLAGS += -arch x86_64 -isysroot $(SIM_SDK_PATH) -miphoneos-version-min=5.1.1
TARGET_CFLAGS += -Fthird_party -arch x86_64 -isysroot $(SIM_SDK_PATH) -miphoneos-version-min=6.0
XCFLAGS += -ObjC++
XLDFLAGS = $(TARGET_CFLAGS) -lm -liconv -Wl,-framework,OpenGLES -lobjc \
-Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox \
-Wl,-framework,UIKit -Wl,-framework,QuartzCore \
-Wl,-framework,CoreMotion -Wl,-framework,Foundation \
-Wl,-framework,GLKit
-Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,MediaPlayer -Wl,-framework,MobileCoreServices \
-Wl,-framework,CFNetwork -Wl,-framework,CoreGraphics -Wl,-framework,SpriteKit -Wl,-framework,AdSupport \
-Wl,-framework,UIKit -Wl,-framework,QuartzCore -Wl,-framework,SystemConfiguration -Wl,-framework,StoreKit -Wl,-framework,CoreMedia \
-Wl,-framework,CoreMotion -Wl,-framework,Foundation -Wl,-framework,CoreVideo -Wl,-framework,CoreTelephony -Wl,-framework,MessageUI \
-Wl,-framework,GLKit -Wl,-framework,GoogleMobileAds
LUA_CFLAGS += -DLUA_USE_POSIX
IOS = 1
else ifeq ($(TARGET_PLATFORM),html)
Expand Down
9 changes: 8 additions & 1 deletion scripts/gen_ios_info_plist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cat << EOF > $f/Info.plist
<string>%s</string>
<key>MinimumOSVersion</key>
<string>5.1.1</string>
<string>6.0</string>
<key>UIRequiresFullScreen</key>
<string>YES</string>
Expand Down Expand Up @@ -104,6 +104,13 @@ cat << EOF > $f/Info.plist
<key>UIStatusBarHidden</key>
<true/>
<!-- needed for Google Ads -->
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<!-- orientation -->
%s
<key>UILaunchImages</key>
Expand Down
33 changes: 26 additions & 7 deletions src/am_backend_ios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import <CoreMotion/CoreMotion.h>
#import <GLKit/GLKit.h>
#import <GameKit/GameKit.h>
#import <GoogleMobileAds/GADBannerView.h>

#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
Expand Down Expand Up @@ -647,7 +648,19 @@ static BOOL handle_orientation(UIInterfaceOrientation orientation) {
viewController.preferredFramesPerSecond = 60; // XXX
self.window.rootViewController = viewController;
ios_view_controller = viewController;


// Create a banner ad and add it to the view hierarchy.
GADBannerView *banner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
banner.hidden = YES;
banner.adUnitID = @"ca-app-pub-3940256099942544/2934735716";
banner.rootViewController = viewController;
[view addSubview:banner];

banner.hidden = NO;
GADRequest *request = [GADRequest request];
request.testDevices = @[@"2077ef9a63d2b398840261c8221a0c9b"];
[banner loadRequest:request];

[self.window makeKeyAndVisible];
return YES;
}
Expand Down Expand Up @@ -907,7 +920,7 @@ static GameCenterDelegate *gamecenter_delegate = nil;
@implementation GameCenterDelegate
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController {
if (ios_view_controller != nil) {
[ios_view_controller dismissModalViewControllerAnimated:YES];
[ios_view_controller dismissViewControllerAnimated:YES completion:nil];
if (ios_view != nil && ios_eng != NULL) {
// reset event data, because sometimes touch end events are missed
// when the leaderboard view controller is displayed.
Expand Down Expand Up @@ -960,6 +973,7 @@ static GameCenterDelegate *gamecenter_delegate = nil;
@end

static int init_gamecenter(lua_State *L) {
/*
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil) {
gamecenter_available = true;
Expand All @@ -970,25 +984,30 @@ static int init_gamecenter(lua_State *L) {
gamecenter_available = false;
}
}];
*/

/*
/*
* XXX FIXME for iOS 6
if ([GKLocalPlayer localPlayer].authenticated == NO) {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if(localPlayer.isAuthenticated) {
am_debug("%s", "gamecenter authenticated ok");
}else {
gamecenter_available = true;
} else if(viewController) {
[self presentViewController:viewController]; //present the login form
} else {
//problem with authentication,probably bc the user doesn't use Game Center
am_debug("%s", "gamecenter authentication failed");
}
})];
} else {
NSLog(@"Already authenticated!");
}
*/

gamecenter_delegate = [[GameCenterDelegate alloc] init];
[gamecenter_delegate retain];
*/
return 0;
}

Expand Down Expand Up @@ -1050,7 +1069,7 @@ static int show_gamecenter_leaderboard(lua_State *L) {
leaderboard_view_controller.leaderboardDelegate = gamecenter_delegate;
}
leaderboard_view_controller.category = category;
[ios_view_controller presentModalViewController: leaderboard_view_controller animated: YES];
[ios_view_controller presentViewController:leaderboard_view_controller animated:YES completion:nil];
}
return 0;
}
Expand Down

0 comments on commit 36bb9b5

Please sign in to comment.