I'm developing an app with Unity that uses Digital Ink Recognition of ML Kit to recognize handwriting.
To fetch ios plugin via unity, I use this script:
public static void Initialize(string languageTag = "en-US")
{
if (_instance != null)
{
return;
}
Debug.Log("Initializing...");
GameObject owner = new GameObject("HandwriteRecognitionIOSPluguin");
_instance = owner.AddComponent<HandwriteRecognitionIOSPluguin>();
_InitializeNew(languageTag);
}
from the above function will be directed to the objective-c script with the following script:
static DigitalInkRecognition* recognition = nil;
extern "C" void _InitializeNew(const char* languageTag)
{
if (recognition == nil)
recognition = [[DigitalInkRecognition alloc] init];
[recognition downloadModel];
}
the following is the script in the objective-c file
#import <GoogleMLKit/MLKit.h>
@interface DigitalInkRecognition : NSObject
@property(nonatomic) MLKDigitalInkRecognitionModel *model;
@property(nonatomic) MLKModelManager *modelManager;
@property(nonatomic) MLKDigitalInkRecognitionModelIdentifier *identifier;
@property(weak, nullable, nonatomic) id delegate;
@end
@implementation DigitalInkRecognition : NSObject
- (id)init
{
self = [super init];
_modelManager = [MLKModelManager modelManager];
_delegate = self;
__weak __typeof(self) weakSelf = self;
[NSNotificationCenter.defaultCenter
addObserverForName:MLKModelDownloadDidSucceedNotification
object:nil
queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification *notification) {
__typeof(self) strongSelf = weakSelf;
if (strongSelf == nil) {
NSLog(@"self == nil handling download success notification");
return;
}
if ([notification.userInfo[MLKModelDownloadUserInfoKeyRemoteModel]
isEqual:strongSelf.model]) {
[strongSelf.delegate displayMessage:@"Model download succeeded"];
}
}];
[NSNotificationCenter.defaultCenter
addObserverForName:MLKModelDownloadDidFailNotification
object:nil
queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification *notification) {
__typeof(self) strongSelf = weakSelf;
if (strongSelf == nil) {
NSLog(@"self == nil handling download fail notification");
return;
}
if ([notification.userInfo[MLKModelDownloadUserInfoKeyRemoteModel]
isEqual:strongSelf.model]) {
[strongSelf.delegate displayMessage:@"Model download failed"];
}
}];
NSString *language = [[NSLocale preferredLanguages] firstObject];
self.identifier =
[MLKDigitalInkRecognitionModelIdentifier modelIdentifierFromLanguageTag:language error:nil];
[self displayMessage:language];
if (self.identifier == nil) {
self.identifier = [MLKDigitalInkRecognitionModelIdentifier modelIdentifierFromLanguageTag:@"en" error:nil];
}
return self;
}
- (IBAction)downloadModel {
if ([self.modelManager isModelDownloaded:self.model]) {
[self.delegate displayMessage:@"Model is already downloaded"];
return;
}
[self.delegate displayMessage:@"Starting download"];
self.model = [[MLKDigitalInkRecognitionModel alloc] initWithModelIdentifier:self.identifier];
self.modelManager = [MLKModelManager modelManager];
//ERROR HERE
[self.modelManager downloadModel:self.model
conditions:[[MLKModelDownloadConditions alloc]
initWithAllowsCellularAccess:YES
allowsBackgroundDownloading:YES]];
}
- (void)displayMessage:(NSString *)message {
NSLog(@"LOG MESSAGE :: %@", message);
}
@end
When entering the 'downloadModel' function, the script will error with the following message:
2022-01-24 13:11:33.828766+0700 appdev[734:210369] +[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10
2022-01-24 13:11:33.868910+0700 appdev[734:210369] Uncaught exception: NSInvalidArgumentException: +[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10
(
0 CoreFoundation 0x00000001804c6d50 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 597328
1 libobjc.A.dylib 0x000000019782b6a8 objc_exception_throw + 56
2 CoreFoundation 0x00000001805966b0 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 1447600
3 CoreFoundation 0x0000000180460f6c 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 180076
4 CoreFoundation 0x00000001804601dc _CF_forwarding_prep_0 + 92
5 UnityFramework 0x00000001081933ac -[MLKDigitalInkRecognitionLogger logEvent:withName:] + 92
6 UnityFramework 0x00000001081949bc -[MLKDigitalInkLogEvent log] + 424
7 UnityFramework 0x000000010819752c -[MLKDigitalInkRecognitionModelManager downloadModel:conditions:] + 328
8 UnityFramework 0x0000000108132e28 -[MLKModelManager downloadModel:conditions:] + 224
9 UnityFramework 0x0000000108124964 -[DigitalInkRecognition downloadModel] + 588
10 UnityFramework 0x000000010945a8a4 HandwriteRecognitionIOSPluguin_Initialize_mC4FA5B192BDF0E20E606D3DC32DFB3A71C363767 + 288
11 UnityFramework 0x000000010945b7cc IOSHandwritingManager_U3CStartU3Eb__17_0_m0444198A2E9188E1DC9F9A84E34AC1E1C22A03C5 + 180
12 UnityFramework 0x0000000109556bc4 UnityAction_Invoke_mC9FF5AA1F82FDE635B3B6644CE71C94C31C3E71A + 276
13 UnityFramework 0x000000010955d9cc UnityEvent_Invoke_mB2FA1C76256FE34D5E7F84ABE528AC61CE8A0325 + 348
14 UnityFramework 0x000000010952b6d8 EventFunction_1_Invoke_m7899B7663B08CD474B8FADD9D85FF446CD839FE6_gshared + 504
15 UnityFramework 0x00000001094661f0 ExecuteEvents_Execute_TisRuntimeObject_mDA4CD02F963B6939F8D079993DC2DCD75AB524DD_gshared + 308
16 UnityFramework 0x0000000109595a7c StandaloneInputModule_ProcessTouchPress_m74A52DA64B9C5EB8B5A38889F25BFEAFC284FB51 + 1216
17 UnityFramework 0x0000000109595060 StandaloneInputModule_ProcessTouchEvents_mFEED66642E804A218DD34A9C5F0F8EAA5CA3B019 + 248
18 UnityFramework 0x0000000109594d9c StandaloneInputModule_Process_mBF40EA3762B85C417E6F88D531174D05A7FFCE75 + 72
19 UnityFramework 0x00000001080f50ac _Z65RuntimeInvoker_TrueVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017PFvvEPK10MethodInfoPvPS4_ + 20
20 UnityFramework 0x0000000109440e5c _ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException + 116
21 UnityFramework 0x00000001090fa620 _Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb + 116
22 UnityFramework 0x0000000109105268 _ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb + 116
23 UnityFramework 0x0000000109110954 _ZN13MonoBehaviour16CallUpdateMethodEi + 300
24 UnityFramework 0x0000000108f96668 _ZN20BaseBehaviourManager12CommonUpdateI16BehaviourManagerEEvv + 224
25 UnityFramework 0x000000010905e588 _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 88
26 UnityFramework 0x000000010905e5bc _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 140
27 UnityFramework 0x000000010905e824 _Z10PlayerLoopv + 356
28 UnityFramework 0x0000000109255784 _ZL19UnityPlayerLoopImplb + 224
29 UnityFramework 0x00000001080be714 UnityRepaint + 140
30 UnityFramework 0x00000001080be5f0 -[UnityAppController(Rendering) repaintDisplayLink] + 88
31 QuartzCore 0x0000000183f5cd1c 36E47EF8-38B9-36C6-95B4-7AF8527D7E9D + 64796
32 QuartzCore 0x0000000183f634e8 36E47EF8-38B9-36C6-95B4-7AF8527D7E9D + 91368
33 CoreFoundation 0x000000018043f69c 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 42652
34 CoreFoundation 0x000000018047f4ec 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 304364
35 CoreFoundation 0x0000000180482adc 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 318172
36 CoreFoundation 0x00000001804400f0 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 45296
37 CoreFoundation 0x0000000180452e1c CFRunLoopRunSpecific + 572
38 GraphicsServices 0x00000001a07e19a0 GSEventRunModal + 160
39 UIKitCore 0x0000000182c86600 D8869DEE-E238-3284-8C9A-623313659320 + 5162496
40 UIKitCore 0x0000000182a1bb08 UIApplicationMain + 2028
41 UnityFramework 0x00000001080bd0f0 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 108
42 appdev 0x00000001001e7e84 main + 68
43 dyld 0x0000000101e34250 start + 444
)
2022-01-24 13:11:33.870345+0700 appdev[734:210369] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10'
*** First throw call stack:
(0x1804c6d3c 0x19782b6a8 0x1805966b0 0x180460f6c 0x1804601dc 0x1081933ac 0x1081949bc 0x10819752c 0x108132e28 0x108124964 0x10945a8a4 0x10945b7cc 0x109556bc4 0x10955d9cc 0x10952b6d8 0x1094661f0 0x109595a7c 0x109595060 0x109594d9c 0x1080f50ac 0x109440e5c 0x1090fa620 0x109105268 0x109110954 0x108f96668 0x10905e588 0x10905e5bc 0x10905e824 0x109255784 0x1080be714 0x1080be5f0 0x183f5cd1c 0x183f634e8 0x18043f69c 0x18047f4ec 0x180482adc 0x1804400f0 0x180452e1c 0x1a07e19a0 0x182c86600 0x182a1bb08 0x1080bd0f0 0x1001e7e84 0x101e34250)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10'
(lldb)
on error, script goes to file 'main.mm' line 26 ([ufw runUIApplicationMainWithArgc: argc argv: argv];). The following is the contents of the 'main.mm' file:
#include <UnityFramework/UnityFramework.h>
UnityFramework* UnityFrameworkLoad()
{
NSString* bundlePath = nil;
bundlePath = [[NSBundle mainBundle] bundlePath];
bundlePath = [bundlePath stringByAppendingString: @"/Frameworks/UnityFramework.framework"];
NSBundle* bundle = [NSBundle bundleWithPath: bundlePath];
if ([bundle isLoaded] == false) [bundle load];
UnityFramework* ufw = [bundle.principalClass getInstance];
if (![ufw appController])
{
// unity is not initialized
[ufw setExecuteHeader: &_mh_execute_header];
}
return ufw;
}
int main(int argc, char* argv[])
{
@autoreleasepool
{
id ufw = UnityFrameworkLoad();
[ufw runUIApplicationMainWithArgc: argc argv: argv];
return 0;
}
}
What can I do to solve the problem I'm having?
Thanks in advance for any idea.