【发布时间】:2017-05-09 22:10:26
【问题描述】:
当点击 adText 按钮时,我的 admob 插页式广告没有显示。我希望显示插页式广告,并在关闭时运行我的 text() 函数。我希望在按下我的 adCall 按钮但在关闭插页式广告以运行我的 call() 函数之后发生同样的事情。
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 init 上的属性传递或使用委托可以解决您的问题吗?
标签: ios swift admob ibaction interstitial