can't see the banner on my simulator - ios-simulator

I want to add Admob in my app, the compilation is correct, but I can not see the banner on my simulator.
The app is for iPad in landscape mode.
I added the UUID of my macbook to the variable TEST_DEVICE_ID.
Could you help me ??
Thanks
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
#"TEST_DEVICE_ID",
nil];

First of all, you're not actually passing the request with testDevices to AdMob. To do that, you'll want to write:
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
#"TEST_DEVICE_ID",
nil];
[bannerView_ loadRequest:request];
Now when you actually release, you'll want to be able to get live ads too. To find out more information, implement GADBannerViewDelegate and log why you aren't getting an ad:
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
}
Remember you'll need to add bannerView_.delegate = self; to set the delegate for this method to be fired.

Related

How to get the full image URL on iOS with UIImagePickerController using new PHAsset stuff

How the heck do you get the full image URL on iOS with UIImagePickerController using new PHAsset stuff, since the ALAssetLibrary stuff was deprecated?
I was having an awful time finding the answer to this, so to help people in the future, here is my code that works to get the actual file URL to a photo selected with the built-in iOS UIImagePickerController. Still a little nervous about using the ALAsset URL to get the PHAsset, if you know of another way to do that then by all means please share.
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL* sourceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
if (sourceURL != nil) {
PHAsset* asset = [[PHAsset fetchAssetsWithALAssetURLs:#[sourceURL] options:nil] lastObject];
PHContentEditingInputRequestOptions* assetOptions = [[PHContentEditingInputRequestOptions alloc] init];
[assetOptions setNetworkAccessAllowed:false];
[asset requestContentEditingInputWithOptions:assetOptions
completionHandler:^(PHContentEditingInput* contentEditingInput, NSDictionary* info) {
NSURL* fullImageURL = contentEditingInput.fullSizeImageURL;
printf("Hey, got the actual image URL: %s\n", [[fullImageURL absoluteString] UTF8String]);
}];
}
// ...finish and dismiss the UIImagePickerController
}

How to play a video in iPhone simulator

I want to play a video in the iPhone simulator. I have tried with MPMoviePlayerViewController, but its not playing. Anybody has an idea on how to do it ? If there is any good tutorial , please help me find one. Thanx.
NOTE: Question related to MPMoviePlayerViewController not MPMoviePlayerController
Just drag and drop the video file in Your Xcode project
Give the url of video in "videourl"
NSURL *url = [NSURL URLWithString:videourl];
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer1];
It will run perfectly in simulator
This link Can also help You
Assuming ARC.
You can for example call that in your viewDidLoad method and add that controller to your view using:
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"test" ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
[self.view addSubview:theMovie.view];
[self addChildViewController:theMovie];
}
in my header file I write:
MPMoviePlayerController *moviePlayer;
with this property:
#property(nonatomic, strong) MPMoviePlayerController *moviePlayer;
and in the method in which I init the moviePlayer:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;
Use the following code
MPMoviePlayerController *moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:yourVideoURL];
moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer1];
[moviePlayer1 play];

AVAudioPlayer EXC_BAD_ACCESS

I am trying to pause the AVAudioPlayer if it is currently playing. When I debug my code and check AVAudioPlayer, I see it is allocated. When I try to access a method/property on it (i.e. myAudioPlayer isPlaying), I get an EXC_BAD_ACCESS error. This happens if the AVAudioPlayer does not have a sound loaded. Is there a way I can do a check to see if it has loaded a sound? I tried accessing myAudioPlayer.data, but I still get the same error.
For me it was because I wasn't calling the one of the designated initialisers. I was instantiating it with AVAudioPlayer() instead of the designated initialisers which are public init(contentsOfURL url: NSURL) throws and public init(data: NSData) throws
As of iOS 13, make sure you are removing the initialization on AVAudioPlayer before asigning it with AVAudioPlayer(contentsOf: URL(...))
i.e. change
var audioPlayer = AudioPlayer() to var audioPlayer: AVAudioPlayer!
I guess you have to use prepareToPlay method to find whether it has loaded or not.
First you have to add AVFoundation Framework.Then,import AVFounadtion framework in .h file.
.h:
AVAudioPlayer *audioPlayer;
.m:
NSURL *url1 = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/audio1.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:&error];
//audioPlayer.numberOfLoops = 0;
[audioPlayer play];
Try this code it may help you..

