Background Task using PushNotificationTrigger() - windows-10-universal

For TimerTigger() Background Task is working fine. When I want to debug I can do it from Lifecycle Events. But when I use PushNotificationTrigger() I am not able to debug the background task. I am not getting where I am doing wrong, please help.
This is what I get on Lifecycle Events while debugging.
This is how I am registering Background task for Raw Notifications,
if (!Windows.ApplicationModel.Background.BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name == "PushBackgroundTask"))
{
var result = await BackgroundExecutionManager.RequestAccessAsync();
var builder = new BackgroundTaskBuilder();
builder.Name = "PushBackgroundTask";
builder.TaskEntryPoint = typeof(NotificationActionBackgroundTask.NotificationActionBG).FullName;
builder.SetTrigger(new Windows.ApplicationModel.Background.PushNotificationTrigger());
BackgroundTaskRegistration task = builder.Register();
}
This is my app's Package.appxmanifest code,
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="NotificationActionBackgroundTask.NotificationActionBG">
<BackgroundTasks>
<Task Type="pushNotification" />
</BackgroundTasks>
</Extension>
</Extensions>

I have checked our code and config file, it seems that they should be correct, in order to let your Backgroundtask's name show in your Lifecycle events windows for your debugging, you need to click the "Suspend" event inside the Lifecycle event windows after you have registered the Backgroundtask. Then your Backgroundtask's name will show inside the Lifecycle events windows.
If it still does not work, I wonder if you have registered the Backgroundtask correctly before you do the debugging, only if we have registered the Backgroundtask successfully, then we can debug the Backgroudtask using the Lifecycle event. If so, could you please try to put a breakpoint inside the register method to see what happens?
For more information, please check the following two articles:
Debug a background task.
Background tasks triggered by raw notifications.

Related

I am using AutoJsContext in geckobrowser with that I am using evaluate scrpit. But now i am using webview2 is there a how can i get this

I am using AutoJsContext in geckobrowser with that I am using evaluate scrpit and asble to get data. But now i am using webview2 is there a how can i get this.
Gecko browser:
using (AutoJSContext context = new AutoJSContext(browser.Window))
{
var userIdResult = context
.EvaluateScript("userId", (nsIDOMWindow)browser.Window.DomWindow);
}
Above is the code I use in gecko browser. now i need to get user id from webview2. Please help me in this issue
I am not able to get any alternative
You can use CoreWebView2.ExecuteScriptAsync to inject script into the current top-level document of the WebView2 and receive the result as a JSON string. The method doesn't have a way to specify an execution context. Script is executed in the global context of the top-level document similar to running script in the console of DevTools in the browser.
For example something like the following:
var resultAsJSON = await coreWebView2.ExecuteScriptAsync('window.userId');

How can I troubleshoot Launch Darkly SDK when it fails to get flag values?

I'm trying to set up a simple Launch Darkly integration in .NET but it isn't working. The code seems to run just fine, but it doesn't actually get the flag value. It always returns false regardless of whether I turn the flag on or off in my Launch Darkly dashboard.
Here's my code:
LdClient client = new LdClient("my sdk key");
var user = LaunchDarkly.Sdk.User.WithKey("12345");
var anonymous = LaunchDarkly.Sdk.User.Builder(Session.SessionID).Anonymous(true).Build();
bool enabledForUser = client.BoolVariation("website-poc", user);
bool enabledForAnonymous = client.BoolVariation("website-poc", anonymous);
client.Dispose();
The variables "enabledForUser" and "enabledForAnonymous" always return false. How can I troubleshoot the issue? What are some possible reasons why it's not working? (Note: the client object's "Initialized" property shows up as true, so I assume that means the connection was successful.)
Here's what my flag looks like on the Launch Darkly dashboard. The green "On" toggle means that it should be returning true, right?
I figured out the issue. I was using the SDK key for the wrong project. You can use the yellow drop-down on the dashboard to see which project you're working with.

HostListener and Angular Universal

