"Extra trailing closure passed in call" error in Capacitor/Camera plugin

Hi,

I am in the process of migrating my app to use capacitor 3 from capacitor 2 and while the npx cap sync ios command works fine, when I try to compile the App to a target device i get the error “Extra trailing closure passed in call” in the Camera plugin as shown in the screenshot below.

The error is in the function below on the line PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: viewController) { _ in

    @objc func pickLimitedLibraryPhotos(_ call: CAPPluginCall) {
        if #available(iOS 14, *) {
            PHPhotoLibrary.requestAuthorization(for: .readWrite) { (granted) in
                if granted == .limited {
                    if let viewController = self.bridge?.viewController {
                        if #available(iOS 15, *) {
                            PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: viewController) { _ in
                                self.getLimitedLibraryPhotos(call)
                            }
                        } else {
                            PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: viewController)
                            call.resolve([
                                "photos": []
                            ])
                        }
                    }
                } else {
                    call.resolve([
                        "photos": []
                    ])
                }
            }
        } else {
            call.unavailable("Not available on iOS 13")
        }
    }

My setup so far as output from ionic info is as below

Ionic:

   Ionic CLI                     : 6.20.4 (/Users/stibrewal/.nvm/versions/node/v14.15.4/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.1
   @angular-devkit/build-angular : 12.2.18
   @angular-devkit/schematics    : 11.2.5
   @angular/cli                  : 12.2.18
   @ionic/angular-toolkit        : 3.1.1

Capacitor:

   Capacitor CLI      : 3.9.0
   @capacitor/android : 3.9.0
   @capacitor/core    : 3.9.0
   @capacitor/ios     : 3.9.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : 6.0.0, android 9.1.0, browser
   Cordova Plugins   : cordova-plugin-ionic-webview 4.2.1, (and 2 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : 1.7.1

System:

   Android SDK Tools : 26.1.1 (/Users/stibrewal/Library/Android/sdk)
   NodeJS            : v14.15.4 (/Users/stibrewal/.nvm/versions/node/v14.15.4/bin/node)
   npm               : 6.14.10
   OS                : macOS Big Sur
   Xcode             : Xcode 12.5 Build version 12E262

I have tried removing and adding the @capacitor/camera plugin back but still get the same error.

Look forward to any help on how to fix this issue.

Thanks,
Sanjay.

If you are updating to Capacitor 3 and not 4, you have to use version 1.x of @capacitor/camera plugin.
Version 4.x of @capacitor/camera plugin will only work with Capacitor 4 and also requires Xcode 13, while you are using Xcode 12.
Capacitor 3 and @capacitor/camera plugin 1.x should both work on Xcode 12.

Thank you @julio-ionic - lowering the @capacitor/camera plugin to 1.x as you suggested helped get past the error. Appreciate your help.

For my own edification, can you please help me understand how would I figure this out myself that version 4.x of @capacitor/camera plugin will not work with capacitor 3 and Xcode 12? Want to be able to resolve these things myself if I can.

Well, it’s mentioned here

These plugins are for Capacitor 4 :rotating_light:

Capacitor 2 core plugins are bundled with Capacitor itself.
For Capacitor 3, use the 1.x version of the plugins.

Also the plugin itself specify that it needs @capacitor/core 4.x

if you are using npm 7 or newer it should prevent version 4 of the plugins from installing if you have a smaller @capacitor/core version. Or at least complain and show some error or warning.

Then the Capacitor docs mention that Capacitor 4 requires Xcode 13 or newer

Same page but for version 3 mentions Xcode 12+

Thanks you @julio-ionic. My npm version happens to be 6.14.10 so I didn’t see any errors or warnings unless I missed those - I will update npm. And clearly I missed that in other documentation. Thank you for pointing those out.