ionic-team / capacitor-docs

https://capacitorjs.com/docs
Apache License 2.0
20 stars 196 forks source link

[Bug]: locally "Custom Native iOS Code" not working (Capacitor 6) #275

Closed rricamar closed 2 months ago

rricamar commented 4 months ago

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 5.7.1 @capacitor/core: 5.7.1 @capacitor/android: 5.7.1 @capacitor/ios: 5.7.1

Installed Dependencies:

@capacitor/cli: 6.0.0-rc.0 @capacitor/core: 6.0.0-rc.0 @capacitor/android: 6.0.0-rc.0 @capacitor/ios: 6.0.0-rc.0

[success] iOS looking great! 👌 [success] Android looking great! 👌

Other API Details

npm 10.2.4
node v20.11.1
pod 1.14.3

Platforms Affected

Current Behavior

I was trying Capacitor 6 today and just discovered that the local Echo plugin from the tutorial is not working (https://capacitorjs.com/docs/ios/custom-code). If I rollback to Capacitor 5.7.1 it works as usual.

Note: I'm using it directly through window.Capacitor.Plugins.Echo (which is now undefined).

Note 2: Another plugin installed and created with https://github.com/ionic-team/create-capacitor-plugin works fine.

Note 3: On Android is working well.

Expected Behavior

Plugin invocation should work as described in the docs.

Project Reproduction

N/A

Additional Information

No response

ionitron-bot[bot] commented 4 months ago

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

jcesarmobile commented 4 months ago

Capacitor 6 removes the automatic plugin registration for iOS, so for non npm plugins, users will have to call registerPlugin as on Android.

That would require using a custom CAPBridgeViewController subclass as explained here

https://capacitorjs.com/docs/ios/viewcontroller

And override it's capacitorDidLoad to register the plugin there, something like this:

override open func capacitorDidLoad() {
    bridge?.registerPluginInstance(EchoPlugin())
}

Moving to capacitor-docs since we have to write docs for it.

xbisa commented 2 weeks ago

I'm facing the same issue for NPM Capacitor 6 plugins such as the toast and local-notifications Capacitor plugins on iOS only. As far as I understand they don't need to be registered. Is anyone else having this issue?

rricamar commented 2 weeks ago

I'm facing the same issue for NPM Capacitor 6 plugins such as the toast and local-notifications Capacitor plugins on iOS only. As far as I understand they don't need to be registered. Is anyone else having this issue?

Hello @xbisa, after updating to Capacitor 6 the local-notifications plugin worked as expected with no additional modifications 🤔 maybe you need to open a new issue for this 👍

xbisa commented 2 weeks ago

Hi @rricamar Thank you for taking time to test it. I'm trying out XCode on macOS in the cloud. I notice that npx cap sync updates my Podfile.lock. This was not happening on my Windows dev environment. If it still fails, I will consider opening a new issue.

xbisa commented 2 weeks ago

@rricamar I opened a new issue

faguilera85 commented 2 weeks ago

I'm facing the same issue with "@capacitor-community/admob": "^6.0.0". When I call await AdMob.initialize(); I get {"code":"UNIMPLEMENTED"} in the Xcode logs using the simulator on iPhone 15 Pro (iOS 17.4). I really need help to understand how to proceed please, I've been blocked for more than a week already.

FernetB commented 4 days ago

Hi!

I did everything that the docs says, but im getting this error @jcesarmobile

"Could not cast value of type 'UIViewController' (0x1358d2330) to 'Capacitor.CAPBridgeViewController'"

Someone had the same problem?

MyViewController.swift

//  App
//
//

import UIKit
import Capacitor

class MyViewController: CAPBridgeViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override open func capacitorDidLoad() {
        bridge?.registerPluginInstance(Webauthn())
        bridge?.registerPluginInstance(FacebookEvents())
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

main.storyboard

...
<viewController id="BYZ-38-t0r" customClass="MyViewController" customModule="Capacitor" 
 customModuleProvider="target" sceneMemberID="viewController"/>
...

PD: I fixed the problem, had to change the customModule=Capacitor to customModule=App