I've successfully been able to integrate both banner ads and image based interstitial ads into my applications with no problems.
I'm considering adding a reward based video ad however I'm not sure if I can simply set up the code as per the interstitial ad but change the adUnitID to that of the rewarded video ad I set up in Admob?
When I do just that the test ad showing an interstitial therefore I can't tell if a video would display.
I'm finding very little guidance to follow online with regard to setting it up this way.
This is what I currently use:
func loadAndShow3() {
let request = GADRequest()
request.testDevices = [kGADSimulatorID, "XXXX"]
myAd = GADInterstitial(adUnitID: "XXXX")
myAd.delegate = self
myAd.load(request)
}
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
if (self.myAd.isReady) {
myAd.present(fromRootViewController: self)
}
func displayAd() {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "loadAndShow"), object: nil)
}
Your current code would not work. You would have to make a new request for a GADRewardBasedVideoAd instead of the GADRequest(). There is a really good tutorial made by Google at how to do that attached below. If you follow the tutorial it's a rather straight forward solution. Best of luck to you.
Google's tutorial.
Related
i want to implement real admob ads in my unity game, i have found banner ad code from google and i replaced test unit id with my real admob app unit id. now problem is that when banner ad show a test ad will be app appeared on to top side of banner ad pls help why show show test ad while i implement real add unitID here is banner ad code.
using System;
using UnityEngine;
using GoogleMobileAds.Api;
public class realsimpleAd : MonoBehaviour
{
private BannerView bannerView;
public void Start()
{
this.RequestBanner();
}
private void RequestBanner()
{
string adUnitId = "ca-app-pub-1154915214031679/1860375924";
this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);
// Called when an ad request has successfully loaded.
this.bannerView.OnAdLoaded += this.HandleOnAdLoaded;
// Called when an ad request failed to load.
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
this.bannerView.LoadAd(request);
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLoaded event received");
}
}
pls help me thanks in advance
Admob will always show test ads in the Unity editor and in applications with few views and recently published.
To experience real ads, you will need to post your app on a store and wait until it downloads enough to show the ads.
As soon as it is published, no ads will appear, because it has not received enough views.
I want to get reward after Ads have been playing finished, now I will get reward when I close the Ads, I don't want this. Here is my code now, in GADFullScreenContentDelegate:
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Rewarded ad dismissed.")
// function which can get reward.
getReward()
}
I don't know where I have to put this function in, is there any delegate that can know the Ads have been playing finished?
I'm trying to get rich notification and play video on the notification.
I success to show an image and not found swift sample code.
What need to be done to add video clip / mp4 notification support?
which function need to add to the NotificationService class ?
Thanks Yakir
There is no need to add extra code and no need to use AV player also. we can achieve that by initialising UNNotificationAttachment with url which we get after URLSession.shared.downloadTask
URLSession.shared.downloadTask(with: attachmentURL) { url, _ , _ in
let attachment = try UNNotificationAttachment(identifier: "identifier", url: url, options: nil)
content.attachments.append(attachment)
}
While updating the content in NotificationServiceExtension. Notification will load the video if it is video url.
Note: - please make sure video should be small size or as suggested by Apple.
When using the AVCaptureSession to connect a AVCaptureDevice the device get's locked by the application and can not be released. The only way the device is truly released is after restarting the app.
We are using AVCaptureSession for previewing the camera and audio level meters. But once we start the actual capture we might need to switch to an alternative capture SDK (in this case DeckLink SDK). How ever the device remains locked by AVFoundation and we can't seem to free it in any way.... It all goes sideways as soon as wel call AVCaptureSession.addInput on the AVCaptureSession from the AVCaptureDevice. And simply iterating the inputs and using AVCaptureSession.removeInput does not seem work.
We setup the session like this:
do {
try self.selectedVideoDevice.lockForConfiguration()
try self.selectedAudioDevice?.lockForConfiguration()
self.cameraSession = AVCaptureSession()
self.cameraSession?.beginConfiguration()
self.cameraSession?.sessionPreset = AVCaptureSession.Preset.high
// Add some outputs... not relevant for the issue at hand?!
// Add audio input
if self.selectedAudioDevice != nil {
let deviceInputAudio = try AVCaptureDeviceInput(device: self.selectedAudioDevice!)
if self.cameraSession?.canAddInput(deviceInputAudio) ?? false {
self.cameraSession?.addInput(deviceInputAudio)
}
}
// Add video input
let deviceInputVideo = try AVCaptureDeviceInput(device: self.selectedVideoDevice)
if self.cameraSession?.canAddInput(deviceInputVideo) ?? false {
self.cameraSession?.addInput(deviceInputVideo)
}
self.cameraSession?.commitConfiguration()
self.cameraSession?.startRunning()
self.selectedVideoDevice.unlockForConfiguration()
self.selectedAudioDevice?.unlockForConfiguration()
} catch {
}
And try to release using something like this... one of the many tries...
self.cameraSession?.stopRunning()
for output in self.cameraSession?.outputs ?? [] {
self.cameraSession?.removeOutput(output)
}
for input in self.cameraSession?.inputs ?? [] {
self.cameraSession?.removeInput(input)
}
self.cameraSession = nil
How ever we can't get the device to be recognized in the DeckLink SDK after using in AVFoundation.
Any ideas would be great as cleaning up or setting the variables to nil doesn't seem to do anything...
We chose to implement the Desktop Video SDK from Blackmagic and do all captures from a Blackmagic device using that. This solves more issues when capturing using Blackmagic Mini Recorder (for example: audio sync) somehow AVFoundation does work with Blackmagic but not really well. And Blackmagic officially never answered the question "Do you support AVFoundation". So in order to make it work I would recommend the Desktop Video SDK that can be downloaded from their site under Support.
https://www.blackmagicdesign.com/support/
Also make sure you never load the video device into your AVFoundation workflow. It will get stuck and hold it. So first check if it's Blackmagic then continue to AVFoundation if not.
Ive opted towards RevMob since the iAd network isn't accepting new apps and I'm trying to put a video ad after a round of my game is played like this:
func gameOver() {
RevMobAds.session().fullscreen().loadVideo()
RevMobAds.session().fullscreen().showVideo()
let transition = SKTransition.fadeWithDuration(0.5)
let gameScene = GameOver(size: self.size)
self.view!.presentScene(gameScene, transition: transition)
}
My fullscreen and banner ads are working perfectly, but when I end the game to load the video, I get this in the console with no ad being shown:
[RevMob] Ad received: (200) - 56ba71998e700003764c65b9
Is anyone else having this problem? If so, have you fixed it?
We have changed our documentation, please checkout the updated one here.
What I believe is happening is that you are not saving the fullscreen object. You should create a fullscreen object and save it into a variable:
video = RevMobAds.session().fullscreen()
Then you can load a video ad into the fullscreen object: video!.loadVideo()
And then showVideo on the fullscreen object: video!.showVideo()
Note that loadVideo() is an asynchronous call, so you should either call the methods with completion handlers or extend our delegate classes.
Best regards,