Guang Zhao
Posts: 0
Joined: Tue Jul 18, 2017 6:43 am

how to use onesignal plugin push notificacions

Hi, Mr. Rohan. can you run onesignal on android? if yes, please tell me how to apply it.
Thanks.

Guang Zhao
Posts: 0
Joined: Tue Jul 18, 2017 6:43 am

how to use onesignal plugin push notificacions

Hi, everyone.
Here is my way.

  1. import Resources/Cordova Plugins/OneSignal Push Notifications
  2. Create new app
  3. in app settings, i do enable onesignal and pushplugin.
  4. in page/index/init function, i added following code.
    alert("start");
    window.plugins.OneSignal.startInit("app_id").endInit();
    alert("end");
  5. export apk file.
  6. run it.
  7. "start" alert is shown. but "end" alert isn't shown. So i think there is error in onesignal.
    Please help me. Thanks.
Z. Rohan
Posts: 0
Joined: Mon Jun 19, 2017 2:13 am

how to use onesignal plugin push notificacions

Hi Guang, I could not get it to work yet. It's the same thing. It never returns from window.plugins.OneSignal.startInit. It seems plugin is not being loaded and I'm not sure why. I'm continuing to try to see why. If you find any solution, let me know.

Guang Zhao
Posts: 0
Joined: Tue Jul 18, 2017 6:43 am

how to use onesignal plugin push notificacions

Hi, Mr. Rohan. I don't figure out the way so far. So I will use firebase sdk instead of OneSignal.
Do you know about it?
If yes, please help me.
Regards.

Jeffry Reed
Posts: 0
Joined: Sun Aug 14, 2016 3:59 pm

how to use onesignal plugin push notificacions

Hello Guang,

Maybe be not so quick to give up? The reason I say so is be because Z has stated that it works. I would reply and state that I have successfully implemented Firebase, However, there is no saying that you will not have issues with Firebase likewise. Possibly you may post discussion in greater details rather than simply stating it don't work? Doing so would help others as well as yourself understand the issues.

best regards

Guang Zhao
Posts: 0
Joined: Tue Jul 18, 2017 6:43 am

how to use onesignal plugin push notificacions

Hi, Jeffry. Thank you for your reply.
I think I have already explained my way how to import OneSignal plugin in appery project.
Could you explain to me how to import firebase plugin in appery projet?
Regards.

Jeffry Reed
Posts: 0
Joined: Sun Aug 14, 2016 3:59 pm

how to use onesignal plugin push notificacions

Hi Guang,

While I don't have extensive experience with firebase, I do have a working prototype using the web SDK in jqm app. Here is an example to create account and login. In this scenario the following code works. Look at the code and screenshot of the UI and it should be clear. I think that's all there is to it.

Image

code// Initialize Firebase
var config = {
apiKey: "your api key",
authDomain: "your-auth-domain.firebaseapp.com",
databaseURL: "https://xyz.firebaseio.com",
projectId: "xyz",
storageBucket: "",
messagingSenderId: "123"
};

firebase.database.enableLogging(true, true);

var defaultApp = firebase.initializeApp(config);

console.log(defaultApp.name); // "[DEFAULT]"

// You can retrieve services via the defaultApp variable...
var defaultStorage = defaultApp.storage();
var defaultDatabase = defaultApp.database();

console.log(defaultStorage); // "[DEFAULT]"

console.log(defaultDatabase); // "[DEFAULT]"

firebase.database().goOffline();
firebase.database().goOnline();

//var email = "me@gmail.com&quot
//var password = "pass123&quot

//createUser(email, password);

function createUser(email, password) {

Code: Select all

 firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) { 
     // Handle Errors here. 
     var errorCode = error.code; 
     var errorMessage = error.message; 
     if (errorCode == 'auth/weak-password') { 
         alert('The password is too weak.'); 
     } else { 
         alert(errorMessage); 
     } 
     console.log(error); 

 }); 

}

