sitefinitysteve / nativescript-google-analytics

Apache License 2.0
23 stars 14 forks source link

Webpack compatibility ios #11

Closed leocaseiro closed 8 years ago

leocaseiro commented 8 years ago

Hi @sitefinitysteve, thank you for this amazing plugin.

I'm having issues with WebPack. It's working fine without bundling it, but if we bundle, the app won't start, and we get the error:

CONSOLE ERROR file:///app/tns_modules/zone.js/dist/zone-node.js:419:27: Unhandled Promise rejection: Value is not a class. ; Zone: <root> ; Task: null ; Value: Error: Value is not a class.

CONSOLE ERROR file:///app/tns_modules/zone.js/dist/zone-node.js:421:23: Error: Uncaught (in promise): Error: Value is not a class. 

I believe it's related to the issue https://github.com/NativeScript/nativescript-dev-webpack/issues/8 which is caused by the __extends().

Do you know an easy fix for that? Thanks

DomGaud commented 8 years ago

Remove the var __extends function :

var __extends = this.__extends || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        __.prototype = b.prototype;
        d.prototype = new __();
    };

and replace the __extends(appDelegate, _super); with this.__extends(appDelegate, _super);

So your code should be as follows:

if (application.ios) {
    //IOS
   var appDelegate = (function (_super) {
        this.__extends(appDelegate, _super);
        function appDelegate() {
            _super.apply(this, arguments);
        }

        appDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) {
            //Module Code to initalize
            googleAnalytics.initalize({
                trackingId: "UA-XXXXXXX-1"
            });
        };

        appDelegate.ObjCProtocols = [UIApplicationDelegate];
        return appDelegate;
    })(UIResponder);
    application.ios.delegate = appDelegate;
}
leocaseiro commented 8 years ago

Wow, that actually works.

Thanks for that!