1
单击adText按钮时,我的admob插页式广告未显示。我希望展示插页式广告,何时解散以运行我的文字()函数。当我的adCall按钮被按下时,我希望发生同样的事情,但插页式广告被解雇后运行我的call()函数。为什么admob插页式广告没有在iOS上显示?
enum RequestType{
case call
case text
}
var requestType: RequestType?
@IBAction func adText(_ sender: Any) {
requestType = .text
presentInterstitialAd()
text()
}
@IBAction func adCall(_ sender: Any) {
requestType = .call
presentInterstitialAd()
call()
}
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitialAd = reloadInterstitialAd()
}
func presentInterstitialAd() {
if self.interstitialAd.isReady {
self.interstitialAd.present(fromRootViewController: self)
}
}
func invokeRequest() {
guard let requestType = requestType else {
fatalError("NO request type specified!")
}
switch requestType {
case .call: invokeCall()
case .text: invokeText()
}
}
func invokeCall() {}
func invokeText() {}
func call() {
if let contactopt = contact {
if let url = NSURL(string: "tel://\(contactopt)") {
// UIApplication.shared.openURL(url as URL)
UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
}
}
}
func text(){
if canSendText() {
if let contactopt = contact{
let messageVC = MFMessageComposeViewController()
messageVC.recipients = [String(contactopt)]
messageVC.messageComposeDelegate = self;
self.present(messageVC, animated: false, completion: nil)}}
else {
let alertController = UIAlertController(title: "Cannot Send Text Message", message: "Your device is not able to send text messages.", preferredStyle: UIAlertControllerStyle.alert)
let DestructiveAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.destructive) {
(result : UIAlertAction) -> Void in
print("error")
}
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
(result : UIAlertAction) -> Void in
print("OK")
}
alertController.addAction(DestructiveAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
}
}
我不认为你可以做到这一点。将'text()'函数作为ViewController初始化或使用委托的属性传递是否解决了您的问题? – Valdmer