Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For iOS devices. ---The provided view controller is not being presented. #1146

Closed
lcaifu opened this issue Jul 26, 2024 · 7 comments
Closed
Assignees
Labels
in triage Issue currently being evaluated interstitial ad Issues related to Interstitial Ad platform-ios iOS applications specifically

Comments

@lcaifu
Copy link

lcaifu commented Jul 26, 2024

iOS device, InterstitialAd, when displaying A, to load B, after B loading is complete, close A at this time, and then display B will report an error. The provided view controller is not being presented.

Versions: google_mobile_ads: ^5.1.0

@malandr2
Copy link
Collaborator

Hi @lcaifu, this is an iOS only error if the UIVIewController's view.window is nil. I think a minimal reproducible sample would help with your use case - can you provide one so I can take a closer look? Thanks

@malandr2 malandr2 added the feedback required Further information is requested label Jul 26, 2024
@lcaifu
Copy link
Author

lcaifu commented Jul 29, 2024

Hi @malandr2 ,This is my sample. Thanks

class AdTestPage extends StatelessWidget {
  const AdTestPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<AdTestLogic>();
    final state = Get.find<AdTestLogic>().state;

    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        ElevatedButton(onPressed: logic.buttonA, child: Text("Button A")),
        ElevatedButton(onPressed: logic.buttonB, child: Text("Button B")),
      ],
    );
  }
}
class AdTestLogic extends GetxController {
  final AdTestState state = AdTestState();


  @override
  void onInit() {
    super.onInit();
    loadAdA();
  }

  void buttonA() {
    showA();
  }

  void buttonB() {
    showB();
  }

  InterstitialAd? appAdA;
  void loadAdA() {
    InterstitialAd.load(
        adUnitId: "ca-app-pub-3940256099942544/4411468910",
        request: const AdRequest(),
        adLoadCallback: InterstitialAdLoadCallback(
          onAdLoaded: (InterstitialAd ad) {
            appAdA = ad;
            LogI('Test A load success ${appAdA?.hashCode}');
          },
          onAdFailedToLoad: (LoadAdError error) {
            appAdA?.dispose();
            appAdA = null;
            LogI('Test A load error ${appAdA?.hashCode}');
          },
        ));
  }

  void showA() {
    appAdA?.show();
    appAdA?.fullScreenContentCallback = FullScreenContentCallback(
        onAdShowedFullScreenContent: (ad) {
          LogI('Test A onAdShowedFullScreenContent ${appAdA?.hashCode}');
          loadAdB();
        },
        onAdImpression: (ad) {},
        onAdFailedToShowFullScreenContent: (ad, err) {
          LogI('Test A onAdFailedToShowFullScreenContent: $err ${appAdA?.hashCode}');
          appAdA?.dispose();
          appAdA = null;
        },
        onAdDismissedFullScreenContent: (ad) {
          LogI('Test A onAdDismissedFullScreenContent ${appAdA?.hashCode}');
          appAdA?.dispose();
          appAdA = null;
        },
        onAdClicked: (ad) {
          LogI('Test A onAdClicked ${appAdA?.hashCode}');
        });
  }

  InterstitialAd? appAdB;
  void loadAdB() {
    InterstitialAd.load(
        adUnitId: "ca-app-pub-3940256099942544/4411468910",
        request: const AdRequest(),
        adLoadCallback: InterstitialAdLoadCallback(
          onAdLoaded: (InterstitialAd ad) {
            appAdB = ad;
            LogI('Test B load success ${appAdB?.hashCode}');
          },
          onAdFailedToLoad: (LoadAdError error) {
            appAdB?.dispose();
            appAdB = null;
            LogI('Test B load success ${appAdB?.hashCode}');
          },
        ));
  }

  void showB() {
    appAdB?.show();
    appAdB?.fullScreenContentCallback = FullScreenContentCallback(
        onAdShowedFullScreenContent: (ad) {
          LogI('Test B onAdShowedFullScreenContent ${appAdB?.hashCode}');
          loadAdA();
        },
        onAdImpression: (ad) {},
        onAdFailedToShowFullScreenContent: (ad, err) {
          LogI('Test B onAdFailedToShowFullScreenContent: $err ${appAdB?.hashCode}');
          appAdB?.dispose();
          appAdB = null;
        },
        onAdDismissedFullScreenContent: (ad) {
          LogI('Test B onAdDismissedFullScreenContent ${appAdB?.hashCode}');
          appAdB?.dispose();
          appAdB = null;
        },
        onAdClicked: (ad) {
          LogI('Test B onAdClicked ${appAdB?.hashCode}');
        });
  }
}

20240729-100315

@github-actions github-actions bot removed the feedback required Further information is requested label Jul 29, 2024
@malandr2
Copy link
Collaborator

Hi @lcaifu, your code is not reproducible for me to run, when copying it I run into errors related to classes that I don't have context to. Can you please share a minimal, reproducible example? Thanks

