admob-plus / admob-plus

Trustable AdMob Plugin for Cordova, Capacitor, Ionic, React Native
https://admob-plus.github.io
MIT License
361 stars 150 forks source link

admob-plus-cordova Not Working in Capacitor #661

Closed harryt2 closed 3 weeks ago

harryt2 commented 1 month ago

The capacitor plugin is very old and the interstitials don't work after the first .showInterstitial().

If you try to use the admob-plus-cordova plugin, it throws an error on iOS that reads Value of type 'WKWebView' has no member 'engineWebView' on line 180 of the AMBPlugin.swift file.

ratson commented 1 month ago

@harryt2 Would you try the latest version to see if it works?

harryt2 commented 1 month ago

Just tried it and had the same problem.

Screenshot 2024-04-12 at 11 46 57 AM

Asked Claude about it and it said

The error message "Value of type 'WKWebView' has no member 'engineWebView'" indicates that the WKWebView class does not have a property or member named engineWebView.

In Capacitor, the web view is directly accessible through the WKWebView class, and there is no need for the engineWebView property that is specific to Cordova.

To fix this issue, you can modify the code to work with Capacitor by directly accessing the WKWebView instance. 

Not sure if the above helps or not. After inspecting the WKWebView class it looks like this:


@available(iOS 8.0, *)
open class WKWebView : UIView {
@NSCopying open var configuration: WKWebViewConfiguration { get }

weak open var navigationDelegate: WKNavigationDelegate?

weak open var uiDelegate: WKUIDelegate?

open var backForwardList: WKBackForwardList { get }

public init(frame: CGRect, configuration: WKWebViewConfiguration)

public init?(coder: NSCoder)

open func load(_ request: URLRequest) -> WKNavigation?

@available(iOS 9.0, *)
open func loadFileURL(_ URL: URL, allowingReadAccessTo readAccessURL: URL) -> WKNavigation?

open func loadHTMLString(_ string: String, baseURL: URL?) -> WKNavigation?

@available(iOS 9.0, *)
open func load(_ data: Data, mimeType MIMEType: String, characterEncodingName: String, baseURL: URL) -> WKNavigation?

open func go(to item: WKBackForwardListItem) -> WKNavigation?

open var title: String? { get }

open var url: URL? { get }

open var isLoading: Bool { get }

open var estimatedProgress: Double { get }

open var hasOnlySecureContent: Bool { get }

@available(iOS 10.0, *)
open var serverTrust: SecTrust? { get }

open var canGoBack: Bool { get }

open var canGoForward: Bool { get }

open func goBack() -> WKNavigation?

open func goForward() -> WKNavigation?

open func reload() -> WKNavigation?

open func reloadFromOrigin() -> WKNavigation?

open func stopLoading()

open func evaluateJavaScript(_ javaScriptString: String, completionHandler: ((Any?, Error?) -> Void)? = nil)

open func evaluateJavaScript(_ javaScriptString: String) async throws -> Any

@available(iOS 15.0, *)
open func closeAllMediaPresentations(completionHandler: (() -> Void)? = nil)

@available(iOS 15.0, *)
open func closeAllMediaPresentations() async

@available(iOS, introduced: 14.5, deprecated: 15.0)
open func closeAllMediaPresentations()

@available(iOS 15.0, *)
open func pauseAllMediaPlayback(completionHandler: (() -> Void)? = nil)

@available(iOS 15.0, *)
open func pauseAllMediaPlayback() async

@available(iOS 15.0, *)
open func setAllMediaPlaybackSuspended(_ suspended: Bool, completionHandler: (() -> Void)? = nil)

@available(iOS 15.0, *)
open func setAllMediaPlaybackSuspended(_ suspended: Bool) async

@available(iOS 15.0, *)
open func requestMediaPlaybackState(completionHandler: @escaping (WKMediaPlaybackState) -> Void)

@available(iOS 15.0, *)
open func requestMediaPlaybackState() async -> WKMediaPlaybackState

@available(iOS 15.0, *)
open var cameraCaptureState: WKMediaCaptureState { get }

@available(iOS 15.0, *)
open var microphoneCaptureState: WKMediaCaptureState { get }

@available(iOS 15.0, *)
open func setCameraCaptureState(_ state: WKMediaCaptureState, completionHandler: (() -> Void)? = nil)

@available(iOS 15.0, *)
open func setCameraCaptureState(_ state: WKMediaCaptureState) async

@available(iOS 15.0, *)
open func setMicrophoneCaptureState(_ state: WKMediaCaptureState, completionHandler: (() -> Void)? = nil)

@available(iOS 15.0, *)
open func setMicrophoneCaptureState(_ state: WKMediaCaptureState) async

@available(iOS 11.0, *)
open func takeSnapshot(with snapshotConfiguration: WKSnapshotConfiguration?, completionHandler: @escaping (UIImage?, Error?) -> Void)

@available(iOS 11.0, *)
open func takeSnapshot(configuration snapshotConfiguration: WKSnapshotConfiguration?) async throws -> UIImage

open var allowsBackForwardNavigationGestures: Bool

@available(iOS 9.0, *)
open var customUserAgent: String?

@available(iOS 9.0, *)
open var allowsLinkPreview: Bool

open var scrollView: UIScrollView { get }

@available(iOS 14.0, *)
open var pageZoom: CGFloat

@available(iOS 11.0, *)
open class func handlesURLScheme(_ urlScheme: String) -> Bool

@available(iOS 14.5, *)
open func startDownload(using request: URLRequest, completionHandler: @escaping (WKDownload) -> Void)

@available(iOS 14.5, *)
open func startDownload(using request: URLRequest) async -> WKDownload

@available(iOS 14.5, *)
open func resumeDownload(fromResumeData resumeData: Data, completionHandler: @escaping (WKDownload) -> Void)

@available(iOS 14.5, *)
open func resumeDownload(fromResumeData resumeData: Data) async -> WKDownload

@available(iOS 14.0, *)
open var mediaType: String?

@available(iOS 15.0, *)
open var interactionState: Any?

@available(iOS 15.0, *)
open func loadSimulatedRequest(_ request: URLRequest, response: URLResponse, responseData data: Data) -> WKNavigation

@available(iOS, introduced: 15.0, deprecated: 15.0)
open func loadSimulatedRequest(_ request: URLRequest, with response: URLResponse, responseData data: Data) -> WKNavigation

@available(iOS 15.0, *)
open func loadFileRequest(_ request: URLRequest, allowingReadAccessTo readAccessURL: URL) -> WKNavigation

@available(iOS 15.0, *)
open func loadSimulatedRequest(_ request: URLRequest, responseHTML string: String) -> WKNavigation

@available(iOS, introduced: 15.0, deprecated: 15.0)
open func loadSimulatedRequest(_ request: URLRequest, withResponseHTML string: String) -> WKNavigation

@available(iOS 15.0, *)
open var themeColor: UIColor? { get }

@available(iOS 15.0, *)
@NSCopying open var underPageBackgroundColor: UIColor!

@available(iOS 16.0, *)
open var fullscreenState: WKWebView.FullscreenState { get }

@available(iOS 15.5, *)
open var minimumViewportInset: UIEdgeInsets { get }

@available(iOS 15.5, *)
open var maximumViewportInset: UIEdgeInsets { get }

@available(iOS 15.5, *)
open func setMinimumViewportInset(_ minimumViewportInset: UIEdgeInsets, maximumViewportInset: UIEdgeInsets)

@available(iOS 16.0, *)
open var isFindInteractionEnabled: Bool

@available(iOS 16.0, *)
open var findInteraction: UIFindInteraction? { get }

@available(iOS 16.4, *)
open var isInspectable: Bool
}

