I need a list of AdMob Functions SWIFT - swift

I've looked all over google's AdMob site, I just want a list of all the inbuilt functions I can use for banners and interstitials.
eg. adViewDidReceiveAd() interstitialDidDismissScreen()
If anyone knows where I can find this, please let me know.

This is bannerView functions where you have to implement GADBannerViewDelegate to be able to use it (don't forget to set the delegate for your banner as myBanner.delegate = self so they will be called).
func adViewDidReceiveAd(bannerView: GADBannerView!) {
}
func adViewDidDismissScreen(bannerView: GADBannerView!) {
}
func adViewWillDismissScreen(bannerView: GADBannerView!) {
}
func adViewWillPresentScreen(bannerView: GADBannerView!) {
}
func adViewWillLeaveApplication(bannerView: GADBannerView!) {
}
func adView(bannerView: GADBannerView!, didFailToReceiveAdWithError error: GADRequestError!) {
}
And for interstitial delegates you will need to implement GADInterstitialDelegate to able to use it.(don't forget to set the delegate for your interstitlal as interstitial.delegate = self so they will be called).
func interstitialDidReceiveAd(ad: GADInterstitial!) {
}
func interstitialDidDismissScreen(ad: GADInterstitial!) {
}
func interstitialWillDismissScreen(ad: GADInterstitial!) {
}
func interstitialWillPresentScreen(ad: GADInterstitial!) {
}
func interstitialWillLeaveApplication(ad: GADInterstitial!) {
}
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
}
Implement these after class declaration, ex: class test:GADInterstitialDelegate {}

Related

Swift - How can cardParams be obtained from STPPaymentOptionsViewController

I want to complete the addition of new payment method that I implemented in this SO question. This save and reuse stripe tutorial shows that cardParams and billingDetails need to be passed to STPPaymentMethodParams. How to I get the cardParams and billingDetails from STPPaymentOptionsViewController?
This is the code that produce the STPPaymentOptionsViewController and then display the STPAddCardViewController when add card button is pressed.
import Foundation
import SwiftUI
import Stripe
struct PaymentOptionsView: UIViewControllerRepresentable {
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, STPPaymentOptionsViewControllerDelegate {
var control: PaymentOptionsView
init(_ control: PaymentOptionsView) {
self.control = control
}
// Implement required delegate methods here:
func paymentOptionsViewControllerDidCancel(_ paymentOptionsViewController: STPPaymentOptionsViewController) {
}
func paymentOptionsViewControllerDidFinish(_ paymentOptionsViewController: STPPaymentOptionsViewController) {
}
func paymentOptionsViewController(_ paymentOptionsViewController: STPPaymentOptionsViewController, didFailToLoadWithError error: Error) {
}
}
func makeUIViewController(context: UIViewControllerRepresentableContext<PaymentOptionsView>) -> STPPaymentOptionsViewController {
let config = STPPaymentConfiguration()
// config.requiredBillingAddressFields = .none
config.appleMerchantIdentifier = "dummy-merchant-id"
return STPPaymentOptionsViewController(configuration: config, theme: STPTheme(), apiAdapter: STPCustomerContext(keyProvider: MyAPIClient()), delegate: context.coordinator)
}
func updateUIViewController(_ uiViewController: STPPaymentOptionsViewController, context: UIViewControllerRepresentableContext<PaymentOptionsView>) { }
}
STPPaymentOptionsViewController by design only returns you a PaymentMethod and not the raw card details.
Since the STPPaymentOptionsViewControllerDelegate returns you a STPPaymentOption, you can cast it to a STPPaymentMethod and then get the billingDetails for that PaymentMethod.
In your didSelect() delegate method, you can cast it like:
if let paymentMethod = paymentOption as? STPPaymentMethod {
print(paymentMethod.stripeId)
}
https://stripe.dev/stripe-ios/docs/Classes/STPPaymentMethod.html#/c:#M#Stripe#objc(cs)STPPaymentMethod(py)billingDetails

FirebaseUI "Sign in with email" does nothing when tapped

I have the following code taken directly from this blog. This code successfully displays the FirebaseUI with Google sign In, Apple sign In, and Email sign in when I place the SignInViewUI into my view.
Google and Apple sign in both function correctly. Email sign in does nothing when tapped.
import Firebase
import FirebaseUI
import SwiftUI
typealias AM = AuthManager
class AuthManager : NSObject{
static let shared = AuthManager()
var authViewController : UIViewController {
return MyAuthViewController(authUI: FUIAuth.defaultAuthUI()!)
}
init(withNavigationBar : Bool = false){
FirebaseApp.configure()
super.init()
self.setupProviders()
}
private func setupProviders(){
let authUI = FUIAuth.defaultAuthUI()!
let providers: [FUIAuthProvider] = [
FUIGoogleAuth.init(authUI: authUI),
FUIOAuth.appleAuthProvider(),
FUIEmailAuth()]
authUI.providers = providers
}
}
extension AuthManager {
// an optional handler closure for error handling
func signOut(onError handler : ((Error?) -> Void)? = nil ){
do {
try FUIAuth.defaultAuthUI()?.signOut()
if let handler = handler {
handler(nil)
}
}
catch (let err){
if let handler = handler {
handler(err)
}
}
}
func isSignedIn() -> Bool {
if let _ = Firebase.Auth.auth().currentUser{
return true
}
return false
}
}
extension AuthManager {
func setAuthDelegate(_ delegate : FUIAuthDelegate){
FUIAuth.defaultAuthUI()?.delegate = delegate
}
}
class MyAuthViewController : FUIAuthPickerViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scrollView = view.subviews[0]
scrollView.backgroundColor = .clear
let contentView = scrollView.subviews[0]
contentView.backgroundColor = .clear
view.backgroundColor = .clear
}
}
struct SignInViewUI: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<SignInViewUI>) ->
UIViewController {
return AM.shared.authViewController
}
func updateUIViewController(_ uiViewController: UIViewController,
context: UIViewControllerRepresentableContext<SignInViewUI>) {
// empty
}
}
I believe this is something to do with a navigation controller being required for the Email sign in, based on the final comment on this GitHub issue.
Surrounding the SignInViewUI in a NavigationView allows the button to work.
Secondly, the FirebaseApp.configure() line must be removed from the AuthManager and placed into the AppDelegate application(_ application: UIApplication, didFinishLaunchingWithOptions ... method.

Why is my data not passing between View Controllers using closure?

I am trying to pass data receive from a network call to another view controller when user has clicked on a button. When making printing on the FirstVC, data is in, but when printing the result in the SecondVC, there is no more value. I don' t want to use delegate but closure instead.
Also, when trying to retain the memory cycle, an error appear...
class APIsRuler {
static var oneRecipeFound: ((OneRecipeSearch) -> ())?
}
class FirstVC: UIViewController {
func cellIsClicked(index: Int) {
APIsRuler.shared.getRecipe(from: recipeID) { (success, oneRecipe) in
if success, let oneRecipe = oneRecipe {
APIsRuler.oneRecipeFound?(oneRecipe)
self.performSegue(withIdentifier: "goToSecondVC", sender: self)
}
}
}
}
Class SecondVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
APIsRuler.oneRecipeFound = { result in
print(result)
}
}
}
Doing this in SecondVC
APIsRuler.oneRecipeFound = { result in
print(result)
}
and this in first
APIsRuler.oneRecipeFound?(oneRecipe)
have no inner communications , you need to read your data directly from the shared class in the secondVc after the segue or send it in
self.performSegue(withIdentifier: "goToSecondVC", sender: <#Herererere#>)
and implement prepareForSegue
Let’s think about the order in which things are happening:
class APIsRuler {
static var oneRecipeFound: ((OneRecipeSearch) -> ())? // 1
}
class FirstVC: UIViewController {
func cellIsClicked(index: Int) {
APIsRuler.shared.getRecipe(from: recipeID) { (success, oneRecipe) in
if success, let oneRecipe = oneRecipe {
APIsRuler.oneRecipeFound?(oneRecipe) // 2
self.performSegue(withIdentifier: "goToSecondVC", sender: self)
}
}
}
}
Class SecondVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
APIsRuler.oneRecipeFound = { result in // 3
print(result)
}
}
}
oneRecipeFound starts out life empty: it is nil.
In FirstVC, the cell is clicked. We call oneRecipeFound. It is still nil, so nothing happens.
In SecondVC, we set the value of oneRecipeFound. Now it has a value, but the call has already happened.
So unless you have a time machine in your pocket, so that you can reverse that order of events somehow, the strategy you’ve outlined is doomed to failure. Of course, if you call oneRecipeFound after setting it, it will work. For example:
Class SecondVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
APIsRuler.oneRecipeFound = { result in
print(result)
}
APIsRuler.oneRecipeFound?(oneRecipe) // prints
}
}

How to use autopoolrelease in swift

The use of autoreleasepool{} in swift is as follows.
autoreleasepool {
// all usage here
}
But I do not know how to use it in public.
Example
class ViewController: UIViewController {
autoreleasepool {
var results: Results<Item>!
}
override func viewDidLoad() {
super.viewDidLoad()
.....
}
}
If this is public, an error occurs. Does autoreleasepool{} need to be in func only?

How can I get my iAd interstitial to work

I've looked everywhere for this but I can't find it. I've checked the code and it works in the simulator but not on the real app on the App Store. I launched the app which used this ad code way back in January and the adverts are still not working, all the billing and stuff is filled in on iTunes connect, I don't know how to fix it.
This is my code for the ads:
func loadInterstitialAd() {
interstitialAd = ADInterstitialAd()
interstitialAd.delegate = self
}
func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) {
}
func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
interstitialAdView = UIView()
interstitialAdView.frame = self.view!.bounds
view!.addSubview(interstitialAdView)
interstitialAd.presentInView(interstitialAdView)
UIViewController.prepareInterstitialAds()
}
func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
interstitialAdView.removeFromSuperview()
}
func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
}
func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
interstitialAdView.removeFromSuperview()
}