Add Mobclix to Cocos2d Scene - iphone

Has anyone integrating mobclix into a cocos2d application? I tried to add a banner of Ad by using Mobclix, but it did not appear, my code:
//In appDelegate:
[Mobclix startWithApplicationId:#"4778FFA3-DDFF-4550-BFFE-7B7AB4B5765D"];
[Mobclix start];
//In my Scene
-(void)onEnter {
adView = [MobclixAdViewiPhone_320x50 new];
adView.delegate = self; //Optional
// set position
adView.frame = CGRectMake(10, 20, 320, 50);
dView.refreshTime = 15;
// add to view
[[[CCDirector sharedDirector] openGLView] addSubview:adView];
// set refresh (automatically gets one ad when changing the property)
[adView getAd];
[super onEnter];
Anyone help me to show Adbanner on my Scene please?

Related

Cannot seem to move iAd banner to the top of the screen with this code

I have searched and searched and have done lots of trial and error on this code trying to move the ad banner to the top of the screen. It has been a week already with no progress. If anyone could help me out with this issue I would be thrilled. The code this is based off of is by the gentleman's great tutorial:
http://codewithchris.com/iad-tutorial/
Here's the code:
#interface ViewController ()
{
BOOL _bannerIsVisible;
ADBannerView *_adBanner;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)];
_adBanner.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!_bannerIsVisible)
{
// If banner isn't part of view hierarchy, add it
if (_adBanner.superview == nil)
{
[self.view addSubview:_adBanner];
}
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Failed to retrieve ad");
if (_bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = NO;
}
}
#end
Change this line:
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)];
To this:
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, -50, 320, 50)];
(where the -50 is the height of the ad banner.) Before you were setting the ad banner's frame to the bottom of the screen using self.view.frame.size.height, whereas now the -50 moves the frame just above the screen.
Also, don't forget you'll need to reverse your CGRectOffsets' y coordinates (remove the (-) from the first and add it to the second) because the ones you have at the moment assume the frame is at the bottom of the screen.
Hope this helps!

Set Revmob banner frame for iphone