/**

  • Handles the sign in button press.
    */
    function toggleSignIn() {
    if (firebase.auth().currentUser) {
    // [START signout]
    firebase.auth().signOut();
    // [END signout]
    } else {
    var email = document.getElementById('pLogin_email').value;
    var password = document.getElementById('pLogin_password').value;
    if (email&#46;length < 4) {
    alert('Please enter an email address&#46;');
    return;
    }
    if (password&#46;length < 4) {
    alert('Please enter a password&#46;');
    return;
    }
    &#47;&#47; Sign in with email and pass&#46;
    &#47;&#47; [START authwithemail]
    firebase&#46;auth()&#46;signInWithEmailAndPassword(email, password)&#46;catch(function(error) {
    &#47;&#47; Handle Errors here&#46;
    var errorCode = error&#46;code;
    var errorMessage = error&#46;message;
    &#47;&#47; [START_EXCLUDE]
    if (errorCode === 'auth/wrong-password') {
    alert('Wrong password&#46;');
    } else {
    alert(errorMessage);
    }
    console&#46;log(error);
    document&#46;getElementById('pLogin_sign_in')&#46;disabled = false;
    &#47;&#47; [END_EXCLUDE]
    });
    &#47;&#47; [END authwithemail]
    }
    document&#46;getElementById('pLogin_sign_in')&#46;disabled = true;
    }

    /**

  • Handles the sign up button press&#46;
    */
    function handleSignUp() {
    var email = document&#46;getElementById('pLogin_email')&#46;value;
    var password = document&#46;getElementById('pLogin_password')&#46;value;
    if (email&#46;length < 4) {
    alert('Please enter an email address&#46;');
    return;
    }
    if (password&#46;length < 4) {
    alert('Please enter a password&#46;');
    return;
    }
    &#47;&#47; Sign in with email and pass&#46;
    &#47;&#47; [START createwithemail]
    firebase&#46;auth()&#46;createUserWithEmailAndPassword(email, password)&#46;catch(function(error) {
    &#47;&#47; Handle Errors here&#46;
    var errorCode = error&#46;code;
    var errorMessage = error&#46;message;
    &#47;&#47; [START_EXCLUDE]
    if (errorCode == 'auth/weak-password') {
    alert('The password is too weak&#46;');
    } else {
    alert(errorMessage);
    }
    console&#46;log(error);
    &#47;&#47; [END_EXCLUDE]
    });
    &#47;&#47; [END createwithemail]
    }

    /**

  • Sends an email verification to the user&#46;
    */
    function sendEmailVerification() {
    &#47;&#47; [START sendemailverification]
    firebase&#46;auth()&#46;currentUser&#46;sendEmailVerification()&#46;then(function() {
    &#47;&#47; Email Verification sent!
    &#47;&#47; [START_EXCLUDE]
    alert('Email Verification Sent!');
    &#47;&#47; [END_EXCLUDE]
    });
    &#47;&#47; [END sendemailverification]
    }

    function sendPasswordReset() {
    var email = document&#46;getElementById('pLogin_email')&#46;value;
    &#47;&#47; [START sendpasswordemail]
    firebase&#46;auth()&#46;sendPasswordResetEmail(email)&#46;then(function() {
    &#47;&#47; Password Reset Email Sent!
    &#47;&#47; [START_EXCLUDE]
    alert('Password Reset Email Sent!');
    &#47;&#47; [END_EXCLUDE]
    })&#46;catch(function(error) {
    &#47;&#47; Handle Errors here&#46;
    var errorCode = error&#46;code;
    var errorMessage = error&#46;message;
    &#47;&#47; [START_EXCLUDE]
    if (errorCode == 'auth/invalid-email') {
    alert(errorMessage);
    } else if (errorCode == 'auth/user-not-found') {
    alert(errorMessage);
    }
    console&#46;log(error);
    &#47;&#47; [END_EXCLUDE]
    });
    &#47;&#47; [END sendpasswordemail];
    }

    /**

  • initApp handles setting up UI event listeners and registering Firebase auth listeners:

  • - firebase&#46;auth()&#46;onAuthStateChanged: This listener is called when the user is signed in or

  • out, and that is where we update the UI&#46;
    */
    function initApp() {
    &#47;&#47; Listening for auth state changes&#46;
    &#47;&#47; [START authstatelistener]
    firebase&#46;auth()&#46;onAuthStateChanged(function(user) {
    &#47;&#47; [START_EXCLUDE silent]
    document&#46;getElementById('pLogin_verify_email')&#46;disabled = true;
    &#47;&#47; [END_EXCLUDE]
    if (user) {
    &#47;&#47; User is signed in&#46;
    var displayName = user&#46;displayName;
    var email = user&#46;email;
    var emailVerified = user&#46;emailVerified;
    var photoURL = user&#46;photoURL;
    var isAnonymous = user&#46;isAnonymous;
    var uid = user&#46;uid;
    var providerData = user&#46;providerData;
    &#47;&#47; [START_EXCLUDE]
    document&#46;getElementById('pLogin_sign_in_status')&#46;textContent = 'Signed in';
    document&#46;getElementById('pLogin_sign_in')&#46;textContent = 'Sign out';
    document&#46;getElementById('pLogin_account_details')&#46;textContent = JSON&#46;stringify(user, null, ' ');
    if (!emailVerified) {
    document&#46;getElementById('verify_email')&#46;disabled = false;
    }
    &#47;&#47; [END_EXCLUDE]
    } else {
    &#47;&#47; User is signed out&#46;
    &#47;&#47; [START_EXCLUDE]
    document&#46;getElementById('pLogin_sign_in_status')&#46;textContent = 'Signed out';
    document&#46;getElementById('pLogin_sign_in')&#46;textContent = 'Sign in';
    document&#46;getElementById('pLogin_account_details')&#46;textContent = 'null';
    &#47;&#47; [END_EXCLUDE]
    }
    &#47;&#47; [START_EXCLUDE silent]
    document&#46;getElementById('sign_in')&#46;disabled = false;
    &#47;&#47; [END_EXCLUDE]
    });
    &#47;&#47; [END authstatelistener]

    document&#46;getElementById('pLogin_sign_in')&#46;addEventListener('click', toggleSignIn, false);
    document&#46;getElementById('pLogin_sign_up')&#46;addEventListener('click', handleSignUp, false);
    document&#46;getElementById('pLogin_verify_email')&#46;addEventListener('click', sendEmailVerification, false);
    document&#46;getElementById('pLogin_password_reset')&#46;addEventListener('click', sendPasswordReset, false);
    }

    &#47;&#47; window&#46;onload = function() { initApp();};/code

    However, there are probably many ways to do it. of the top of my head you could probably use the android or ios sdk respectively, although this is probably not the best for hybrid cordova app.

    you may want to check out the following plugin

    https://github.com/arnesson/cordova-p...
    https://github.com/fechanique/cordova...
    https://github.com/hbmartin/cordova-p...
    http://plugins.telerik.com/cordova/pl...

    note that I have yet to get any of the telerik cordova plugins to work in appery, not sure why.

    hope this helps and good luck