@available(iOS 14.0, macOS 11.0, *)
extension WKWebView {

@MainActor public func callAsyncJavaScript(_ functionBody: String, arguments: [String : Any] = [:], in frame: WKFrameInfo? = nil, in contentWorld: WKContentWorld, completionHandler: ((Result<Any, Error>) -> Void)? = nil)

@MainActor public func createPDF(configuration: WKPDFConfiguration = .init(), completionHandler: @escaping (Result<Data, Error>) -> Void)

@MainActor public func createWebArchiveData(completionHandler: @escaping (Result<Data, Error>) -> Void)

@MainActor public func evaluateJavaScript(_ javaScript: String, in frame: WKFrameInfo? = nil, in contentWorld: WKContentWorld, completionHandler: ((Result<Any, Error>) -> Void)? = nil)

@MainActor public func find(_ string: String, configuration: WKFindConfiguration = .init(), completionHandler: @escaping (WKFindResult) -> Void)
}

@available(iOS 15.0, macOS 12.0, *)
extension WKWebView {

@MainActor public func callAsyncJavaScript(_ functionBody: String, arguments: [String : Any] = [:], in frame: WKFrameInfo? = nil, contentWorld: WKContentWorld) async throws -> Any?

@MainActor public func pdf(configuration: WKPDFConfiguration = .init()) async throws -> Data

@MainActor public func evaluateJavaScript(_ javaScript: String, in frame: WKFrameInfo? = nil, contentWorld: WKContentWorld) async throws -> Any?

@MainActor public func find(_ string: String, configuration: WKFindConfiguration = .init()) async throws -> WKFindResult
}
@available(iOS 14.5, *)
public enum WKMediaPlaybackState : Int, @unchecked Sendable {

case none = 0

case playing = 1

case paused = 2

case suspended = 3
}
@available(iOS 15.0, *)
public enum WKMediaCaptureState : Int, @unchecked Sendable {

case none = 0

case active = 1

case muted = 2
}
extension WKWebView {

@available(iOS 16.0, *)
public enum FullscreenState : Int, @unchecked Sendable {