I am using Revmob for showing add banner using below code.
[RevMobAds startSessionWithAppID:#"My Application id"];
[RevMobAds session].testingMode = RevMobAdsTestingModeWithAds;
[[RevMobAds session] showBanner];
and it's showing test banner perfectly at the bottom.
Now my question is i want to set this banner at the top of my application.
so how can i set this banner frame ?
I have tried to use RevMobBannerView
My code is
RevMobBannerView *banner = [[RevMobBannerView alloc]
initWithFrame:CGRectMake(0, 100, 320, 50)];
[banner setBackgroundColor:[UIColor yellowColor]];
[banner loadAd];
[self.window addSubview:banner];
but it's not working...it's not showing anything into screen.
any help will be apriciated...
Thanks !
From RevMob Documentation site:
RevMobBannerView *ad = [[RevMobAds session] bannerView];
ad.delegate = self;
[ad loadAd];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
ad.frame = CGRectMake(0, 0, 768, 114);
} else {
ad.frame = CGRectMake(0, 0, 320, 50);
}
[self.view addSubView:ad];
In case tkanzakic answer didn't work, you can always use a UIView to put the banner into and add it to your view. In banner load delegate, resize your intermediate view to banner's bounds.
edit:
Something like
ad = [[[RevMobAds session] bannerView] retain];
ad.delegate = self;
[ad loadAd];
- (void)revmobAdDidReceive {
intermediateView.frame = CGRectMake(0,0, somewidth, someheight);
ad.frame = intermediateView.bounds;
[intermediateView addSubview:ad];
}
the RevMobAds object has a RevMobBannerView property, and this property has a frame. Accordingly to the documentation:
You can use this property to define the position of the banner in the screen. The default is a banner on the botton of the screen
EDIT:
Try this to set the frame:
RevMobAds *revMovAds = [RevMobAds startSessionWithAppID:#"My Application id"];
revMovAds.bannerView.frame = CGRect(x,y,xx,yy);
[revMovAds showBanner];
When I'm adding it(RevMob version 5.9) in my project. I do it like this:
[RevMobAds startSessionWithAppID:#"my id"];
RevMobBannerView *ad = [[RevMobAds session] bannerView]; // you must retain this object
[ad loadWithSuccessHandler:^(RevMobBannerView *banner) {
banner.frame = CGRectMake(0, 381, 320, 50);
[self.window.rootViewController.view addSubview:banner];
NSLog(#"Ad loaded");
} andLoadFailHandler:^(RevMobBannerView *banner, NSError *error) {
NSLog(#"Ad error: %#",error);
} onClickHandler:^(RevMobBannerView *banner) {
NSLog(#"Ad clicked");
}];

UIImagePickerController overlayView and showsCameraControls issue

I'm trying to use a custom overlay on the UIImagePickerController and also be able to move and scale the resulting image. The problem is when I set showsCameraControls=YES, the overlay won't show but I can use the the move and scale functionality. However, when showsCameraControls=NO, the overlay appears, but when I take the picture, I don't even get the option to crop the image. The actual view loaded from the xib is just a UIToolbar with two buttons, one of which takes the picture
I have a controller (OverlayViewController) which loads the overlay from a xib file as it's view. This controller also has a UIImagePickerController so it sets the overlay of the UIImagePickerController to the view of the OverlayController. This first method is called in a different controller to set it all up and display it. In summary, I need to be able see the overlayView and use it's button to take the picture, which I can then move and scale
-(void) openCameraForImage
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.overlayViewController =
[[OverlayViewController alloc] initWithNibName:#"OverlayViewController" bundle:nil];
// as a delegate we will be notified when pictures are taken and when to dismiss the image picker
self.overlayViewController.delegate = self;
[self.overlayViewController setupImagePicker:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
}
else {
[Common ShowAlert:#"Alert" andMessage:#"There is no camera on this device"];
}
}
This method is in OverlayViewController and does the work of setting up the Overlay.
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
self.imagePickerController.sourceType = sourceType;
[self.imagePickerController setAllowsEditing:YES];
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
self.imagePickerController.showsCameraControls = NO; //This line allows overlay to show but move and scale doesn't work
self.imagePickerController.allowsEditing = YES;
//[self.view setUserInteractionEnabled:NO];
if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
{
// setup our custom overlay view for the camera
//
// ensure that our custom view's frame fits within the parent frame
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,
CGRectGetHeight(overlayViewFrame) -
self.view.frame.size.height - 10.0,
CGRectGetWidth(overlayViewFrame),
self.view.frame.size.height + 10.0);
self.view.frame = newFrame;
self.imagePickerController.cameraOverlayView = self.view;
}
}
}
This method in OverlayViewConroller takes the picture
- (IBAction)takePhoto:(id)sender
{
[self.imagePickerController takePicture];
}
I think you can put your image picker code in openCameraForImage
In your OverlayViewController, just use it to purely show the Overlay for your camera.
#implementation RiskCameraOverlayViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view setBackgroundColor:[UIColor blackColor]];
opUpImage = [UIImage imageNamed:#"camera_overlay_op_up"];
opDownImage = [UIImage imageNamed:#"camera_overlay_op_down"];
opUpFrameBegin = CGRectMake(0, -50, 320, 358);
opUpImageView = [[UIImageView alloc] initWithFrame:opUpFrameBegin];
[opUpImageView setImage:opUpImage];
opDownFrameBegin = CGRectMake(0, 265, 320, 314);
opDownImageView = [[UIImageView alloc] initWithFrame:opDownFrameBegin];
[opDownImageView setImage:opDownImage];
[self.view addSubview:opUpImageView];
[self.view addSubview:opDownImageView];
}
You might reach an issue where "Use photo" or "Retake" is not working, do a
[self.view removeFromSuperview];

how to add a custom subview inside TTThumbviewController (Three20)

i am developing an iphone application which have to show images from server as thumbnail list. I have created thumbnailview using Three20 package TTThumbViewcontroller class.
Now i have to add banner view above the thumbnail view as shows in the image. Also i have to add the bottom banner view in the TTPhotoviewcontroller also.
can anyone guide me, how to add my custom banner view (UIView) along with either TTThumbviewConntroller or TTPhotoViewController to my parent view?
Edit:I had successfully added a subview for the controller which extends TTThumbViewcontroller. Now i have to add a subview above the TTPhotoViewController toolbar (as in the attached image).
thanks in advance.
Ram
The banner view is nothing different than a normal view. So you could do the same with any other view. Following is the code I use in my app (I have the same banner view at the bottom of the screen, you can adjust its position to put in above the tab bar):
- (void)viewDidLoad{
[super viewDidLoad];
//we don't want user to see the ads at the very first load.
//once, it succeeds, it will be animated up by the bannerViewDidLoadAd
adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 480, 320, 50)];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[adView setDelegate:self];
[self.view addSubview:adView];
self.bannerIsVisible = NO;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
adView.frame = CGRectMake(0, 346, 320, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
adView.frame = CGRectMake(0, 480, 320, 50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)dealloc{
adView.delegate = nil;
[adView release];
[super dealloc];
}

How to resize a UIModalPresentationFormSheet?

I am trying to display a modal view controller as a UIPresentationFormSheet. The view appears, but I can't seem to resize it. My XIB has the proper height & width, but it seems to get overridden when I call it like this:
composeTweetController = [[ComposeTweet alloc] initWithNibName:#"ComposeTweet" bundle:nil];
composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:composeTweetController animated:TRUE];
Any thoughts? I am using the iPhone SDK 3.2 beta 4
You are able to adjust the frame of a modal view after presenting it:
Tested in iOS 5.1 - 7.1
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentViewController:targetController animated:YES completion:nil];
if(floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){
targetController.view.superview.frame = CGRectInset(targetController.view.superview.frame, 100, 50);
}else{
targetController.view.frame = CGRectInset(targetController.view.frame, 100, 50);
targetController.view.superview.backgroundColor = [UIColor clearColor];
}
Here's a method that works on iOS7 as well as iOS5 and iOS6: (arc)
-(void)presentController:(UIViewController*)controller fromRootController:(UIViewController*)rootController withSize:(CGSize)size
{
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:controller];
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[rootController presentModalViewController:nav animated:YES];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
nav.view.superview.backgroundColor = [UIColor clearColor];
nav.view.bounds = CGRectMake(0, 0, size.width, size.height);
}
else
{
nav.view.superview.bounds = CGRectMake(0, 0, size.width, size.height);
}
}
composeTweetController = [[ComposeTweet alloc] initWithNibName:#"ComposeTweet" bundle:nil];
composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:composeTweetController animated:TRUE];
//if you want to change its size but the view will remain centerd on the screen in both portrait and landscape then:
composeTweetViewController.view.superview.bounds = CGRectMake(0, 0, 320, 480);
//or if you want to change it's position also, then:
composeTweetViewController.view.superview.frame = CGRectMake(0, 0, 320, 480);
As of iOS7 you can simply do
composeTweetController.preferredContentSize = CGSizeMake(380.0, 550.0);
Tested and works for iOS 6, using XCode 4.5
I stumbled upon my answer after reading much of the tips on here:
In the viewWillAppear:(BOOL)animated method:
[super viewWillAppear:animated];
//resize modal view
self.view.superview.bounds = CGRectMake(0, 0, 432, 680);
In the viewDidAppear:(BOOL)animated method:
CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
self.view.superview.center = centerPoint;
I tried to add the centering code in the same place as the resizing code, but that did not work. For some reason, it only works after the view has appeared on the screen.
I surmise that it has something to do with the way that UIModalPresentationFormSheet works, because when I was stepping through in the LLDB debugger, I noticed that there was a variable _formSheetSize that was still {540, 620}. Go figure.
This will work with any UIModalTransitionStyle
#interface BaseDialog ()
#property(nonatomic,assign) CGRect origFrame;
#end
#implementation BaseDialog
-(void)viewDidLoad{
[super viewDidLoad];
self.origFrame=self.view.frame;
}
-(CGSize)formSheetSize{
return self.origFrame.size;
}
Following first code is how to present your model view controller
composeTweetController = [[ComposeTweet alloc] initWithNibName:#"ComposeTweet" bundle:nil];
composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:composeTweetController];
navigationController.delegate = self;
[self presentModalViewController:navigationController animated:YES];
And In your ComposeTweet controller class
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.view.superview.frame = CGRectMake(0, 0,500,400);
}
iOS 7
So the approach of setting the superview's frame or bounds doesn't work anymore on iOS 7 (for UIModalTransitionStyleCoverVertical). You can, however, now set the background color of the superview to clear and then change the frame of the modal view controller how you see fit.
So in iOS 7 you will want to:
present the view controller (presentation mode: UIModalPresentationFormSheet)
set view controller superview background color to clear
change frame of view controller as desired (perhaps making it smaller and then centering it in superview)
I got a full screen modal view from UIPresentationFormSheet with just this line:
modalViewController.view.superview.bounds = CGRectMake(0, 0, 1024, 748);
#bdrobert sadly your nice solution does not work anymore on iOS6 - the container keeps the original size even though the new viewcontroller is embedded with the custom size.
You probably need to use the containment API introduced in iOS5, but you need to add a dimmed background on your own, fetching all touch events for that area.
On change of orientation, this code work perfect....
settingViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:settingViewController animated:YES completion:nil];
settingViewController.view.superview.frame = CGRectMake(0, 0, 700, 700);
UIInterfaceOrientation currentOrientation = [self getDeviceOrientation];
if(currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
settingViewController.view.superview.center = centerPoint;
}
else
{
CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.height/2, [[UIScreen mainScreen] bounds].size.width/2);
settingViewController.view.superview.center = centerPoint;
}
The modern ios13 way:
use popover (formsheet and page ignore preferredContentSize)
then set or override preferredContentSize aka Ed Pilowat & Co
The view size is fixed. You will have to implement things yourself if you want something different.