Onesignal Webpush Notification : This site has been updated in the background - reactjs

I have some concerns & questions about web push notifications using onesignal, because sometimes the notification show "this site has been updated in the background".
First what caused the notif shown like that, is that from settings device phone or from my code?
Second how to fix the message content like that?
i implement like this in head.js
if (navigator.serviceWorker) {
navigator.serviceWorker.register(`https://test.com/OneSignalSDKWorker.js?appId=test123`).then(function (registration) {
console.log(registration);
});
}
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js"></script>
is i call double sdk caused that?

Related

cn1PostMessage is undefined on Android. PostMessage is not working

I created a webview (BrowserComponent) and added a listener:
BComp.addWebEventListener(BrowserComponent.onMessage, e->{
Display.getInstance().callSerially(()->{
Dialog.show("Message", (String)e.getSource(), "OK", null);
});
});
Then, in the JavaScript of the embedded website, I called cn1PostMessage and postMesage. This works well in the simulator! But when building the application, on Android, it does nothing (cn1PostMessage is undefined and postMessage is not received by the main program).
var msg = "test";
if(window.cn1PostMessage) {
window.cn1PostMessage(msg);
} else {
window.parent.postMessage(msg, '*');
// Tried: window.postMessage(msg, '*');
// Tried: window.top.postMessage(msg, '*');
}
What can I do?
Thanks!
I just tried building the BrowserComponentPostMessageSample, and it seemed to work fine on my Galaxy S8, Android 8.
If you're finding that window.cn1PostMessage is undefined, then either there was a javascript error in page load that prevented that callback from being installed, or your code is running before the CodenameOne initialization code has run.
I have just added support for the "android.webContentsDebuggingEnabled" display property, which will make the app's web views debuggable using Chrome's remote development tools. This will make it easier for your to track down such issues. See usage example:
Display.getInstance().setProperty("android.webContentsDebuggingEnabled", "true");
This will be available in Friday's update (Dec. 6/19).
In the mean time, I recommend starting with the BrowserComponentPostMessageSample and modifying it to suit your needs from there.
Alternatively, if you can post a test case to demonstrate the issue, I can look at it.

react-native-onesignal receive push notification without opening notification

I have checked react-native-onesignal github README and it seems the only way to get the notification is to open which is through the onNotificationOpened() callback.
Their documentation stated that:
When any notification is opened or received the callback onNotification is called passing an object with the notification data.
But onNotification clearly does not work.
Is there any way to get the notification without opening the push notification or enabling the in-app alert notification?
The onNotification function will only be called when opening a notification or when one is received while the app is in focus.
If you need to handle a notification in the background before it is opened you will need to do so with native code.
iOS - set content_available to true on the OneSignal create notification REST API POST call, this will fire the
- application:didReceiveRemoteNotification:fetchCompletionHandler: selector.
Android - Setup a NotificationExtenderService by following the OneSignal Background Data and Notification Overriding instructions.
Regarding implementation of NotificationExtenderService in android (not answering the original question, but the question asked by #ryeballar), as explained in https://documentation.onesignal.com/docs/android-customizations#section-background-data-and-notification-overriding:
I am getting notifications when the app is closed/swiped-out/not-started without implementing NotificationExtenderService
However, in order to implement NotificationExtenderService you need to do the following (as described in the onesignal documentation referenced above, note that there is a typo there, fixed below):
Create a file called NotificationExtender.java in node_modules\react-native-onesignal\android\src\main\java\com\geektime\rnonesignalandroid, with the following contents:
.
import com.onesignal.OSNotificationPayload;
package com.geektime.rnonesignalandroid;
import com.onesignal.OSNotificationPayload;
import com.onesignal.OSNotificationPayload;
import com.onesignal.NotificationExtenderService;
import com.onesignal.OSNotificationReceivedResult;
public class NotificationExtender extends NotificationExtenderService {
#Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
// Read properties from result.
// Return true to stop the notification from displaying.
return false;
}
}
Add the following to android\app\src\main\AndroidManifest.xml:
.
<service android:name=".NotificationExtender"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="com.onesignal.NotificationExtenderService" />
</intent-filter>
</service>
rebuild your app

Refreshing web page in real time in sails.js