Z. Rohan
Posts: 0
Joined: Mon Jun 19, 2017 2:13 am

how to use onesignal plugin push notificacions

Hi Guang,

Still haven't gotten OneSignal working yet. I am still trying and emailed OneSignal to see if they can look into why it's not working. They think the way Appery is bundling the plugin when exporting is not letting it get loaded. Indeed, when I run a test app I see that OneSignal is never loaded properly. I didn't have a lot of time to work on it, but I am going to keep on trying.

Z. Rohan
Posts: 0
Joined: Mon Jun 19, 2017 2:13 am

how to use onesignal plugin push notificacions

Hi Jeffrey,

Thanks for your sample code. I also got Firebase real-time db working in an Ionic app. That part is not too hard. But I think what Guang is asking (and also my interest in OneSignal) is for the push notifications (i.e. Firebase Cloud messaging).

Did you ever try FCM in your app? If so, let us know what you did.

Guang, I never tried FCM yet, but I would get my client to switch from OneSignal if I could get it to work. Let me know if you make progress with either one. Thanks.

Guang Zhao
Posts: 0
Joined: Tue Jul 18, 2017 6:43 am

how to use onesignal plugin push notificacions

Hi, Mr. Rohan.
I saw config.xml file.
BTW, there is no onesignal plugin. I think it's very important.
for example if i enable firebase plugin, there is.
Make sense?
And how about you?
Please answer me.
Thank you for your time.
Regards.

Return to “Issues”