    case notInFullscreen = 0

    case enteringFullscreen = 1

    case inFullscreen = 2

    case exitingFullscreen = 3
}
}

extension WKWebView {

@available(iOS, introduced: 9.0, deprecated: 10.0)
open var certificateChain: [Any] { get }
}
ratson commented 1 month ago

@harryt2 Just realize your were using the cordova plugin, which is not supported for capacitor. Please use @admob-plus/capacitor instead, see https://admob-plus.github.io/docs/capacitor

harryt2 commented 4 weeks ago

Ah ok, didn't realize it wouldn't work. Thanks for looking into it.

Trying out the capacitor one since you pushed an update on April 8th.

Should the version bump of the ads SDK also be in the AdmobPlusCapacitor.podspec file? I think it's still 8.13.0 in there so when I npx cap sync it's adding that one.

harryt2 commented 4 weeks ago

Got an error on line 47 of the AMBInterstitial.swift (also in AMBRewardedInterstital)

Cannot override 'adDidPresentFullScreenContent' which has been marked unavailable


func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
     self.emit(AMBEvents.interstitialShow)
}
harryt2 commented 4 weeks ago

A couple more in AdMobPlusPlugin.swift:50

Value of type 'GADRequestConfiguration' has no member 'tag' Value of type 'GADRequestConfiguration' has no member 'tagForUnderAge'


 @objc func configRequest(_ call: CAPPluginCall) {
        let ctx = AMBContext(call)
        let requestConfiguration = GADMobileAds.sharedInstance().requestConfiguration

        if let maxAdContentRating = ctx.optMaxAdContentRating() {
            requestConfiguration.maxAdContentRating = maxAdContentRating
        }

        if let tag = ctx.optChildDirectedTreatmentTag() {
            requestConfiguration.tag(forChildDirectedTreatment: tag)
        }

        if let tag = ctx.optUnderAgeOfConsentTag() {
            requestConfiguration.tagForUnderAge(ofConsent: tag)
        }

        if let testDevices = ctx.optTestDeviceIds() {
            requestConfiguration.testDeviceIdentifiers = testDevices
        }

        ctx.resolve()
    }

Seems like a lot has changed between the versions
harryt2 commented 3 weeks ago

Just tried @admob-plus/capacitor@2.0.0-alpha.3 and it works! Closing this thread.