@malandr2 malandr2 added the feedback required Further information is requested label Jul 30, 2024
@lcaifu
Copy link
Author

lcaifu commented Jul 31, 2024

Hi @malandr2 , This is a new example code. Thanks

`import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

class TestAdPage extends StatefulWidget {
@OverRide
State createState() => _TestAdPageState();
}

class _TestAdPageState extends State {
@OverRide
void initState() {
super.initState();

loadAdA();

}

void reinitialize() {
loadAdA();
}

void buttonA() {
showA();
}

void buttonB() {
showB();
}

InterstitialAd? appAdA;
void loadAdA() {
InterstitialAd.load(
adUnitId: "ca-app-pub-3940256099942544/4411468910",
request: const AdRequest(),
adLoadCallback: InterstitialAdLoadCallback(
onAdLoaded: (InterstitialAd ad) {
appAdA = ad;
print('Test A load success ${appAdA?.hashCode}');
},
onAdFailedToLoad: (LoadAdError error) {
appAdA?.dispose();
appAdA = null;
print('Test A load error ${appAdA?.hashCode}');
},
));
}

void showA() {
appAdA?.show();
appAdA?.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (ad) {
print('Test A onAdShowedFullScreenContent ${appAdA?.hashCode}');
loadAdB();
},
onAdImpression: (ad) {},
onAdFailedToShowFullScreenContent: (ad, err) {
print('Test A onAdFailedToShowFullScreenContent: $err ${appAdA?.hashCode}');
appAdA?.dispose();
appAdA = null;
},
onAdDismissedFullScreenContent: (ad) {
print('Test A onAdDismissedFullScreenContent ${appAdA?.hashCode}');
appAdA?.dispose();
appAdA = null;
},
onAdClicked: (ad) {
print('Test A onAdClicked ${appAdA?.hashCode}');
});
}

InterstitialAd? appAdB;
void loadAdB() {
InterstitialAd.load(
adUnitId: "ca-app-pub-3940256099942544/4411468910",
request: const AdRequest(),
adLoadCallback: InterstitialAdLoadCallback(
onAdLoaded: (InterstitialAd ad) {
appAdB = ad;
print('Test B load success ${appAdB?.hashCode}');
},
onAdFailedToLoad: (LoadAdError error) {
appAdB?.dispose();
appAdB = null;
print('Test B load success ${appAdB?.hashCode}');
},
));
}

void showB() {
appAdB?.show();
appAdB?.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (ad) {
print('Test B onAdShowedFullScreenContent ${appAdB?.hashCode}');
},
onAdImpression: (ad) {},
onAdFailedToShowFullScreenContent: (ad, err) {
print('Test B onAdFailedToShowFullScreenContent: $err ${appAdB?.hashCode}');
appAdB?.dispose();
appAdB = null;
},
onAdDismissedFullScreenContent: (ad) {
print('Test B onAdDismissedFullScreenContent ${appAdB?.hashCode}');
appAdB?.dispose();
appAdB = null;
},
onAdClicked: (ad) {
print('Test B onAdClicked ${appAdB?.hashCode}');
});
}

@OverRide
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(onPressed: reinitialize, child: Text("Reinitialize")),
ElevatedButton(onPressed: buttonA, child: Text("Click first A")),
ElevatedButton(onPressed: buttonB, child: Text("Reclick B")),
],
);;
}
}
`

@github-actions github-actions bot removed the feedback required Further information is requested label Jul 31, 2024
@malandr2
Copy link
Collaborator

malandr2 commented Aug 2, 2024

Hi @lcaifu, thanks for fixing the code, I'm able to run it.

I can reproduce your issue. This appears to be a Flutter issue as I cannot reproduce this using our Interstitial example iOS repo. I have escalated this to engineering to take a closer look. We are also working on #700 and the resolution may affect this issue. In the short-term, to mitigate the issue I called loadAdB() in onAdDismissedFullScreenContent and the problem went away.

@malandr2 malandr2 added platform-ios iOS applications specifically interstitial ad Issues related to Interstitial Ad in triage Issue currently being evaluated labels Aug 2, 2024
@lcaifu
Copy link
Author

lcaifu commented Aug 5, 2024

你好@lcaifu,感谢您修复代码,我可以运行它了。

我可以重现您的问题。这似乎是 Flutter 的问题,因为我无法使用我们的 Interstitial 示例 iOS 存储库重现此问题。我已将此问题上报给工程部门以进行更深入的研究。我们也在处理#700,解决方案可能会影响此问题。在短期内,为了缓解问题,我打电话咨询loadAdB()onAdDismissedFullScreenContent问题就解决了。

Thanks,This solution can be used temporarily.

@malandr2
Copy link
Collaborator

This has been resolved with #1153 and will be included in the next google_mobile_ads plugin release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in triage Issue currently being evaluated interstitial ad Issues related to Interstitial Ad platform-ios iOS applications specifically
Projects
None yet
Development

No branches or pull requests

3 participants