A Nativescript plugin that wraps the iOS and Android OneSignal Push Notifications SDK.
- iOS
- Android
tns plugin add nativescript-onesignal
Does not need any configuration.
Does not need any configuration.
var TnsOneSignal = require('nativescript-onesignal').TnsOneSignal
TnsOneSignal
is the native iOS OneSignal
class.
In your main.ts
:
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, 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba')
} catch (error) {
console.error('error', error)
}
return true
}
}
application.ios.delegate = MyDelegate
}
TnsOneSignal
is the native Android com.onesignal.OneSignal
class.
In your main.ts
:
import * as application from 'application';
var TnsOneSignal = require('nativescript-onesignal').TnsOneSignal
if (application.android) {
application.on(application.launchEvent, function(args: application.ApplicationEventData) {
try {
console.dump('TnsOneSignal', TnsOneSignal)
TnsOneSignal.startInit(application.android.context).init()
} catch (error) {
console.error('error', error)
}
})
}
Android - In the works...
npm run setup
# iOS
npm run demo.ios
# Android
npm run demo.android