In my project I am using sails.js. From test1.ejs I am calling a web service which in turn calls another ejs(test2.ejs) using res.view().
Now android user is inputting some values which affects the database and needs to reflect on the web page in real time. I am not able to figure out how this can be achieved using sails.js.
Also I need to even show the android user response and at the same time refresh the web page. In short I want a dynamic UI like share market where any changes on the server is reflected on the front end.
Will I need to use anything else like angularjs?
You can use JavaScript Interface if I understand your problem right.
You should create the class like this:
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
#JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
After this you should connect this interface to your webview like this:
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
Now you can call Java code from JS like this:
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
Or call JS code from Java like this:
webview.loadUrl("javascript:window.showAndroidToast(\"Hello, World!\")");
More info is available here: https://developer.android.com/guide/webapps/webview.html

addEventListner for received SMS using mozMobileMessage in B2G

I have been teaching myself how to write apps in AngularJS for Firefox OS for a university assignment. This is my first attempt at writing an app in JS.
The aim of the app is to run commands based upon 'commands' sent via SMS (aka, 'ring loud', 'lock device', 'turn on wifi', and reply to an SMS command with GPS locations). At the moment, I'm just trying to do a simple $window.alert('Messaged Received'), to display when an SMS has been received.
My problem is, I am trying to create an addEventListener for incoming SMS, and for the moment, display an $window.alert(). Later, I will use a case switch.
I've referred to the MDN API to create the Event Listener.
var mozMM = navigator.mozMobileMessage;
mozMM.addEventListener('received', function addEventListener(evt) {
// Display a alert when a message is received
$window.alert('SMS received');
$window.alert(evt.message.body);
}, false);
My manifest.webapp has been set up to include all the relevant settings:
"type" : "certified",
"permissions": {
"backgroundservice":{},
"sms":{},
...
},
"messages": [
{ "sms-received": "/index.html" },
{ "notification": "/index.html" }
]
I am able to send SMS from my app without any issues. So I assume I have no problems with my permissions. I've also confirmed that I have full access to the mozMobileMessage object.
For testing, I am using a Geekphone, which has been rooted, and can install certified apps.
I have uploaded the source code to github:
https://github.com/s3069246/findmydevice/tree/master/app
Thanks to someone on Google Groups for giving me the correct solution. I thought I would also share it here.
The issue was that I was using the wrong Event Handler. I should have been using a system message handler instead
navigator.mozSetMessageHandler('sms-received', function onSMS(sms) {
/* here your code */
});
Combined with the "message": [] handler in the manifest, the system handler will alert the application that a message has been received, even if the app is running in the background.

Facebook (web) dialog started immediately dismissing on iOS6/SDK3.1|3.2

I had some code to post to a friend's facebook wall that upon the deprecation of this via Open Graph I changed to use the deprecated headers and Facebook dialog to include the user in the posting. That has been working for weeks, but seems to have stopped working (worked fine Tuesday, failed Wednesday) in production application (i.e. no code change or re-build.)
I've spent hours trying all sort of things (running on main thread, asserting sessions are live, re-writting to SDK 3.2, uninstalling app/re-installing, completely changing the dialog type and post contents) to restore the ability but whatever I do the dialog immediately dismisses. [Note: There are no developer alerts on our app, and I believe that none of the app settings have changed.]
Here is the code. The facebookManager "performConnectedAction" is from the Facebook sample to ensure an active session (and I assert it w/o problem.) :
NSMutableDictionary *wallPost = [NSMutableDictionary dictionary];
// Content populating not show (and I've tried various simplifications)
// Who to...
[wallPost setObject:_selectedUser.id forKey:kFB_FIELD_TO];
[facebookManager performConnectedAction:^{
FBSession *facebookSession = facebookManager.facebookSession;
Assert( facebookSession.isOpen, #"Need an open Facebook session.");
[FBWebDialogs presentFeedDialogModallyWithSession:facebookSession parameters:wallPost handler:^(FBWebDialogResult result, NSURL *resultURL,NSError *error) {
if ( !!error ) {
[self logEventWithFormat:#"Failed to invite on Facebook [%#]", error];
}
}];
}];
Basically ... not only does the dialog flash up/down, but no callback is given (no error or result provided.) All other parts of the Facebook application continue to operate (our graph calls, our Facebook Friends dialog, and so on.)
I'd appreciate any thoughts on ways to investigate this further. I have filed a bug report:
http://developers.facebook.com/bugs/165456656937602?browse=search_5130e2d7663dd6543665811
I had the same issue and fixed it by delaying the method call like this. My method is fbWallPost
[self performSelector:#selector(fbWallPost) withObject:nil afterDelay:0.5];

Resources