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

Nativescript 2.5 + Angular #7

Open davorpeic opened 7 years ago

davorpeic commented 7 years ago

Hi,

anybody managed to get this working on Nativescript 2.5 + Angular app?

My main.ts looks like this

import { platformNativeScriptDynamic } from "nativescript-angular/platform";

import { AppModule } from "./app.module";

import { Config } from "./shared/config";
import * as application from 'application';
var TnsOneSignal = require('nativescript-onesignal').TnsOneSignal;

if (application.ios) {
    class MyDelegate extends UIResponder implements UIApplicationDelegate {

        public static ObjCProtocols = [UIApplicationDelegate]

        private applicationDidFinishLaunchingWithOptions(app: UIApplication, launchOptions: NSDictionary): boolean {

            try {

                console.dump('TnsOneSignal', TnsOneSignal)
                TnsOneSignal.initWithLaunchOptionsAppId(launchOptions, Config.ONESIGNAL);

            } catch (error) {
                console.error('error', error)
            }

            return true
        }

    }
    application.ios.delegate = MyDelegate
}

platformNativeScriptDynamic().bootstrapModule(AppModule);

And this is what I get when I try to build

bash-3.2$ tns build ios
Executing before-prepare hook from /Users/MyMac/Apps/myapps/mobile-agent/hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 2.1.6
app/main.ts(10,11): error TS2420: Class 'MyDelegate' incorrectly implements interface 'UIApplicationDelegate'.
  Property 'applicationDidFinishLaunchingWithOptions' is private in type 'MyDelegate' but not in type 'UIApplicationDelegate'.

app/main.ts(14,93): error TS2314: Generic type 'NSDictionary<KeyType, ObjectType>' requires 2 type argument(s).

app/main.ts(18,17): error TS2346: Supplied parameters do not match any signature of call target.

node_modules/tns-platform-declarations/ios/objc-i386/objc!CoreAudio.d.ts(7,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'AudioBuffer' must be of type '{ new (): AudioBuffer; prototype: AudioBuffer; }', b
ut here has type 'StructType<AudioBuffer>'.

node_modules/tns-platform-declarations/ios/objc-i386/objc!UIKit.d.ts(4954,15): error TS2300: Duplicate identifier 'UIEvent'.

node_modules/tns-platform-declarations/ios/objc-i386/objc!UIKit.d.ts(4954,15): error TS2417: Class static side 'typeof UIEvent' incorrectly extends base class static side 'typeof NSObject'.
  Types of property 'alloc' are incompatible.
    Type '() => UIEvent' is not assignable to type '() => NSObject'.
      Type 'UIEvent' is not assignable to type 'NSObject'.
        Property 'accessibilityActivationPoint' is missing in type 'UIEvent'.

node_modules/typescript/lib/lib.d.ts(14991,11): error TS2300: Duplicate identifier 'UIEvent'.
node_modules/typescript/lib/lib.d.ts(14997,13): error TS2300: Duplicate identifier 'UIEvent'.

TypeScript compiler failed with exit code 1

I tried to remove/add platform ios and this is without typings defined in references, if I add them then I get lots of android typings errors.

thanks

davorpeic commented 7 years ago

Ok, I managed to get this working, I created few methods with promises that I need in this project, I will create a Gist tomorrow so others can follow this example if they need this implemented in Angular

tushar-1health commented 7 years ago

@davorpeic Any update?

davorpeic commented 7 years ago

Hey, I started but didn't finished, let me see if I can upload gist today, thanks

davorpeic commented 7 years ago

Hey @tushar-1health I put in this gist service that I use to get IDs and to save tags, these are all methods that I use at this moment besides registering device. I'm sure it can be improved.

Please try and let me know how it goes https://gist.github.com/davorpeic/93605ccf42702e7b932c61b6bd6bcc46

roblav96 commented 7 years ago

@davorpeic your example will only work on iOS. please refer to this https://github.com/roblav96/nativescript-onesignal/issues/5#issuecomment-284811981

davorpeic commented 7 years ago

Thanks @roblav96 yeah, I just saw your example, thanks!

tusharvikky commented 7 years ago

@davorpeic @roblav96 Hey, Have you configured receivedCallback / actionCallback? I was unable to redirect when a button is clicked on notification. Hoping you can help here.

davorpeic commented 7 years ago

Hey @tusharvikky I recommend everybody to switch to Firebase Messaging, it's also free and works great with Eddy's https://github.com/EddyVerbruggen/nativescript-plugin-firebase, I had to modify a little bit my NS app code, and my laravel server side was already using curl post, so I almost only replaced url and it kept working the same with firebase fcm. The firebase plugin is maintained and it is working fine, much better than this plugin.