mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.17k stars 1.05k forks source link

🔧 V3.x FrameProcessorPlugin : Can't find the -swift.h file #1998

Closed IvanByRool closed 10 months ago

IvanByRool commented 10 months ago

How were you trying to build the app?

Hey,

I'm using XCode to build my IOS app with RN Xcode : 14.3 RN : 0.72.5 Vison Camera : 3.3.1

I had to re-write my own FrameProcessor after migration from 2.15 to 3.3.1 But I don't understand how to solve my last problems

What I have

  1. An OCRFrameProcessor.switft file
import MLKit

@objc(OCRFrameProcessorPlugin)
public class OCRFrameProcessorPlugin: FrameProcessorPlugin {

  @objc public static func callback(_ frame: Frame!, withArgs _: [Any]!) -> Any! {

...

  }
}
  1. An OCRFrameProcessor.m file
#import <Foundation/Foundation.h>

#import "OCRFrameProcessor.h"
#if defined __has_include && __has_include("OCRFrameProcessor-Swift.h")
#import "OCRFrameProcessor-Swift.h"
#else
#import <OCRFrameProcessor/OCRFrameProcessor-Swift.h>
#endif

@implementation RegisterPlugins

    + (void) load {
        [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"OCR"
                                              withInitializer:^FrameProcessorPlugin*(NSDictionary* options) {
            return [[OCRFrameProcessor alloc] init];
        }];
    }

@end

This is where my problems are

#import <VisionCamera/FrameProcessorPlugin.h>
#import <VisionCamera/FrameProcessorPluginRegistry.h>

@interface RegisterPlugins : FrameProcessorPlugin

@end

I'm quite new with this, so any help would be appreciated, I wanted to update to 3.x for my project in order to use new cool features.

Thanks

Full build logs

Showing All Messages
/src/ios/OCRFrameProcessor/OCRFrameProcessor.m:7:9: 'OCRFrameProcessor/OCRFrameProcessor-Swift.h' file not found

Project dependencies

{
    "react": "18.2.0",
    "react-native": "0.72.5",
    "react-native-reanimated": "^3.5.4",
    "react-native-vision-camera": "^3.3.1",
    "react-native-worklets-core": "^0.2.2"
}

VisionCamera Version

3.3.1

Target platforms

iOS

Operating system

MacOS

Can you build the VisionCamera Example app?

No, I cannot build the Example app either

Additional information

mrousavy commented 10 months ago

Hey - well the -Swift file should be <YourProjectName>-Swift.h, for VisionCamera it's VisionCamera-Swift.h. For the example app it'd be VisionCameraExample-Swift.h.

But you can also register it manually, it doesn't need to be in a +load method - it can also be in the app's AppDelegate :)

IvanByRool commented 10 months ago

Thanks for your answer @mrousavy, but I'm clearly out of my confort zone with this ;)

I added a CaRoolTruck-Swift.h file, under OCRFrameProcessor folder. Probably a lot I don't understand, but what is it for ? No sure what to put inside :/

And I don't understand what you meant by AppDelegate.

I don't want you to waste your time teaching my how it works, so do you have a "working" code I can go through in order to learn by myself ? Once again, thanks for everything, Ivan

IvanByRool commented 10 months ago

To give you more context, I wrote my FrameProcessor module for OCR reading on an older version with

OCRFrameProcessor.m

#import <VisionCamera/FrameProcessorPlugin.h>

@interface VISION_EXPORT_SWIFT_FRAME_PROCESSOR(OCR, OCRFrameProcessorPlugin)
@end

And OCRFrameProcessor.swift

import MLKit

@objc(OCRFrameProcessorPlugin)
public class OCRFrameProcessorPlugin: NSObject, FrameProcessorPluginBase {