Hiding controls overlay in mediaplayer framework, sdk4 iphone xcode

I am building a simple & basic video app using the media player framework.
How do I hide the player control overlay in SDK4, xcode so that the user does not have access to play, pause, ff, rw, etc.?
The codes I have implemented simply do not work and either give errors or do nothing at all.
I am stumped and have not been able to find support via research. I also need to take care of a memory leak later.
I've tried:
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"1960" ofType:#"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.scalingMode = MPMovieScalingModeAspectFill;
[moviePlayerController play];
}
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"Video1" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)];
moviePlayerController.controlStyle=MPMovieControlStyleNone;
try
yourPlayer.controlStyle = MPMovieControlStyleNone;
and change yourPlayer to your name of the player.

Buttons and Images are not being added to the view on Device (works in simulator)

I'm trying to load a plist from my main bundle and it isn't working too well. I keep geting a invalid CFStringRef which results in a nil for all the displays that I wanted.
To make this even more odd. It works perfectly in the simulator. I have attached this image to help explain.
http://img847.imageshack.us/img847/1185/screenshot20110325at120m.png
This doesn't make any sense to me. It works in simulator, by why doesn't it work on the device?
- (void)viewDidLoad {
[super viewDidLoad];
imageV = [[UIImage alloc]init];
imageV = [UIImage imageNamed:[NSString stringWithFormat:#"%#", imageTitle]];
button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0, 0, 320, 65);
button.frame = frame; // match the button's size with the image size
[button setBackgroundImage:imageV forState:UIControlStateNormal];
[button addTarget:self action:#selector(adClicked:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
[self.view addSubview:button];
NSLog(#"%i %#", [self.view.subviews count], webLink);
}
in both the simulator and device the console reports that there is one subview in each view created. In the simulator the button is added and appears with its image changed. However On the Device the button does not appear with its image changed. though it says the button is there it simply doesn't appear and I can't interact with it either incase the image just wasn't setting.
//addScroller.m
I've tried cleaning the target and adding the images directly to the app folder... I got nothing. my next bet is that it has something to do with the fact that i'm loading it from a plist file or something. I did rename the ads folder and made it lower case and started pretty much from scratch. would the plist be causing the issue? is the way in which I've loaded it changing the file casing or modifying the strings?
- (void)viewDidLoad {
[super viewDidLoad];
adIndex = 0;
adTimer = [[NSTimer alloc]init];
ad = [[Ad alloc]init];
adsList = [[NSMutableDictionary alloc]init];
item = [[NSDictionary alloc]init];
filePath = [[NSString alloc]init];
filePath = [[NSBundle mainBundle] pathForResource:#"Ads" ofType:#"plist"];
NSLog(#"%#", filePath);
adsList = [[[NSMutableDictionary alloc] initWithContentsOfFile:filePath]retain];
for (int i = 0; i < [adsList count]; i++) {
item = [[NSDictionary alloc]init];
item = [adsList valueForKey:[NSString stringWithFormat:#"%i", i ]];
ad = [[Ad alloc] initWith:[item objectForKey:#"adImage"] Link:[item objectForKey:#"website"]];
//[ads addObject:a];
ad.view.frame = CGRectMake(320 * i, 0, 320, 65);
[adsView addSubview:ad.view];
[item release];
}
[adsView setContentSize:CGSizeMake(320 * [adsList count], 65)];
adsView.pagingEnabled = YES;
adIndex = HBRandomInt([adsList count]);
[self scrollAds];
[NSTimer scheduledTimerWithTimeInterval:8.0
target:self
selector:#selector(scrollAds)
userInfo:nil
repeats:YES];
//[adTimer release];
//[ad release];
//[item release];
//[adsList release];
}
EDIT: I loaded the picture elsewhere in the app and it worked fine
The simulator (Mac) isn't case sensitive. The device is. This is often what causes problems loading resources on a device that seem to work just fine in the simulator.
Don't use [[NSString alloc] init];
Try NSString *filePath = nil;

Resources