Admob Interstitial Cocos2d Objective C - ios

i'm searching on google but i only find the way to integrate the AdMob Banner View on my app in Cocos2d. Now I need to put the full screen AdMob interstitial and i don't find the way to do it :. Please Help me, how i can do it??
I'm not sure what source code i need to post... I would like to show the interstitial when the app startup and when there is the game over.
I already tried this
but it gave me some error.

In AppDelegate.h, add GADInterstitialDelegate
#interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate, GADInterstitialDelegate>
{
}
-(void)showAdmobFullScreenAds;
#end
#define App ((AppController *)[[UIApplication sharedApplication] delegate])
In AppDelegate.m
-(void)showAdmobFullScreenAds
{
GADInterstitial *interstitial_ = [[GADInterstitial alloc] init];
interstitial_.adUnitID = #"ca-app-pub-YOUR_ID";
interstitial_.delegate = self;
[interstitial_ loadRequest:[GADRequest request]];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
{
[interstitial presentFromRootViewController:[CCDirector sharedDirector]];
}
// In GameOver class, add #import "AppDelegate.h" then use below function
[App showAdmobFullScreenAds];

Related

How to disable the Cordova webview in the background? (iOS only)

I'm working on a iOS Cordova app that gets launched in the background to handle location events. This is working fine, but I've noticed that when the app gets launched in the background, the webview is initialized and my entire app is rendered. I have all the logic for handling the background launch written natively so I could (hopefully) avoid rendering the UI and running the Javascript side.
I thought I could disable the webview by wrapping the MainViewController creation in an if statement, but that doesn't seem to be working (I know the webview is being run because it's sending HTTP requests).
Here is my AppDelegate.m:
#import "AppDelegate.h"
#import "MainViewController.h"
#import "AppName-Swift.h"
#implementation AppDelegate {
LocationSyncManager* locationSyncManager;
}
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
bool isLocationLaunch = launchOptions[#"location"] == nil ? false : launchOptions[#"location"];
NSString* serverAddress = #"http://192.168.1.61:9090/api/notes/nearby";
locationSyncManager = [LocationSyncManager create: serverAddress isLocationLaunch: isLocationLaunch];
// Don't render the webview if the app is launched in the background by a location event
if(!isLocationLaunch) {
self.viewController = [[MainViewController alloc] init];
}
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
#end
Figured out the issues:
isLocationLaunch was always false because I was checking the location launch flag wrong.
Also in order to keep Cordova from rendering/running javascript, I had to keep super didFinishLaunchingWithOptions from being called during location launched.
This works:
#import "AppDelegate.h"
#import "MainViewController.h"
#import "AppName-Swift.h"
#implementation AppDelegate {
LocationSyncManager* locationSyncManager;
}
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
bool isLocationLaunch = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
NSString* serverAddress = #"http://192.168.1.61:9090/api/notes/nearby";
locationSyncManager = [LocationSyncManager create: serverAddress isLocationLaunch: isLocationLaunch];
if(!isLocationLaunch) {
self.viewController = [[MainViewController alloc] init];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
return nil;
}
#end

Admob interstitial presented whitout calling presentFromRootViewController

I'm using Admob interstitial in my app.
I followed all the guidelines and I observe Video interstitial are presented automatically while I did not call yet presentFromRootViewController.
I'm using that code to preload the interstitial :
splashInterstitial_ = [[GADInterstitial alloc] initWithAdUnitID: interstitialIdStr];
splashInterstitial_.delegate = self;
requestInterstitial = [GADRequest request];
[splashInterstitial_ loadRequest: requestInterstitial];
In the delegate, I do not present the interstitial :
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
}
I present the interstitial manually between two screens, as follow :
if (splashInterstitial_.isReady)
{
[splashInterstitial_ presentFromRootViewController: interstitialRootViewController];
self.lastInterstitialTime = [[NSDate date] timeIntervalSince1970];
return YES;
}
I placed a breakpoint on presentFromRootViewController, the breakpoint is never reached, and I can see interstitial videos presented on real device.
I sounds like the loadRequest on interstitial triggers a presentation which should not occur.
Anybody experiencing a similar issue ?
Thanks

iOS app crash when presenting multiple Admob Mediated Interstitials

