roblav96 / nativescript-onesignal

A Nativescript plugin that wraps the iOS and Android OneSignal Push Notifications SDK.
https://documentation.onesignal.com/docs/getting-started
Other
24 stars 42 forks source link

[iOS] Terminating app due to uncaught exception 'NativeScript encountered a fatal error: TypeError: Attempted to assign to readonly property. #66

Open ejlocop opened 3 years ago

ejlocop commented 3 years ago

Hello, can anyone help me with this error? I have no idea how do I fix this..

this is the output from the --log trace option.

(CoreFoundation) *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: TypeError: Attempted to assign to readonly property.
at
__(file: node_modules/tslib/tslib.es6.js:26:25)
at __extends(file: node_modules/tslib/tslib.es6.js:27:79)
at file: app/services/notification.ts:6:27
at initializeNotification(file: app/services/notification.ts:6:27)
at file:///app/bundle.js:12286:38
at ./main.ts(file:///app/bundle.js:12306:34)
at __webpack_require__(file: app/webpack/bootstrap:74:0)
at checkDeferredModules(file: app/webpack/bootstrap:43:0)
at webpackJsonpCallback(file: app/webpack/bootstrap:30:0)
at anonymous(file:///app/bundle.js:2:61)
at evaluate([native code])
at moduleEvaluation([native code])
at [native code]
at asyncFunctionResume([native code])
at [native code]
at promiseReactionJob([native code])
', reason: '(null)'
*** First throw call stack:
(
0   CoreFoundation                      0x00007fff20421af6 __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x00007fff20177e78 objc_exception_throw + 48
2   NativeScript    <…>
NativeScript caught signal 6.
Native Stack:
1   0x10b426171 sig_handler(int)
2   0x7fff6115a5fd _sigtramp
3   0x1
4   0x7fff200fab94 abort
5   0x7fff20253818 abort_message
6   0x7fff20244e7d demangling_unexpected_handler()
7   0x7fff201780d1 _objc_terminate()
8   0x7fff20252c47 std::__terminate(void (*)())
9   0x7fff202553d0 __cxa_get_exception_ptr
10  0x7fff20255397 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
11  0x7fff20177f9c _objc_exception_destructor(void*)
12  0x10b3d5b6f NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
13  0x10b427524 -[TNSRuntime executeModule:referredBy:]
14  0x10ab45003 main
15  0x7fff2025a3e9 start
16  0x1
JS Stack:

and here's the contents of the notification.ts file

import * as application from 'tns-core-modules/application'
var TnsOneSignal = require('nativescript-onesignal').TnsOneSignal

export const initializeNotification = () => {
    if (application.ios) {
        class MyDelegate extends UIResponder implements UIApplicationDelegate {

            public static ObjCProtocols = [UIApplicationDelegate]

            public applicationDidFinishLaunchingWithOptions(app: UIApplication, launchOptions: NSDictionary<any, any>): boolean {
                try {
                    console.log('[iOS] TnsOneSignal', TnsOneSignal)
                    TnsOneSignal.initWithLaunchOptionsAppId(launchOptions, NATIVE_ONESIGNAL_APP_ID)
                } catch (error) {
                    console.error('error', error)
                }
                return true
            }
        }
        application.ios.delegate = MyDelegate
    }

    else {
        application.on(application.launchEvent, function (args: application.ApplicationEventData) {
            try {
                console.log('[Android] TnsOneSignal', TnsOneSignal)
                TnsOneSignal.startInit(application.android.context).init()
            }
            catch (error) {
                console.error('error', error)
            }
        })
    }
}