EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 444 forks source link

applicationDidFinishLaunchingWithOptions is not a function #1318

Open ryanlangton opened 5 years ago

ryanlangton commented 5 years ago

Upgraded to v9.0.1 with NS 5.4.2 and getting the following error

JavaScript error:
file:///app/vendor.js:96014:97: JS ERROR TypeError: FBSDKApplicationDelegate.sharedInstance.applicationDidFinishLaunchingWithOptions is not a function. (In 'FBSDKApplicationDelegate.sharedInstance.applicationDidFinishLaunchingWithOptions(application, launchOptions)', 'FBSDKApplicationDelegate.sharedInstance.applicationDidFinishLaunchingWithOptions' is undefined)
NativeScript caught signal 11.

Here is the code in vendor.js

firebase_common_1.firebase.addAppDelegateMethods = function (appDelegate) {
    if (typeof (FIRMessaging) !== "undefined" || useExternalPushProvider || typeof (FBSDKApplicationDelegate) !== "undefined") {
        appDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) {
            if (launchOptions) {
                var remoteNotification = launchOptions.objectForKey(UIApplicationLaunchOptionsRemoteNotificationKey);
                if (remoteNotification) {
                    firebaseMessaging.handleRemoteNotification(application, remoteNotification);
                }
            }
            if (typeof (FBSDKApplicationDelegate) !== "undefined") {
                FBSDKApplicationDelegate.sharedInstance.applicationDidFinishLaunchingWithOptions(application, launchOptions);
            }
            return true;
        };
    }
ryanlangton commented 5 years ago

I updated my firebase.nativescript.json file to match a new application with the nativescript-plugin-firebase added fresh (some of the properties names not match)

{
    "external_push_client_only": false,
    "using_ios": true,
    "using_android": true,
    "firestore": true,
    "realtimedb": false,
    "authentication": true,
    "remote_config": false,
    "performance_monitoring": false,
    "messaging": false,
    "in_app_messaging": false,
    "crashlytics": false,
    "crash_reporting": false,
    "storage": true,
    "facebook_auth": true,
    "google_auth": true,
    "admob": false,
    "dynamic_links": false,
    "ml_kit": false
}

Now it's still crashing but doesn't give me an error.. the stack trace seems to indicate it's somewhere around the same place in code (when it calls didFinishLaunchingWithOptions)

NativeScript debugger attached.
CONSOLE INFO file:///app/vendor.js:91964:36: HMR: Hot Module Replacement Enabled. Waiting for signal.
CONSOLE LOG file:///app/bundle.js:383:20: auth service set up current user stream
NativeScript caught signal 11.
Native Stack:
1   0x1055151df sig_handler(int)
2   0x10c13db5d _sigtramp
3   0x600000840e00
4   0x10c083b4d libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_x86_64>::step()
5   0x10c087e4c _Unwind_RaiseException
6   0x10bc614aa __cxa_throw
7   0x10a682bfa _objc_exception_destructor(void*)
8   0x10b825555 +[NSException raise:format:]
9   0x1030bc462 +[FIRApp configure]
10  0x105e3151d ffi_call_unix64
11  0x12ec41790
JS Stack:
1   configure@[native code]
2   @file:///app/vendor.js:96240:37
3   ZoneAwarePromise@file:///app/vendor.js:90905:37
4   init@file:///app/vendor.js:96215:23
5   FirebaseModule@file:///app/bundle.js:766:31
6   _createClass@file:///app/vendor.js:53986:28
7   _createProviderInstance@file:///app/vendor.js:53956:38
8   initNgModule@file:///app/vendor.js:53889:55
9   NgModuleRef_@file:///app/vendor.js:54616:21
10  createNgModuleRef@file:///app/vendor.js:54605:28
11  @file:///app/vendor.js:60322:49
12  onInvoke@file:///app/vendor.js:59830:39
13  run@file:///app/vendor.js:90141:49
14  run@file:///app/vendor.js:90141:49
15  @file:///app/vendor.js:90886:37
16  runTask@file:///app/vendor.js:90191:57
17  drainMicroTaskQueue@file:///app/vendor.js:90598:42
18  @file:///app/vendor.js:86653:44
19  notify@file:///app/vendor.js:116736:31
20  @[native code]
21  notifyAppStarted@file:///app/vendor.js:113712:36
22  didFinishLaunchingWithOptions@file:///app/vendor.js:113704:30
23  @[native code]
24  onReceive@file:///app/v<…>

Line 113704 is the line: this.notifyAppStarted(notification);

    IOSApplication.prototype.didFinishLaunchingWithOptions = function (notification) {
        if (!displayedOnce) {
            displayedLinkTarget = CADisplayLinkTarget.new();
            displayedLink = CADisplayLink.displayLinkWithTargetSelector(displayedLinkTarget, "onDisplayed");
            displayedLink.addToRunLoopForMode(NSRunLoop.mainRunLoop, NSDefaultRunLoopMode);
            displayedLink.addToRunLoopForMode(NSRunLoop.mainRunLoop, UITrackingRunLoopMode);
        }
        this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds);
        this._window.backgroundColor = UIColor.whiteColor;
        this.notifyAppStarted(notification);
    };
adonus19 commented 5 years ago

Has there been any progress on this issue? I am seeing a similar problem.

EddyVerbruggen commented 5 years ago

I'd be happy to take a look if anyone shared a minimal repo with me that reproduces the issue.

adonus19 commented 5 years ago

I'll try and get a small demo up and link here.

adonus19 commented 5 years ago

Here is a link that reproduces the issue: https://github.com/adonus19/ns-firebase-demo.git

This is a basic NativeScript project created using "tns create" with tabs.

adonus19 commented 5 years ago

I don't know why I didn't think of this sooner. But, I tried connecting without any configuration passed to firebase.init() and I was able to connect. Seems there may be an issue with the configuration I am passing in.

adonus19 commented 5 years ago

After doing some more research, I see that firebase is already configured and does not need to have configuration properties passed to it like how it would be done in a web based project. Simply running firebase.init().then(() => {}) resolves the issue.

EddyVerbruggen commented 5 years ago

@adonus19 I'd be happy to try your repo, but it won't run because the import '../../firebase-config' is missing. Can you share it with me?

adonus19 commented 5 years ago

@EddyVerbruggen the firebase-config file was all the specifics to my firebase account, i.e. apiKey and so on.

pichurichko commented 5 years ago

Had the same issue, moving const firebase = require("nativescript-plugin-firebase"); from Angular example inside ngOnInit right before firebase.init({... solved it.

tcha-tcho commented 4 years ago

Having the same issue here! :(

jensstigaard commented 4 years ago

I am also experiencing the same issue here on the iOS emulator :( "tns-ios": { "version": "6.2.0" }

Has anyone found a solution to this?