method is not a recognised objective c method

Pritish

Lot of question are asked regarding the same but none of them solve my error.

Here is my objective c file

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <UIKit/UIKit.h>

@interface RCT_EXTERN_MODULE(LanguageTranslationModule, NSObject)


RCT_EXTERN_METHOD(callbackMethod:(NSString*)englishText (RCTResponseSenderBlock)callback)

@end

Here is my swift class

@objc(LanguageTranslationModule)
class LanguageTranslationModule: NSObject {

  var resultCallback: RCTResponseSenderBlock!

  @objc func callbackMethod(_ englishText: String, callback: @escaping RCTResponseSenderBlock) -> Void {
    resultCallback = callback
    debugPrint("Hi there")
    translateText(msg: englishText)
  }...

Here is my JS call from React Native

LanguageTranslationModule.callbackMethod(englishText, (err, r) => {
        if (!err) {
          setProgress(false);
          setMarathiText(r.text.toString());
        } else {
          setProgress(false);
          setMarathiText(err);
        }
      });

Following is my translate text method

func translateText(msg: String) {

    let options = TranslatorOptions(sourceLanguage: .en, targetLanguage: .mr)
    let englishMarathiTranslator = NaturalLanguage.naturalLanguage().translator(options: options)

    let conditions = ModelDownloadConditions(
      allowsCellularAccess: false,
      allowsBackgroundDownloading: true
    )

    englishMarathiTranslator.downloadModelIfNeeded(with: conditions) {error in
      guard error == nil else { return }
      englishMarathiTranslator.translate(msg) { (translatedText, error) in
        guard error == nil, let translatedText = translatedText else { return }
        let resultsDict = [
          "text" : translatedText
        ];
        self.resultCallback([NSNull() ,resultsDict])
      }
    }
  }

have added underscore to my first parameter in swift file as that is most of the solution to other questions asked on stack as well as there is space between the underscore and actual variable name. If I remove the englishText variable from all the files and hardcode that text in swift file then my function works fine. of course then I had to add underscore to the callback variable, so no logical error from my side

ivanmoskalev

I assume that the error is in the title of the question. It seems that your Swift method's signature doesn't match the signature declared in the Objective C interface.

Try adding an argument label to the second parameter in the declaration.

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <UIKit/UIKit.h>

@interface RCT_EXTERN_MODULE(LanguageTranslationModule, NSObject)


RCT_EXTERN_METHOD(callbackMethod:(NSString*)englishText callback:(RCTResponseSenderBlock)callback)
//                                                      ^^^^^^^^

@end

Explanation:

RCT_EXTERN_METHOD(callbackMethod:(NSString*)englishText callback:(RCTResponseSenderBlock)callback)

matches

@objc func callbackMethod(_ englishText: String, callback: @escaping RCTResponseSenderBlock) -> Void

while your original variant

RCT_EXTERN_METHOD(callbackMethod:(NSString*)englishText (RCTResponseSenderBlock)callback)

would match

@objc func callbackMethod(_ englishText: String, _ callback: @escaping RCTResponseSenderBlock) -> Void

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Swift: Converting this Objective C Method

分類Dev

Objective C/XCode - Image in ImageView not recognised by Xcode

分類Dev

Call a method from AppDelegate - Objective-C

分類Dev

calling objective c method from callback

分類Dev

button in webView execute Objective C method

分類Dev

Creating a method in objective-c with a delay argument

分類Dev

Method with Objective-C selector conflicts - 'with' at the end

分類Dev

How to call Objective-C instancetype method in Swift?

分類Dev

No Method declared with Objective-C Selector for Notification UIKeyboardWillShowNotification and UIKeyboardWillHideNotification

分類Dev

Call Swift class method from Objective-C

分類Dev

AudioKit: How to use AKPlayer playAt method in Objective-C?

分類Dev

Using variables defined in one method inside another in Objective-C

分類Dev

Calling a method from another class - SpriteKit/Objective C

分類Dev

Objective-C: Can not instantiate method of another class

分類Dev

Objective C: Method using NSMutableString returns random characters

分類Dev

Method load() defines Objective-C class method 'load', which is not permitted by Swift 1.2

分類Dev

"Objective-C method conflicts with optional requirement method"error after update to XCode 6.3 (Swift 1.2)

分類Dev

Swift 2.0 Method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C

分類Dev

Xcode 6.3&Swift ERROR:Objective-C method 'init' defined by implicit initializer 'init()' here

分類Dev

Cloning a method in c#

分類Dev

C++ Method Pointer?

分類Dev

C# UnitTest Method Result

分類Dev

c# contains method usage

分類Dev

C# self reference a method

分類Dev

Objective-Cを使用したReactNativeアプリをSwiftに変換する際のRCT_EXTERN_METHODの問題

分類Dev

Passing a pointer class method as an argument to another class method C++

分類Dev

CALL METHOD and method chaining

分類Dev

Java:method()。method()

分類Dev

Method Parameter Without A Parameter Type In C#

Related 関連記事

  1. 1

    Swift: Converting this Objective C Method

  2. 2

    Objective C/XCode - Image in ImageView not recognised by Xcode

  3. 3

    Call a method from AppDelegate - Objective-C

  4. 4

    calling objective c method from callback

  5. 5

    button in webView execute Objective C method

  6. 6

    Creating a method in objective-c with a delay argument

  7. 7

    Method with Objective-C selector conflicts - 'with' at the end

  8. 8

    How to call Objective-C instancetype method in Swift?

  9. 9

    No Method declared with Objective-C Selector for Notification UIKeyboardWillShowNotification and UIKeyboardWillHideNotification

  10. 10

    Call Swift class method from Objective-C

  11. 11

    AudioKit: How to use AKPlayer playAt method in Objective-C?

  12. 12

    Using variables defined in one method inside another in Objective-C

  13. 13

    Calling a method from another class - SpriteKit/Objective C

  14. 14

    Objective-C: Can not instantiate method of another class

  15. 15

    Objective C: Method using NSMutableString returns random characters

  16. 16

    Method load() defines Objective-C class method 'load', which is not permitted by Swift 1.2

  17. 17

    "Objective-C method conflicts with optional requirement method"error after update to XCode 6.3 (Swift 1.2)

  18. 18

    Swift 2.0 Method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C

  19. 19

    Xcode 6.3&Swift ERROR:Objective-C method 'init' defined by implicit initializer 'init()' here

  20. 20

    Cloning a method in c#

  21. 21

    C++ Method Pointer?

  22. 22

    C# UnitTest Method Result

  23. 23

    c# contains method usage

  24. 24

    C# self reference a method

  25. 25

    Objective-Cを使用したReactNativeアプリをSwiftに変換する際のRCT_EXTERN_METHODの問題

  26. 26

    Passing a pointer class method as an argument to another class method C++

  27. 27

    CALL METHOD and method chaining

  28. 28

    Java:method()。method()

  29. 29

    Method Parameter Without A Parameter Type In C#

ホットタグ

アーカイブ