I'm trying to listen to a MessageEvent sent with postMessage in my Angular 2 component.
My first attempt was simply doing:
window.addEventListener("message", this.handlePostMessage.bind(this));
And then in ngOnDestroy:
window.removeEventListener("message", this.handlePostMessage.bind(this));
However this didn't work as expected. If I navigated to another route and back, there would be two event listeners registered.
So instead I've been trying to decorate the method with HostListener, but I can't get this working when using prerendering (Angular Universal with .NET Core using the asp-prerender-module).
#HostListener('window:message', ['$event'])
private handlePostMessage(msg: MessageEvent) {
...
}
That gives me the following error on page load:
Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: MessageEvent is not defined
Is there a workaround for this?
You're getting this error because MessageEvent is not defined. You must import whatever file defines this.
My #HostListeners look like this:
#HostListener("window:savePDF", ["$event"]) savePDF(event) {
this.savePDFButtonPushed();
}
and you can read more about them here:
https://angular.io/guide/attribute-directives
However, I'm currently experiencing the same issue you are -- that if I navigate to another route and back, I now receive two events. And that is using #HostListener. :-( However I haven't upgraded Angular in a while (currently using 4.4.6), so maybe they've fixed it since that release.
**Edit: Just upgraded to Angular 5.1.0. The 'duplicate events' #HostListener issue remains. :-(
Edit #2: I tried also using window.addEventListener like you tried, and also had the same issue, despite using window.removeEventListener in ngOnDestroy().
This lead me to dig a little deeper, where I found some code I had added to listen to messages from a child iFrame. Any chance you have something similar in your code?
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
// Listen to messages from child window ("unsign" and "savePDF") and pass those along as events to Angular can pick them up in its context
eventer(messageEvent,function(e) {
window.dispatchEvent( new Event( e.data ) );
},false);
This had been in my page's constructor. I protected it so it only executed the first time the page was constructor, and now all is well.

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

SignalR server doesn't consistently call methods on client

I have an AngularJS application that I intend to have receive communications via SignalR from the server, most notably when data changes and I want the client to refresh itself.
The following is my hub logic:
[HubName("update")]
public class SignalRHub : Hub
{
public static void SendDataChangedMessage(string changeType)
{
var context = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>();
context.Clients.All.ReceiveDataChangedMessage(changeType);
}
}
I use the following within my API after the data operation has successfully occurred to send the message to the clients:
SignalRHub.SendDataChangedMessage("newdata");
Within my AngularJS application, I create a service for SignalR with the following javascript that's referenced in the HTML page:
angular.module('MyApp').value('signalr', $.connection.update);
Within the root for the AngularJS module, I set this up with the following so that it starts and I can see the debug output:
$(function () {
$.connection.hub.logging = true;
$.connection.hub.start();
});
$.connection.hub.error(function(err) {
console.log('An error occurred: ' + err);
});
Then I've got my controller. It's got all sorts of wonderful things in it, but I'll show the basics as relate to this issue:
angular.module('MyApp').controller('MyController', function($scope, signalr) {
signalr.client.ReceiveDataChangedMessage = function dataReceived(changeType) {
console.log('DataChangedUpdate: ' + changeType);
};
});
Unfortunately, when I set a breakpoint in the javascript, this never executes though the rest of the program works fine (including performing the operation in the API).
Some additional (hopefully) helpful information:
If I set a breakpoint in the SignalRHub class, the method is successfully called as expected and throws no exceptions.
If I look at Fiddler, I can see the polling operations but never see any sign of the call being sent to the client.
The Chrome console shows that the AngularJS client negotiates the websocket endpoint, it opens it, initiates the start request, transitions to the connected state, and monitors the keep alive with a warning and connection lost timeout. There's no indication that the client ever disconnects from the server.
I reference the proxy script available at http://localhost:port/signalr/hubs in my HTML file so I disregard the first error I receive stating that no hubs have been subscribed to. Partly because the very next message in the console is the negotiation with the server and if I later use '$.connection.hub' in the console, I'll see the populated object.
I appreciate any help you can provide. Thanks!
It's not easy to reproduce it here, but it's likely that the controller function is invoked after the start of the connection. You can verify with a couple of breakpoints on the first line of the controller and on the start call. If I'm right, that's why you are not called back, because the callback on the client member must be defined before starting the connection. Try restructuring your code a bit in order to ensure the right order.

Resources