NativeScript / nativescript-facebook

NativeScript plugin, wrapper of native Facebook SDK for Android and iOS
Apache License 2.0
79 stars 50 forks source link

"Error: attempt to insert nil object from objects[0]" when trying to use 'logEvent' #226

Closed ZDiyanov closed 4 years ago

ZDiyanov commented 4 years ago
 "dependencies": {
    "nativescript-facebook": "../src",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-vue": "~2.4.0",
    "tns-core-modules": "^6.0.0"

    "nativescript-facebook": "^4.2.1",
    "nativescript-plugin-firebase": "^10.5.2",
    "nativescript-vue": "~2.5.0",
    "tns-core-modules": "~6.5.0",
  },
  "devDependencies": {
    "@babel/core": "~7.1.0",
    "@babel/preset-env": "~7.1.0",
    "babel-loader": "~8.0.0",
    "nativescript-dev-appium": "^6.1.3",
    "nativescript-dev-webpack": "~1.5.1",
    "nativescript-vue-devtools": "^1.4.0",
    "nativescript-vue-template-compiler": "~2.5.0",
    "node-sass": "^4.7.1",
    "vue-loader": "~15.9.0"
}

I'm following the demo for Vue in the respective repo directory. I'm trying to use the 'logEvent' from a Vue.js mixin method in the 'created' lifecicle hook of a view. The issue is present on both iOS and Android, the CLI returns the following when running for iOS:

