0

I have a music streaming app in which I use lock screen controls to play/pause/next the song.

I have Admob Interstitial ads in my app.

However when I use the lock screen controls, it gets passed down to the video ad as well because of which the video ad starts playing along with my app's music. Is there any way to prevent this?

Here's how I am handling the lock screen controls. I don't interact with the ads in any of this code but still the control gets passed down to admob's video player:

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {

    ////NSLog(@"CustomApp:remoteControlReceivedWithEvent:%@", event.description);
    if (event.type == UIEventTypeRemoteControl)
    {
        switch (event.subtype)
        {
            case UIEventSubtypeRemoteControlPlay:
                //  play the video
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[[SoundEngine sharedInstance] audioPlayer] resume];
                    //[[SoundEngine sharedInstance] setLockScreenElapsedTime];
                });

                break;

            case  UIEventSubtypeRemoteControlPause:
                // pause the video
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[[SoundEngine sharedInstance] audioPlayer] pause];
                    //[[SoundEngine sharedInstance] setLockScreenElapsedTime];
                });

                break;

            case  UIEventSubtypeRemoteControlNextTrack:
                // to change the video
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[SoundEngine sharedInstance] nextClicked];
                    //[[SoundEngine sharedInstance] setLockScreenElapsedTime];
                });

                break;

            case  UIEventSubtypeRemoteControlPreviousTrack:
                // to play the privious video
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[SoundEngine sharedInstance] prevClicked];
                    //[[SoundEngine sharedInstance] setLockScreenElapsedTime];
                });

                break;

            default:
                break;
        }
    }
}

1 Answers1

0

I also recently encountered an AdMob interstitial video ads playing after I called load, without ever calling present. In addition, when I did present the ads, toggling the mute switch did not work.
The versions of AdMob SDK were 7.19.1 and 7.20.0.

In the end I identified it to be an AdMob issue, but it was not so obvious. The portion that was causing the error was registering UserAgent for UserDefauts. In particular the following lines cause the problem.

let userAgent : String = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9"
UserDefaults.standard.register(defaults: ["UserAgent" : userAgent])

Probably AdMob touches user agent stored in UserDefaults when loading ads. However, I absolutely needed that custom user agent so am still unsure what I can do, but at least we know how AdMob SDK fails us in this case.

ykonda
  • 499
  • 6
  • 15
  • Instead of setting the User-Agent in the Userdefaults, why not set it on a per request's header basis? – sudoExclaimationExclaimation May 17 '17 at 20:23
  • @PranoyC on WKWebView it used to be that the request's user agent was overwritten by what is in UserDefaults, but in iOS 10 that seems to be taken care of by using customUserAgent. – ykonda May 18 '17 at 21:36