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,
Related
I have a Reality Composer file with several scenes, all of which starts empty and then some models appear one by one every second. Even though the animation works perfectly in Quicklook and Reality Composer, it does a strange glitch when I try to integrate it in my app with Xcode. When the very first scene is launched or when we go to another scene, they don't start empty.. For a tiny split second, we see all the models of that scene being displayed, only to disappear immediately.
Then, we see them appearing slowly as they were supposed to. That tiny flash of models at the beginning of each scene is ruining everything. I tried using a .reality file and a .rcproject file, same problem. In fact, when we preview the animation of the Reality file inside Xcode, it does the same glitch. I tried using different Hide and Show functions, no change.. I tried different triggers such as notifications, scene start, on tap, no change.
I checked quite some tutorials and still couldn't find anything wrong in what I'm doing. I almost feel like there is a glitch in the current integration of Reality Composer. I would really appreciate some ideas on the subject...
Try this to prevent a glimpse...
import UIKit
import RealityKit
class ViewController: UIViewController {
#IBOutlet var arView: ARView!
var box: ModelEntity!
override func viewDidLoad() {
super.viewDidLoad()
let scene = try! Experience.loadScene()
self.box = scene.cube!.children[0] as? ModelEntity
self.box.isEnabled = false
arView.scene.anchors.append(scene)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.box.isEnabled = true
}
}
}
In such a scenario glitching occurs only for sphere. Box object works fine.
#AndyJazz Thanks. This solution works for me. Alternately to the line :
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.box.isEnabled = true
I suggest (while in Reality Composer) Create a Behavior with:
Trigger Scene Start
Action Show
The appearance of the entity can then also be tweaked with a Motion Type, Ease Type and Style as well as chained to additional sequences.
I have implemented a pager in which each page shows the user a video. Each page has his own AVPlayer instanciated.
Everything work as expected until the 17th video.
I read a lot regarding this issue. It appears that this is an Apple limitation, where an app is limited to display the player layers.
The solution I tried (several sources says it fixes the issue) is to remove the player layer from its parent and set the player to Nil. So each time a page disappears (didDisappear) I call:
// player and playerLayer are init at viewWillAppear().
player?.pause()
player = nil
playerLayer?.removeFromSuperlayer()
That does not change anything... I am still limited to 16 video plays.
Thus, my question is:
1) Why this behavior? Is it really expected?
2) How do Musical.ly or Snapchat achieve to switch infinitly between videos?
Thanks a lot for your help.
Try to change your code with
player?.pause()
player?.replaceCurrentItem(with: nil)
playerLayer?.removeFromSuperlayer()
player = nil
setting nil item into player will stop playing.
1) Yes, it's expected behavior for AVPlayer. It was designed for video players creation or for displaying ads videos in games, but not for videos walls like has Instagram or similar services.
2) It's simple. They are not using AVPlayer. For your purpose you can use combination of AVAssetReader and AVSampleBufferDisplayLayer
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.
I have successfully integrated a working movie player with a pre-roll iAd video! Thanks to #Daniel Storm. However, I want information on how to exit the movie when the movie is finished or when the ad is finished. (exit means remove from the view), Also detect if the user has watched the ad. If there is internet connection failure or iAd failure, how can i detect if the pre-roll ad did not play.
I am making a game, and if a user decides to get more coins, that person must watch an ad. If they click on the watch ad button, I want to detect if the ad loaded successfully so that person can get coins after they watch the ad. Once the ad finishes I want to dismiss the MPMoviePlayerController view.
Thank you for your help!
Edit:
Is this correct? :
Is it ok to remove the MPMoviePlayerViewController from the view after it is played like this?: Is this the correct way to remove it?
moviePlayer.playPrerollAdWithCompletionHandler { (error) -> Void in
NSLog("\(error)")
self.moviePlayer.view.removeFromSuperview()
I am supposing this is correct because it removes the view, but is this what apple intends us to do?
I'm developing a camera app to snap photo when the volume button is pressed.
I used AudioSessionAddPropertyListener(kAudioSessionProperty_CurrentHardwareOutputVolume, audioVolumeChangeListenerCallback, self); to successfully get notified when a volume button get pressed before my camera started. However, after I started the camera, this property listener no longer works. Is it get auto deactivated or something?
I have tried to implement a custom UIImagePickerController to include the Audio Session Property Listener inside the ImagePickerController but with no hope. Grateful if anyone can share your view. Thanks.
I'm sorry to say that this is something that is not supported in IOS4. If you managed to implement this successfully the app will get rejected by apple.
However is was announced at WWDC 2011 that this is fully supported in IO5 and will be default behaviour when using UIImagePickerController in any app.
Hope this helps.
Even in the default camera app on the iphone, turning up/down the volume is not supported. May be they block the input from those buttons when the camera is turned on. What they dont block is the silent switch. I added this notification and my callback was called even with the camera on:
AudioSessionInitialize(nil, nil, nil, nil);
AudioSessionSetActive(true);
AudioSessionAddPropertyListener(
kAudioSessionProperty_AudioRouteChange,
applicationAudioRouteDidChange,
self);
The problem you need to solve is that the 'applicationAudioRouteDidChange' method will also be called if someone inserts the headphones. You can check this as said in the AudioSessionProgrammingGuide:
When the system invokes a route-change callback, it provides the
information you need to figure out which action to take. Base your
callback on the AudioSessionPropertyListener prototype from audio
session services, as shown here:
void MyPropertyListener ( void *inClientData, AudioSessionPropertyID inID,UInt32 inDataSize, const void *inData );
For a route change event, the
system sends the kAudioSessionProperty_AudioRouteChange in the inID
parameter.
The inData parameter sent to your callback contains a CFDictionaryRef
object that describes:
Why the route changed What the previous route was
I did this and it takes the picture when silent switch is mmmm switched:
void applicationAudioRouteDidChange(void *inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize, const void *inData)
{
if ([[(NSDictionary*)inData objectForKey:#"OutputDeviceDidChange_Reason"] intValue] == 5) {
[((RootViewController*)inClientData).picker takePicture];
}
// Do something like reset the system
}
As mentioned by Tom, the functionality you are trying to implement would be a part of iOS 5.