I am using cocos2d 3.0.
In AppDelegate class I have implemented admob and it works fine, but it is always on the screen. But I want admob to be hidden during the main scene and to appear when it is game over.
In AppDelegate.h I have
#import <UIKit/UIKit.h>
#import "cocos2d.h"
#import "GADBannerView.h"
typedef enum _bannerType
{
kBanner_Portrait_Top,
kBanner_Portrait_Bottom,
kBanner_Landscape_Top,
kBanner_Landscape_Bottom,
}CocosBannerType;
#define BANNER_TYPE kBanner_Portrait_Top
#interface AppController : CCAppDelegate
{
CocosBannerType mBannerType;
GADBannerView *mBannerView;
float on_x, on_y, off_x, off_y;
}
-(void)hideBannerView;
-(void)showBannerView;
In MainScene class I've tried to write
mBannerView.hidden = YES;
but it is said that mBannerView is undeclared identifier.
I guess i should somehow use -(void) hideBannerView, but I don't know how.
Could you please tell me what should I do to hide admob on certain scenes.
You can move banner up and down to hide.
AppController *app = (AppController*)[UIApplication sharedApplication].delegate;
[app hideBannerView];
Here is Full Source: Cocos2d v3 Admob Sample
Related
I added iAd to my application using self.canDisplayBannerAds. The application uses UITabBarController and that seems to be causing a problem. See the "empty" (gray) space in the screenshot below.
The UITextView has the following constraints:
And the program is very simple:
#import <iAd/iAd.h>
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.canDisplayBannerAds = YES;
}
#end
This simple program, with the canDisplayBannerAds commented out (or set to NO) doesn't have a gray rectangle at all. But with ads I can't seem to get rid of that "empty" (gray) rectangle. Does anyone have a suggestion to resolve this issue?
Demo project on github.
Just make your ViewController's TabBar to Opaque and your problem will be resolved.
How to extend Google Analytics file with each view in ios ? I'm new to iOS and confused with the syntax.
I want to extend with this viewcontroller
#interface IXComposeViewController ()<UITextFieldDelegate,UIActionSheetDelegate,UITableViewDataSource,UITableViewDelegate,IXScrollViewDelegate>
So how should I combine these two extension?
#interface IXComposeViewController : GAITrackedViewController
Confused with syntax,please help.
You did it exactly right, for screen tracking in Google Analytics you only need to perform two simple steps:
the UIViewController that should be tracked needs to inherit from GAITrackedViewController, so your suggested syntax is correct: #interface IXComposeViewController : GAITrackedViewController
add the line self.screenName = #"screen: IXComposeViewController"; // or any other string in your viewWillAppear or viewDidAppear
To make it clear, in your header-file, you need to extend GAITrackedViewController, so it would look somewhat like this:
IXComposeViewController.h
#import "GAITrackedViewController.h"
#interface IXComposeViewController : GAITrackedViewController
// declare public properties and methods
#end
IXComposeViewController.m
#implementation IXComposeViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.screenName = #"About Screen";
}
#end
I am trying to migrate a UIViewController Objective-C class to Swift. This view controller is inheriting from a BaseViewController where I have common functionality that I want to have in all controllers. The problem I am having is that the generated myproject-Swift.h is not able to find my BaseViewController.
Is there any way to implement a UIViewController in swift that inherits from a BaseViewController (subclass of UIViewController) written in Objective-C? Is there a bridging problem?
It can be reproduced with this minimal code:
BaseViewController.h
#import <UIKit/UIKit.h>
#interface BaseViewController : UIViewController
#end
BaseViewController.m
import "BaseViewController.h"
#implementation BaseViewController
#end
ViewController.swift
import UIKit
class ViewController : BaseViewController {
}
AppDelegate.m
#import "AppDelegate.h"
#import "projectname-Swift.h" // Replace with your project name
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ViewController *vc = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
projectname-Bridging-Header.h
#import "BaseViewController.h"
As pointed out in the accepted answer on How can I add forward class references used in the -Swift.h header?
Interoperability guide (Importing Swift into Objective-C):
If you use your own Objective-C types in your Swift code, make sure to
import the Objective-C headers for those types prior to importing the
Swift generated header into the Objective-C .m file you want to access
the Swift code from.
The example is solved by importing BaseViewController before the importing projectname-Swift.h in:
AppDelegate.m
#import "AppDelegate.h"
#import "BaseViewController.h"
#import "projectname-Swift.h" // Replace with your project name
// ...
It looks like they have fixed the issue. Currently under XCode6-Beta6 the problem reported by #atxe does not occur anymore. Therefor you can finally roll your AppDelegate.m header back to:
#import "AppDelegate.h"
#import "projectname-Swift.h" // Replace with your project name
I was wondering if there is a way to declare a project wide variable like you get when you start a application with a UINavigationController and you can call that navigation controller from anywhere in you application because of how its been declared in the applications Delegate.
I am wanting to create a project (global) var that allows me to call SVProgress hud or dismiss it from anywhere in my application. I have this issue where I load a UIViewController onto the navigation stack, start the SVProgress hud then make a request to my DB.. if I get an error back i need to handle a few things one of them is to be able to dissmiss the SVProgress hud.
This is the code I have so far
AppDelegate.h
#import "SVProgressHUD.h"
#interface MYAPPAppDelegate : UIResponder <UIApplicationDelegate> {
//..
}
#property (strong, nonatomic) SVProgressHUD *svprogressHud;
AppDelegate.m
#synthesize svprogressHud;
not really sure if this is possible hopefully someone out there will be able to help me out.
Here is a link to SVProgress git
One thing you can do from your view controller is grab the app delegate and cast it to the type of your delegate like so:
#import "MYAPPDelegate.h"
MYAPPDelegate *ad = (MYAPPDelegate *)[[UIApplication sharedApplication] delegate];
[ad.svprogressHud displayOrWhatever];
Not really the cleanest but should get the job done.
Just add the header file name into you pre-compiled header (<projectname>_Prefix.pch) file inside of the #ifdef __OBJC__
Like as:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "SVProgressHUD.h"
#endif
Then it will give you access to the file across all files.....
Just extending Roberts answer, In order to avoid repeating the code to get the app delegate and then cast it into MYAPPDelegate, I would create a header file/class in your project with a utility function.
Create new header called AppUtils.h
#import "MYAPPAppDelegate.h"
#ifndef AppName_AppUtils_h
#define AppName_AppUtils_h
static inline MYAPPAppDelegate* AppDelegate() {
return (MYAPPDelegate *)[[UIApplication sharedApplication] delegate];
}
#endif
Where ever you need access to these variables import the header AppUtils.h and use the helper function. Example:
#import "AppUtils.h"
...
- (void)foo {
// use app delegate
UIViewController *rootVC = AppDelegate().rootViewController;
}
I'm struggling getting started with the Universal App template in Xcode 4.1. I'm following the basic principles set out by kotancode here. The problem is getting the relevant view controller to load. I will focus on the iPhone part as an example. I create a subclass of UIViewController without a XIB as my "master" view controller class (where shared code will go). I then subclass this to create the iPhone specific UIViewController class called BaseViewController_iPhone, this time with a XIB.
The iPhone specific app delegate the header is set to:
#import "TestAppDelegate.h"
#import "BaseViewController_iPhone.h"
#interface TestAppDelegate_iPhone : TestAppDelegate {
BaseViewController_iPhone *viewController;
}
#property (nonatomic, retain) IBOutlet BaseViewController_iPhone *viewController;
#end
and for the implementation I try to override the applicationdidfinishlaunchingwithoptions method.
#import "TestAppDelegate_iPhone.h"
#implementation TestAppDelegate_iPhone
#synthesize viewController;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
-(void)dealloc {
[viewController release];
[super dealloc];
}
#end
This doesn't appear to work, it compiles fine and runs, but the new view controller and the corresponding XIB are not displayed (the original main window xib from the template is). I'm sure i'm missing something very simple, but i've spent a long time googling to no avail. Any help gratefully received.
Thank you.
Have you connected the ViewController in the app's delegate's XIB to your "BaseViewController_iPhone *viewController" ?
Are you sure the ViewController in the app's delegate's XIB is of the type BaseViewController?
Is the ViewController loading the correct XIB (check that in the app's delegate's xib)?
Check that and give some feedback.