***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1   0x10476960e NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
2   0x1047aa548 NativeScript::FFICallback<NativeScript::ObjCMethodCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
3   0x1051ab222 ffi_closure_unix64_inner
4   0x1051abc4a ffi_closure_unix64
5   0x7fff23d67245 _CFXRegistrationPost1
6   0x7fff23d66fb1 ___CFXNotificationPost_block_invoke
7   0x7fff23e64513 -[_CFXNotificationRegistrar find:object:observer:enumerator:]
8   0x7fff23d66906 _CFXNotificationPost
9   0x7fff2591a26b -[NSNotificationCenter postNotificationName:object:userInfo:]
10  0x7fff48c8419e -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:]
11  0x7fff48c89bf9 -[UIApplication _runWithMainScene:transitionContext:completion:]
12  0x7fff4839225d -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:]
13  0x7fff4889dcc1 _UIScenePerformActionsWithLifecycleActionMask
14  0x7fff48392d6f __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke
15  0x7fff4839277e -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:]
16  0x7fff48392b9c -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]
17  0x7fff48392431 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:]
18  0x7fff48396a22 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke_2
19  0x7fff487b3dad +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:]
20  0x7fff488bc41e _UISceneSettingsDiffActionPerformChangesWithTransitionContext
21  0x7fff4839673d __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke
22  0x7fff488bc321 _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext
23  0x7fff483965ab -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]
24  0x7fff481eafa8 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke
25  0x7fff481e9b67 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:]
26  0x7fff481eacd2 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:]
27  0x7fff48c88141 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:]
28  0x7fff487da8dc -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:]
29  0x7fff36cacd2e -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:]
30  0x7fff36cd2dc1 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154
31  0x7fff36cb7757 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]
JavaScript stack trace:
initWithObjectsForKeys(file: node_modules/nativescript-facebook/app-events.ios.js:19:52)
at NSDictionary([native code])
at logEvent(file: node_modules/nativescript-facebook/app-events.ios.js:19:52)
at logFacebookEvent(file: app/mixins/facebook.js:7:15)
at logFacebookEvent([native code])
at trackPage(file: app/views/Home.vue:25:0)
at trackPage([native code])
at created(file: app/views/Home.vue:17:0)
at invokeWithErrorHandling(file: node_modules/nativescript-vue/dist/index.js:3368:61)
at callHook(file: node_modules/nativescript-vue/dist/index.js:6608:30)
at insert(file: node_modules/nativescript-vue/dist/index.js:5536:15)
at invokeInsertHook(file: node_modules/nativescript-vue/dist/index.js:7191:34)
at patch(file: node_modules/nativescript-vue/dist/index.js:7410:21)
at file: node_modules/nativescript-vue/dist/index.js:6334:28
at updateComponent(file: node_modules/nativescript-vue/dist/index.js:6455:17)
at get(file: node_modules/nativescript-vue/dist/index.js:3842:29)
at Watcher(file: node_modules/nativescript-vue/dist/index.js:3831:6)
at mountComponent(file: node_modules/nativescript-vue/dist/index.js:6462:14)
at file: node_modules/nativescript-vue/dist/index.js:14065:4
at file: node_modules/@nativescript/core/data/observable/observable.js:110:31
at [native code]
at file: node_modules/@nativescript/core/application/application.ios.js:171:36
at file: node_modules/@nativescript/core/application/application.ios.js:163:30
at [native code]
at file: node_modules/@nativescript/core/application/application.ios.js:36:32
at UIApplicationMain(<…>
JavaScript error:
file: node_modules/nativescript-facebook/app-events.ios.js:19:52: JS ERROR Error: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
(CoreFoundation) *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Error: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
at
initWithObjectsForKeys(file: node_modules/nativescript-facebook/app-events.ios.js:19:52)
at NSDictionary([native code])
at logEvent(file: node_modules/nativescript-facebook/app-events.ios.js:19:52)
at logFacebookEvent(file: app/mixins/facebook.js:7:15)
at logFacebookEvent([native code])
at trackPage(file: app/views/Home.vue:25:0)
at trackPage([native code])
at created(file: app/views/Home.vue:17:0)
at invokeWithErrorHandling(file: node_modules/nativescript-vue/dist/index.js:3368:61)
at callHook(file: node_modules/nativescript-vue/dist/index.js:6608:30)
at insert(file: node_modules/nativescript-vue/dist/index.js:5536:15)
at invokeInsertHook(file: node_modules/nativescript-vue/dist/index.js:7191:34)
at patch(file: node_modules/nativescript-vue/dist/index.js:7410:21)
at file: node_modules/nativescript-vue/dist/index.js:6334:28
at updateComponent(file: node_modules/nativescript-vue/dist/index.js:6455:17)
at get(file: node_modules/nativescript-vue/dist/index.js:3842:29)
at Watcher(file: node_modules/nativescript-vue/dist/index.js:3831:6)
at mountComponent(file: node_modules/nativescript-vue/dist/index.js:6462:14)
at file://<…>

and on tns run android:

JS: HMR: Hot Module Replacement Enabled. Waiting for signal.
JS: [Vue warn]: Error in created hook: "TypeError: Cannot read property 'logEvent' of undefined"
JS: 
JS: found in
JS: 
JS: ---> <Home> at views/Home.vue
JS:        <Frame>
JS:          <App> at components/App.vue
JS:            <Root>
System.err: An uncaught Exception occurred on "main" thread.
System.err: Unable to start activity ComponentInfo{{app_id}/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: TypeError: Cannot read property 'logEvent' of undefined
System.err: 
System.err: StackTrace:
System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{{app_id}/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: TypeError: Cannot read property 'logEvent' of undefined
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
System.err:     at android.os.Looper.loop(Looper.java:193)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6669)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
System.err: Caused by: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: TypeError: Cannot read property 'logEvent' of undefined
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err:     at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:19)
System.err:     at android.app.Activity.performCreate(Activity.java:7136)
System.err:     at android.app.Activity.performCreate(Activity.java:7127)
System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
System.err:     ... 11 more
ZDiyanov commented 4 years ago

Update: Using setInterval and checking if the logEvent method is not undefined seems to fix the issue on Android, the issue persists on iOS.

ZDiyanov commented 4 years ago

Update: The issue was solved, I was using an improper format for the parameters. There's a check for Android that prevents the issue by not including the parameters if there's no parameter value:

if (param.value !== undefined) {
     bundle.putString(param.key, param.value);
}

I don't think this check is there for iOS, so the build fails.