  @objc public static func callback(_ frame: Frame!, withArgs _: [Any]!) -> Any! {
...

}

I noticed changes since 3.x, this is where I'm struggling.

thx

mrousavy commented 10 months ago

AppDelegate is in your example app or your library user's app. +load could be an option but not sure hwo that'd work, I dont have an example. example app here just registers the plugin in AppDElegate

dolakzdenek commented 10 months ago

@IvanByRool Check if the name of your project is correct (you'll find it in root dir of plugin in podspec file as s.name). If it is really OCRFrameProcessor, not something like ocr-frame-processor, then you should import that as

#import <ocr_frame_processor-Swift.h>

@mrousavy I noticed that XCode15 has issues with +load +initialize doesn't work for Swift plugin (Plugin is not found), I used code from the Example plugin I guess AppDelegate will probably work for now but Iam looking for better solution

IvanByRool commented 10 months ago

Thanks @dolakzdenek,

I fixed it, you were both right here. The -Swift.h file wasn't properly named.

I know end up with the issue " Frame Processor threw an error: Failed to load Frame Processor Plugin!" when using the plugin. I'm using +initialize like in the example, so based on your last com, I'm assuming something else should help me solve it ?

Thanks a lot, ivan

mrousavy commented 10 months ago

Cool, so the original issue is solved then.

Frame Processor threw an error: Failed to load Frame Processor Plugin!

Check your native logs. Does it say "Registering Frame Processor Plugin ...." in there? If not, it is not registering it.

IvanByRool commented 10 months ago

Hey,

no it"s not, I have the following

2023-10-16 16:41:27.871404+0200 CaRoolTruck-Val[80831:13683086] [javascript] Loading react-native-worklets-core...
2023-10-16 16:41:27.872749+0200 CaRoolTruck-Val[80831:13683086] [javascript] Worklets loaded successfully
2023-10-16 16:41:27.875624+0200 CaRoolTruck-Val[80831:13683086] VisionCameraProxy: Creating Worklet Context...
2023-10-16 16:41:27.876233+0200 CaRoolTruck-Val[80831:13683086] VisionCameraProxy: Worklet Context Created!
2023-10-16 16:41:28.028830+0200 CaRoolTruck-Val[80831:13682780] [native] VisionCamera.didSetProps(_:): Updating 11 prop(s)...
2023-10-16 16:41:28.029231+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.configureCaptureSession(): Configuring Session...
2023-10-16 16:41:28.029239+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.configureCaptureSession(): Initializing Camera with device com.apple.avfoundation.avcapturedevice.built-in_video:0...
2023-10-16 16:41:28.029245+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.configureCaptureSession(): Adding Video input...
2023-10-16 16:41:28.035549+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.configureCaptureSession(): Adding Video Data output...
2023-10-16 16:41:28.039073+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.invokeOnInitialized(): Camera initialized!
2023-10-16 16:41:28.039124+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.configureCaptureSession(): Session successfully configured!
2023-10-16 16:41:28.039861+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.configureFormat(): Configuring Format...
2023-10-16 16:41:28.039866+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.configureDevice(): Configuring Device...
2023-10-16 16:41:28.040101+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.configureDevice(): Device successfully configured!
2023-10-16 16:41:28.040239+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.didSetProps(_:): Starting Session...
2023-10-16 16:41:28.228937+0200 CaRoolTruck-Val[80831:13683079] [native] VisionCamera.didSetProps(_:): Started Session!
2023-10-16 16:41:28.235759+0200 CaRoolTruck-Val[80831:13683086] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 16:41:28.649403+0200 CaRoolTruck-Val[80831:13683086] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!

Any idea ? thx

mrousavy commented 10 months ago

Way further up in your logs. This gets logged when the app starts.

IvanByRool commented 10 months ago

Didn't want to pollute,

here is the full log

2023-10-16 17:29:26.104806+0200 CaRoolTruck-Val[81207:13698882] <SKPaymentQueue: 0x28243d150>: No observers found that respond to "paymentQueue:shouldAddStorePayment:forProduct:", will not check for purchase intents
flipper: FlipperClient::addPlugin Inspector
flipper: FlipperClient::addPlugin Preferences
flipper: FlipperClient::addPlugin React
2023-10-16 17:29:26.160091+0200 CaRoolTruck-Val[81207:13699176] 10.7.0 - [FirebaseMessaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2023-10-16 17:29:26.171311+0200 CaRoolTruck-Val[81207:13699182] 10.7.0 - [FirebaseAnalytics][I-ACS023007] Analytics v.10.7.0 started
2023-10-16 17:29:26.172525+0200 CaRoolTruck-Val[81207:13699182] 10.7.0 - [FirebaseAnalytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r)
2023-10-16 17:29:26.219359+0200 CaRoolTruck-Val[81207:13699176] 10.7.0 - [FirebaseAnalytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
flipper: FlipperClient::addPlugin Network
2023-10-16 17:29:26.805724+0200 CaRoolTruck-Val[81207:13698882] [native] Running application caroolTruck ({
    initialProps =     {
    };
    rootTag = 1;
})
2023-10-16 17:29:26.978768+0200 CaRoolTruck-Val[81207:13699173] 10.7.0 - [FirebaseAnalytics][I-ACS023012] Analytics collection enabled
2023-10-16 17:29:26.978889+0200 CaRoolTruck-Val[81207:13699173] 10.7.0 - [FirebaseAnalytics][I-ACS023220] Analytics screen reporting is enabled. Call Analytics.logEvent(AnalyticsEventScreenView, parameters: [...]) to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
2023-10-16 17:29:27.067717+0200 CaRoolTruck-Val[81207:13698882] BleManager created
2023-10-16 17:29:27.266901+0200 CaRoolTruck-Val[81207:13699200] 10.7.0 - [FirebaseMessaging][I-FCM012002] Error in application:didFailToRegisterForRemoteNotificationsWithError: aucune autorisation « aps-environment » valide détectée pour l’application
2023-10-16 17:29:27.695062+0200 CaRoolTruck-Val[81207:13699173] SocketStream read error [0x281735e00]: 1 54
2023-10-16 17:29:30.612306+0200 CaRoolTruck-Val[81207:13699201] [connection] nw_socket_handle_socket_event [C7:1] Socket SO_ERROR [61: Connection refused]
2023-10-16 17:29:30.612444+0200 CaRoolTruck-Val[81207:13699173] [connection] nw_connection_get_connected_socket_block_invoke [C7] Client called nw_connection_get_connected_socket on unconnected nw_connection
2023-10-16 17:29:30.612582+0200 CaRoolTruck-Val[81207:13699173] TCP Conn 0x2817ba620 Failed : error 0:61 [61]
2023-10-16 17:29:30.612857+0200 CaRoolTruck-Val[81207:13699173] [connection] nw_connection_copy_connected_local_endpoint_block_invoke [C7] Client called nw_connection_copy_connected_local_endpoint on unconnected nw_connection
2023-10-16 17:29:30.612929+0200 CaRoolTruck-Val[81207:13699173] [connection] nw_connection_copy_connected_remote_endpoint_block_invoke [C7] Client called nw_connection_copy_connected_remote_endpoint on unconnected nw_connection
2023-10-16 17:29:30.717881+0200 CaRoolTruck-Val[81207:13699165] SocketStream read error [0x2817315e0]: 1 54
2023-10-16 17:29:30.720048+0200 CaRoolTruck-Val[81207:13698882] -[RNFBMessagingModule signalBackgroundMessageHandlerSet] [Line 104] signalBackgroundMessageHandlerSet called
2023-10-16 17:29:30.720069+0200 CaRoolTruck-Val[81207:13698882] -[RNFBMessagingAppDelegate signalBackgroundMessageHandlerSet] [Line 74] signalBackgroundMessageHandlerSet sharedInstance.backgroundMessageHandlerSet was NO
2023-10-16 17:29:30.721272+0200 CaRoolTruck-Val[81207:13699193] [javascript] Running "caroolTruck" with {"rootTag":1,"initialProps":{}}
2023-10-16 17:29:31.056663+0200 CaRoolTruck-Val[81207:13698882] [native] [GESTURE HANDLER] Initialize gesture handler for root view <RCTRootContentView: 0x10a310800; frame = (0 0; 390 844); gestureRecognizers = <NSArray: 0x2828b31b0>; layer = <CALayer: 0x28212eb40>> reactTag: 1; frame = {{0, 0}, {390, 844}}; layer = <CALayer: 0x28212eb40>
2023-10-16 17:29:33.792398+0200 CaRoolTruck-Val[81207:13699165] SocketStream read error [0x281731220]: 1 54
2023-10-16 17:29:35.256407+0200 CaRoolTruck-Val[81207:13698882] Bridge call to: deviceContexts
2023-10-16 17:29:36.859111+0200 CaRoolTruck-Val[81207:13699164] SocketStream read error [0x281011220]: 1 54
2023-10-16 17:29:39.925711+0200 CaRoolTruck-Val[81207:13699173] SocketStream read error [0x281011220]: 1 54
2023-10-16 17:29:42.988206+0200 CaRoolTruck-Val[81207:13699201] SocketStream read error [0x28172ee40]: 1 54
2023-10-16 17:29:46.058595+0200 CaRoolTruck-Val[81207:13699162] SocketStream read error [0x28172ee40]: 1 54
2023-10-16 17:29:49.130195+0200 CaRoolTruck-Val[81207:13699164] SocketStream read error [0x281011220]: 1 54
2023-10-16 17:29:52.205454+0200 CaRoolTruck-Val[81207:13699162] SocketStream read error [0x2817208c0]: 1 54
2023-10-16 17:29:55.272374+0200 CaRoolTruck-Val[81207:13699162] SocketStream read error [0x28172ee40]: 1 54
2023-10-16 17:29:58.339198+0200 CaRoolTruck-Val[81207:13699176] SocketStream read error [0x2817328a0]: 1 54
2023-10-16 17:30:01.408424+0200 CaRoolTruck-Val[81207:13699201] SocketStream read error [0x281011220]: 1 54
2023-10-16 17:30:04.477547+0200 CaRoolTruck-Val[81207:13699173] SocketStream read error [0x281730b40]: 1 54
2023-10-16 17:30:07.547242+0200 CaRoolTruck-Val[81207:13699164] SocketStream read error [0x281011220]: 1 54
2023-10-16 17:30:10.612138+0200 CaRoolTruck-Val[81207:13699162] SocketStream read error [0x28172f520]: 1 54
2023-10-16 17:30:13.682173+0200 CaRoolTruck-Val[81207:13699164] SocketStream read error [0x28172f520]: 1 54
2023-10-16 17:30:16.756879+0200 CaRoolTruck-Val[81207:13699201] SocketStream read error [0x281721040]: 1 54
2023-10-16 17:30:19.828086+0200 CaRoolTruck-Val[81207:13699164] [connection] nw_socket_handle_socket_event [C30.1.1:1] Socket SO_ERROR [54: Connection reset by peer]
2023-10-16 17:30:22.894569+0200 CaRoolTruck-Val[81207:13699201] SocketStream read error [0x2817210e0]: 1 54
2023-10-16 17:30:25.962438+0200 CaRoolTruck-Val[81207:13699164] SocketStream read error [0x2817210e0]: 1 54
2023-10-16 17:30:29.034724+0200 CaRoolTruck-Val[81207:13699173] [connection] nw_socket_handle_socket_event [C33.1.1:1] Socket SO_ERROR [54: Connection reset by peer]
2023-10-16 17:30:31.916050+0200 CaRoolTruck-Val[81207:13699162] [tcp] tcp_input [C12.1.1:3] flags=[R] seq=2973794834, ack=0, win=0 state=LAST_ACK rcv_nxt=2973794834, snd_una=2809553655
2023-10-16 17:30:31.919432+0200 CaRoolTruck-Val[81207:13699162] [tcp] tcp_input [C12.1.1:3] flags=[R] seq=2973794834, ack=0, win=0 state=CLOSED rcv_nxt=2973794834, snd_una=2809553655
2023-10-16 17:30:31.919670+0200 CaRoolTruck-Val[81207:13699162] [tcp] tcp_input [C12.1.1:3] flags=[R] seq=2973794834, ack=0, win=0 state=CLOSED rcv_nxt=2973794834, snd_una=2809553655
2023-10-16 17:30:32.112425+0200 CaRoolTruck-Val[81207:13699547] SocketStream read error [0x2810128a0]: 1 54
2023-10-16 17:30:34.248254+0200 CaRoolTruck-Val[81207:13699173] [tcp] tcp_input [C13.1.1:3] flags=[R] seq=264969755, ack=0, win=0 state=LAST_ACK rcv_nxt=264969755, snd_una=1963674880
2023-10-16 17:30:34.248836+0200 CaRoolTruck-Val[81207:13699173] [tcp] tcp_input [C13.1.1:3] flags=[R] seq=264969755, ack=0, win=0 state=CLOSED rcv_nxt=264969755, snd_una=1963674880
2023-10-16 17:30:34.249000+0200 CaRoolTruck-Val[81207:13699173] [tcp] tcp_input [C13.1.1:3] flags=[R] seq=264969755, ack=0, win=0 state=CLOSED rcv_nxt=264969755, snd_una=1963674880
2023-10-16 17:30:35.179715+0200 CaRoolTruck-Val[81207:13699162] SocketStream read error [0x2810128a0]: 1 54
2023-10-16 17:30:38.251610+0200 CaRoolTruck-Val[81207:13699162] SocketStream read error [0x281731f40]: 1 54
2023-10-16 17:30:41.325380+0200 CaRoolTruck-Val[81207:13699173] SocketStream read error [0x281731f40]: 1 54
2023-10-16 17:30:44.396604+0200 CaRoolTruck-Val[81207:13699547] SocketStream read error [0x281731f40]: 1 54
2023-10-16 17:30:47.467659+0200 CaRoolTruck-Val[81207:13699164] SocketStream read error [0x2817210e0]: 1 54
2023-10-16 17:30:50.542192+0200 CaRoolTruck-Val[81207:13699162] SocketStream read error [0x28172d400]: 1 54
2023-10-16 17:30:53.615353+0200 CaRoolTruck-Val[81207:13699173] SocketStream read error [0x281721220]: 1 54
2023-10-16 17:30:55.565808+0200 CaRoolTruck-Val[81207:13699193] [javascript] Loading react-native-worklets-core...
2023-10-16 17:30:55.567157+0200 CaRoolTruck-Val[81207:13699193] [javascript] Worklets loaded successfully
2023-10-16 17:30:55.569811+0200 CaRoolTruck-Val[81207:13699193] VisionCameraProxy: Creating Worklet Context...
2023-10-16 17:30:55.570356+0200 CaRoolTruck-Val[81207:13699193] VisionCameraProxy: Worklet Context Created!
2023-10-16 17:30:55.700870+0200 CaRoolTruck-Val[81207:13698882] [native] VisionCamera.didSetProps(_:): Updating 12 prop(s)...
2023-10-16 17:30:55.701135+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.configureCaptureSession(): Configuring Session...
2023-10-16 17:30:55.701161+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.configureCaptureSession(): Initializing Camera with device com.apple.avfoundation.avcapturedevice.built-in_video:0...
2023-10-16 17:30:55.701195+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.configureCaptureSession(): Adding Video input...
2023-10-16 17:30:55.707348+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.configureCaptureSession(): Adding Video Data output...
2023-10-16 17:30:55.708571+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.invokeOnInitialized(): Camera initialized!
2023-10-16 17:30:55.708701+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.configureCaptureSession(): Session successfully configured!
2023-10-16 17:30:55.709693+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.configureFormat(): Configuring Format...
2023-10-16 17:30:55.709712+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.configureDevice(): Configuring Device...
2023-10-16 17:30:55.710266+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.configureDevice(): Device successfully configured!
2023-10-16 17:30:55.710469+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.didSetProps(_:): Starting Session...
2023-10-16 17:30:55.900407+0200 CaRoolTruck-Val[81207:13699164] [native] VisionCamera.didSetProps(_:): Started Session!
2023-10-16 17:30:55.908503+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:56.320851+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:56.520082+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:56.634737+0200 CaRoolTruck-Val[81207:13699201] SocketStream read error [0x28107fc00]: 1 54
2023-10-16 17:30:56.718479+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:56.922883+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:57.118240+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:57.315545+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:57.521898+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:57.720323+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:57.924308+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:58.113834+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
2023-10-16 17:30:58.312842+0200 CaRoolTruck-Val[81207:13699193] [javascript] Frame Processor threw an error: Failed to load Frame Processor Plugin!
mrousavy commented 10 months ago

Ah shit my bad, I don't have logs in there. Try adding a log line in FrameProcessorPluginRegistry.m to see if the addFrameProcessorPlugins func is actually being called.

I created a PR that will do that here: https://github.com/mrousavy/react-native-vision-camera/pull/2012

mrousavy commented 10 months ago

Let me know if those logs get called for you.

IvanByRool commented 10 months ago

Thanks,

no they're not called.

If it helps, this is the code I have for my FrameProcessor (from the builder)

#if __has_include(<VisionCamera/FrameProcessorPlugin.h>)
#import <Foundation/Foundation.h>
#import <VisionCamera/FrameProcessorPlugin.h>
#import <VisionCamera/FrameProcessorPluginRegistry.h>
#import <VisionCamera/Frame.h>

#import "caroolTruck-Swift.h"

@interface XyzFrameProcessorPlugin (FrameProcessorPluginLoader)
@end

@implementation XyzFrameProcessorPlugin (FrameProcessorPluginLoader)

+ (void)initialize
{
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"xyz"
                                        withInitializer:^FrameProcessorPlugin*(NSDictionary* options) {
    return [[XyzFrameProcessorPlugin alloc] initWithOptions:options];
  }];
}

@end

#endif

And,

#if VISION_CAMERA_ENABLE_FRAME_PROCESSORS
import VisionCamera

@objc(XyzFrameProcessorPlugin)
public class XyzFrameProcessorPlugin: FrameProcessorPlugin {
  @objc public init(withOptions options: [AnyHashable : Any]) {
    super.init()
  }

  @objc override public func callback(_ frame: Frame, withArguments arguments: [AnyHashable : Any]?) -> Any {
    let buffer = frame.buffer
    let orientation = frame.orientation
    // code goes here
    return "yeah"
  }
}
#endif
mrousavy commented 10 months ago

Well if they're not getting called then they're just not registered.

Can you try to use +load instead of +initialize? That will definitely be called

IvanByRool commented 10 months ago

It's not logged with +load either.

Don't know if that helps but added logs on frameProcessorPlugins above function and getting plugins = {}

+ (NSMutableDictionary<NSString*, PluginInitializerFunction>*)frameProcessorPlugins {
  static NSMutableDictionary<NSString*, PluginInitializerFunction>* plugins = nil;
  if (plugins == nil) {
    plugins = [[NSMutableDictionary alloc] init];
  }
  return plugins; --> this is {}
}
ShchipskiiYura commented 10 months ago

Hi, I have some problem with build plugin.

When I build app, I catch error like that:

Знімок екрана 2023-10-17 о 12 50 20

my VisionCameraFaceDetector.m file

#import <Foundation/Foundation.h>
#import <VisionCamera/FrameProcessorPlugin.h>
#import <VisionCamera/FrameProcessorPluginRegistry.h>
#import <VisionCamera/Frame.h>

#import "vision_camera_face_detector-Swift.h"

@interface VisionCameraFaceDetector (FrameProcessorPluginLoader)
@end

@implementation VisionCameraFaceDetector (FrameProcessorPluginLoader)

+ (void)load
{
  [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"scanFaces"
                                        withInitializer:^FrameProcessorPlugin*(NSDictionary* options) {
    return [[VisionCameraFaceDetector alloc] initWithOptions:options];
  }];
}

@end

Can you help me, please. Where there might be an error? Thanks a lot

mrousavy commented 10 months ago

@IvanByRool is your +load method even called? Put a breakpoint in your plugin's +load method.

IvanByRool commented 10 months ago

No it's not.

I followed this doc : https://react-native-vision-camera.com/docs/guides/frame-processors-plugins-ios Anything you think may be missing there ?

I have .m & .swift files for the frame processor I have the plugin called in my JS I have [react-native-worklets-core] babel.config.js looks like this

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ['react-native-reanimated/plugin'],
    ['react-native-worklets-core/plugin'],
  ],
};
mrousavy commented 10 months ago

This has something to do with native iOS development.

I don't know why the +load method is not called, maybe your .m file is not properly included in your app's xcode project?

You can also add the plugin in your AppDelegate's start method - that'll always be called.

IvanByRool commented 10 months ago

Thanks @mrousavy I'll try. Had to pause this for the moment.

Thanks a lot for your help

IvanByRool commented 9 months ago

Hey,

just to let you know, it's now working fine with latest version

thx