I have implemented Admob in my iOS application. Banners, rewarded videos and mediated interstitials (Admob, Unity and Chartboost). The only problem I have is that the app always crash after 3-4 interstitial ads has been presented. The debugger shows this message: Message from debugger: Terminated due to memory issue.
I am 100% sure the crash comes from the Interstitials. I have tested completely without ads, no crash. And only with banner ads, no crash.
This is the code I use to implement and show Interstitial ads:
#interface ViewController ()
#property(nonatomic, strong) GADInterstitial *interstitial;
#end
- (void)viewDidLoad {
[self loadInterstitial];
}
- (void)loadInterstitial {
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:#"ca-app-pub-xxxxx/xxxxx"];
self.interstitial.delegate = self;
[self.interstitial loadRequest:[GADRequest request]];
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial {
[self loadInterstitial];
}
- (void)someMethod {
if (self.interstitial.isReady) {
[self.interstitial presentFromRootViewController:self];
}
}

google plus login is redirecting to google.com in ios

I followed google developer docs to implement a simple google plus (gmail) sign in button in my basic app. But When i run the code it going to google.com.
So here are the steps i followed.
1.Created new client id and added that into app from google console.
2.Imported frameworks
3.When i run the code i can see
it first open google sign in page then it will open Oauth page if i press "allow" access then it will redirect from "accounts.google.com" to "google.com.
I have created a sample project for that
Here is my code and screen shots
my file and framework list
CODE
AppDelegate.m
#import <GooglePlus/GooglePlus.h>
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
ViewController.h
#import <UIKit/UIKit.h>
#import <GooglePlus/GooglePlus.h>
#class GPPSignInButton;
#interface ViewController : UIViewController<GPPSignInDelegate>
#property (strong, nonatomic) IBOutlet GPPSignInButton *signInButton;
#end
ViewController.m
//
#import <GooglePlus/GooglePlus.h>
#import "ViewController.h"
#import <GoogleOpenSource/GoogleOpenSource.h>
#define kClientId #"49781846815-pbsb1vso4nrbes9a4al5kae2d98ie3cf.apps.googleusercontent.com"
#define kGTLAuthScopePlusLogin #"https://www.googleapis.com/auth/plus.login"
#interface ViewController ()
#end
#implementation ViewController
#synthesize signInButton;
- (void)viewDidLoad {
[super viewDidLoad];
GPPSignIn *signIn = [GPPSignIn sharedInstance];
// Do any additional setup after loading the view, typically from a nib.
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user's email
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientId;
// Uncomment one of these two statements for the scope you chose in the previous step
signIn.scopes = #[ kGTLAuthScopePlusLogin ]; // "https://www.googleapis.com/auth/plus.login" scope
signIn.scopes = #[ #"profile" ]; // "profile" scope
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
NSLog(#"Received error %# and auth object %#",error, auth);
if (error) {
// Do some error handling here.
} else {
[self refreshInterfaceBasedOnSignIn];
}
}
-(void)refreshInterfaceBasedOnSignIn {
if ([[GPPSignIn sharedInstance] authentication]) {
// The user is signed in.
NSLog(#"hi");
self.signInButton.hidden = YES;
// Perform other actions here, such as showing a sign-out button
} else {
self.signInButton.hidden = NO;
// Perform other actions here
}
}
- (void)presentSignInViewController:(UIViewController *)viewController {
// This is an example of how you can implement it if your app is navigation-based.
[[self navigationController] pushViewController:viewController animated:YES];
}
#end
Please help to clear this google.com redirect issue and also to develop a good login.
As of May 2015, even if you got this working, your app would then be rejected by Apple's App Store review team because of a childish fight going on between Apple and Google. See this issue in the Google+ SDK: https://code.google.com/p/google-plus-platform/issues/detail?id=900

AdMob interstitial shown only once on iOS

I'm using admob interstitial on my iOS app.
I'm able to display the interstitial only one time, any further request to display a new interstitial fails (delegate is never called by the way).
My code is as follow:
-(void) viewDidLoad
{
[super viewDidLoad];
[self allocateAndDisplayAd];
}
-(void) allocateAndDisplayAd
{
splashInterstitial_ = [[GADInterstitial alloc] init];
splashInterstitial_.adUnitID = #"ca-app-pub-MY-ID";
splashInterstitial_.delegate = self;
GADRequest *requestInterstitial = [GADRequest request];
[splashInterstitial_ loadRequest: requestInterstitial];
}
// below functions delegate are never triggered when requesting a new interstitial !!
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
[splashInterstitial_ presentFromRootViewController: self];
}
- (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error
{
splashInterstitial_ = nil;
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad
{
splashInterstitial_ = nil;
}
The interstitial is properly displayed when app launches (request done from the viewDidLoad), then any new request (call to allocateAndDisplayAd) fails (no error message, delegate function never called).
I tried to set splashInterstitial_ = nil; so I'm sure the next request will reallocate a new interstitial, but no way to display more than one ad.
Any help would be appreciated.
Thanks
Ok I found my issue
Any request to show interstitial from applicationWillEnterForeground will be ignored ...
And my second request was done from applicationWillEnterForeground

Resources