Comments (8)
If by any means someone comes here, I solved my problem by doing the following:
I added in src-cordova/package.json the following:
"cordova": {
"plugins": {
"onesignal-cordova-plugin": {}
},
},
"devDependencies": {
"onesignal-cordova-plugin": "^2.11.3"
}
After that, i made a onesignal.js file inside the boot folder and I also added it in quasar.conf.js in boot section.
In that file I used the next lines of code:
export default async ({app, router, store, Vue}) => {
document.addEventListener('deviceready', async () => {
if (window.plugins.OneSignal) {
//START ONESIGNAL CODE
//Remove this method to stop OneSignal Debugging
// window.plugins.OneSignal.setLogLevel({logLevel: 6, visualLevel: 0});
const notificationOpenedCallback = (jsonData) => {
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
};
// Set your iOS Settings
// const iosSettings = {};
// iosSettings["kOSSettingsKeyAutoPrompt"] = false;
// iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;
window.plugins.OneSignal
.startInit('YOUR ONESIGAL ID')
.handleNotificationOpened(notificationOpenedCallback)
// .iOSSettings(iosSettings)
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
.endInit();
// The promptForPushNotificationsWithUserResponse function will show the iOS push notification prompt.
// We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 6)
// window.plugins.OneSignal.promptForPushNotificationsWithUserResponse(function (accepted) {
// console.log("User accepted notifications: " + accepted);
// });
//END ONESIGNAL CODE
}
});
}
from quasar-app-extension-onesignal.
Hey @NickHatBoecker
I also try to figure out how to connect OneSignal to Quasar.
Did you have any luck with the implementation of this extension or you tried a different path?
from quasar-app-extension-onesignal.
Hey @aimon7
I indeed got it working with Quasar and OneSignal, but it was a hell of a ride.
First I followed the official OneSignal tutorial for iOS/Android. After that I extended the files for Quasar.
I wrote about the extended iOS implementation on my blog, but it's in German. Maybe you can figure it out with the code examples (and I hope I'm allowed to post this here): https://blog.nick-hat-boecker.de/onesignal-push-notifications-quasar/
The only problem I could not fix is, that the OneSignalSecret is committed to the git repository in AppDelegate.swift
following the official OneSignal tutorial for iOS. It would be nice if AppDelegate
could load any configuration file, but I don't know how :(
If you have any questions, feel free to write me.
Best regards
Nick
from quasar-app-extension-onesignal.
Thx for the quick answer @NickHatBoecker .
Will check your blog (although I don't speak German (google translate ftw!!!)).
Would you say that Android (with cordova in quasar) will require the same steps as Capacitor?
Wish you the best,
Ioannis
from quasar-app-extension-onesignal.
@aimon7 Nice that the cordova plugin worked for you. I used capacitor, so the plugin didn't work for me.
For android I created a Plugin OneSignalPlugin.java
with the following code:
package com.mynamespace.myproject;
import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.onesignal.OneSignal;
import android.util.Log;
@NativePlugin
public class OneSignalPlugin extends Plugin {
private static final String ONESIGNAL_APP_ID = "YOUR_ONE_SIGNAL_ID";
public static String ONESIGNAL_USER_ID = "";
public static boolean ONESIGNAL_ENABLED = false;
public void load() {
// Enable verbose OneSignal logging to debug issues if needed.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
// OneSignal Initialization
OneSignal.initWithContext(getContext());
OneSignal.setAppId(ONESIGNAL_APP_ID);
if (OneSignal.getDeviceState().isSubscribed()) {
ONESIGNAL_USER_ID = OneSignal.getDeviceState().getUserId();
ONESIGNAL_ENABLED = OneSignal.getDeviceState().isSubscribed();
Log.d("ONESIGNAL_USER_ID", ONESIGNAL_USER_ID);
}
}
@PluginMethod
public void getStatus(PluginCall call) {
JSObject ret = new JSObject();
ret.put("notificationsEnabled", ONESIGNAL_ENABLED);
ret.put("oneSignalId", ONESIGNAL_USER_ID);
call.success(ret);
}
}
And in MainActivity.java
I referenced it like this:
package com.mynamespace.myproject;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import com.mynamespace.myproject.OneSignalPlugin;
import java.util.ArrayList;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(OneSignalPlugin.class);
}});
}
}
In any Vue component you can then access
const { OneSignalPlugin } = window.Capacitor.Plugins
const { notificationsEnabled, oneSignalId } = await OneSignalPlugin.getStatus()
Hope this helps anyone as well
from quasar-app-extension-onesignal.
Thanks @aimon7!! Your solution also works with Capacitor 🥇
from quasar-app-extension-onesignal.
@NickHatBoecker where did you save these files?
Have you solution for iOS/web?
from quasar-app-extension-onesignal.
Hi!
To use OneSignal into capacitor, this is the package.json into src-capacitor
{
"name": "APP",
"version": "0.0.1",
"description": "App",
"author": "Dev",
"private": true,
"dependencies": {
"@capacitor/android": "2.4.7",
"@capacitor/cli": "^2.0.0",
"@capacitor/core": "^2.0.0"
},
"devDependencies": {
"onesignal-cordova-plugin": "^2.11.3"
},
"cordova": {
"plugins": {
"onesignal-cordova-plugin": {}
}
}
}
Then, into src-capacitor, we must to execute yarn add onesignal-cordova-plugin
And then quasar build
:)
from quasar-app-extension-onesignal.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quasar-app-extension-onesignal.