PushSharp events not firing for WP8 - windows-phone-8

I have PushSharp successfully sending push notifications to Android, BB10, and iOS devices. I want to being sending notifications to WP8+ devices but it seems that nothing I do successfully registers the WindowsPhoneService.
Here is the code that I'm using:
PushBroker push = new PushBroker();
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;
push.RegisterWindowsPhoneService();
WindowsPhoneToastNotification windowsPhoneToastNotification = new WindowsPhoneToastNotification()
.ForEndpointUri(new Uri([[Device Uri]]))
.ForOSVersion(WindowsPhoneDeviceOSVersion.Eight)
.WithBatchingInterval(BatchingInterval.Immediate)
.WithNavigatePath("/MainPage.xaml")
.WithText1("Test 1")
.WithText2("Test 2")
;
push.StopAllServices();
Everything is pretty straightforward but notifications are not sent and no events get fired. Nothing. I can hit breakpoints all the way to "push.StopAllServices();" but not any breakpoints in any of the PushSharp-related events.
What am I missing?

In the latest version of PushSharp, there is a parameter to pass to the "StopAllService" for waiting the queue sended before stop :
//
push.StopAllServices(true);
This will force the pushchannel to send the notifications in the queue.

Related

web audio API crashing chrome

I'm trying to build something using the processor node here. Almost anything I do in terms of debugging it crashes chrome. Specifically the tab. Whenever I bring up dev tools, and 100% of the time i put a breakpoint in the onaudioprocess node, the tab dies and I have to either find the chrome helper process for that tab or force quit chrome altogether to get started agin. Its basically crippled my development for the time being. Is this a known issue? Do I need to take certain precautions to prevent chrome from crashing? Are the real time aspects are the web audio api simply not debuggable?
Without seeing your code, it's a bit hard to diagnose the problem.
Does running this code snippet crash your browser tab?
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
function onPlay() {
let scriptProcessor = audioCtx.createScriptProcessor(4096, 2, 2);
scriptProcessor.onaudioprocess = onAudioProcess;
scriptProcessor.connect(audioCtx.destination);
let oscillator = audioCtx.createOscillator();
oscillator.type = "sawtooth";
oscillator.frequency.value = 220;
oscillator.connect(scriptProcessor);
oscillator.start();
}
function onAudioProcess(event) {
let { inputBuffer, outputBuffer } = event;
for (let channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
let inputData = inputBuffer.getChannelData(channel);
let outputData = outputBuffer.getChannelData(channel);
for (let sample = 0; sample < inputBuffer.length; sample++) {
outputData[sample] = inputData[sample];
// Add white noise to oscillator.
outputData[sample] += ((Math.random() * 2) - 1) * 0.2;
// Un-comment the following line to crash the browser tab.
// console.log(sample);
}
}
}
<button type="button" onclick="onPlay()">Play</button>
If it crashes, there's something else in your local dev environment causing you problems, because it runs perfectly for me.
If not, then maybe you are doing a console.log() (or some other heavy operation) in your onaudioprocess event handler? Remember, this event handler processes thousands of audio samples every time it is called, so you need to be careful what you do with it. For example, try un-commenting the console.log() line in the code snippet above – your browser tab will crash.

How to configure Non-authenticated push notification for windows phone 8 in worklight

I have configured push notification in Android and IOS, and it's works perfectly. but when I configured Non-authenticated push notification for windows phone 8 in worklight, it's not working.I follow the below MobileFirst document to run push notification for windows Phone 8:
https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/notifications/push-notifications-overview/push-notifications-in-hybrid-applications/#setupWP8
Also i want to know, for subscription based push notification, which notification is recommended for windows phone 8 i.e. Non-authenticated push or Authenticated push?
Below is my code:
adapter.js
function submitNotification(userId, notificationText){
var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);
if (userSubscription==null){
return { result: "No subscription found for user :: " + userId };
}
var notification={};
notification.MPNS={};
var badgeDigit = 1;
var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});
notification.MPNS.toast={};
notification.MPNS.toast.text1 = "Toast title";
notification.MPNS.toast.text2 = "Toast content";
WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText);
WL.Server.notifyAllDevices(userSubscription, notification);
return {
result: "Notification sent to user :: " + userId
};
}
application-descriptor.xml
<windowsPhone8 version="1.0">
<uuid>5747-54938-fjhg-f459-844h-fhkj</uuid>
</windowsPhone8>
Please help me on windows phone 8 push notification.
++++++++++++++++++++++++++++++Update Question+++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
After adding push sender id in "application-descriptor.xml". push notification is working on windows phone8. but facing problem to receive broadcast notification on windows phone8.
broadcastAdapter.js
function sendBroadcastNotification(applicationId, notificationText) {
var notificationOptions = {};
notificationOptions.message = {};
notificationOptions.message.alert = notificationText;
WL.Server.sendMessage(applicationId, notificationOptions);
return {
result : "Notification sent to all users."
};
}
client side code in main.js:
if(WL.Client.Push){
WL.Client.Push.onMessage = function (props, payload) {
navigationFromNotification = true;
WL.SimpleDialog.show("Tag Notifications", "Provider notification data: " + JSON.stringify(props), [ {
text : 'Close',
handler : function() {
WL.SimpleDialog.show("Brodcast Notifications", "Application notification data: " + JSON.stringify(payload), [ {
text : 'Close',
handler : function() {
window.location.href="#/home/2";
}
}]);
}
}]);
};
}
Am I need to add anything to receive broadcast Notification on windows phone8 ?
The documentation you have linked to clearly mentions to add an empty pushSender element, and as can be seen in your code snippet from application-descriptor.xml - you did not do that. Basically, you did not configure your application to use push notifications(!).
<windowsPhone8 version="1.0">
<uuid>auto-generated by the platform</uuid>
<pushSender />
</windowsPhone8>
Authenticated or not authenticated push is not related to user-based subscription.
You can use either one. The only limitation by MS is that non-authenticated is limited to 500 messages per day, whereas authenticated is not limited (and more secure).
a) MPNS Push notifications can operate in unauthenticated or authenticated mode. In unauthenticated mode, the number and frequency of notifications allowed through the Microsoft Push Notification Service is throttled (unauthenticated push notifications are currently limited to 500 per day, per channel).
MSDN documentation.
IBM MobileFirst supports both authenticated and non-authenticated MPNS push.
b) In case of Tag/Broadcast MPNS notifications, by default the notification appears within the application tile. For the notification to be displayed when the application is in foreground or as a toast notification add the following code to the sendBroadcastNotification() method in the adapter:
notificationOptions.settings = {};
notificationOptions.settings.mpns ={};
notificationOptions.settings.mpns.raw = {};
notificationOptions.settings.mpns.raw.payload= {'payload' : notificationText};
notificationOptions.settings.mpns.toast ={};
notificationOptions.settings.mpns.toast.text1 = 'Title';
notificationOptions.settings.mpns.toast.text2= notificationText;
Refer to the TagNotifications sample for the complete code

browseForDirectory fails on Windows 7 with File.documentsDirectory as root

Odd, non-cross platform behavior here: in an AIR app, I want to open a directory browse window.
On OSX I use this code and it works fine (projectDirectory has been declared earlier as type File:
projectDirectory = File.documentsDirectory;
projectDirectory.browseForDirectory("Select Project Directory");
but it fails on Windows 7: no directory browser opens. However if I specify the userDirectory I do get a directory browser:
projectDirectory = File.userDirectory;
projectDirectory.browseForDirectory("Select Project Directory");
According to the Adobe AIR docs, both these File directory constants are valid for each platform so I am confused. I've fiddled with it and tried various things but I can't get File.documentsDirectory` to work on WIndows 7. Has anyone seen this before?
My dev environment is OSX and I am running Windows 7 as an admin user through VMWare so maybe that is the culprit but I would expect total failure if that were the case.
Update
Odd - with File.documentsDirectory I don't get an error and don't even see the "BEFORE" btn click msg but with
File.userDirectory I see the msgs and the directory browser opens as expected.
//projectDirectory = File.documentsDirectory;
projectDirectory = File.userDirectory;
try{
projectDirectoryPathField.text += "BEFORE button clicked \n";
projectDirectory.browseForDirectory("Select Project Directory");
projectDirectoryPathField.text += "AFTER button clicked \n";
} catch(error:SecurityError){
projectDirectoryPathField.text += error.errorID +" \n";
projectDirectoryPathField.text += error.message +" \n";
projectDirectoryPathField.text += error.name +" \n";
}

Flash update 12 broke my video recorder

When flash pushed the 12.0.0.70 version to Chrome it broke my video recorder.
According to the patch notes here, one thing was changed that might have broken my flash-based recorder
[3689061] [Video] Resolves an issue injected in Flash Player
11.9.900.170 that caused the video buffer to no longer be filled if the buffer was emptied while playing an RTMP stream
My recorder breaks when it's time to stop the stream and save the video to the Adobe Media Server.
I tried debugging it with the 12.0.0.70 flash debugger, but it doesn't crash when I'm using the debugger. Only when using the non-debugger Chrome version does it crash.
I can't debug it and get any useful information out of my swf, apart from making a bunch of external calls to console.log to see where it fails.
If someone also ran into a similar issue with flash-based, media-server-connected webcam recorders, and can guess at what might fix my problem, I'd be grateful.
I'm building this swf with Flex 4.6.0
Here's the function that stops the video recorder.
public function doStop():void{
if(status=="paused"){
doResume();
}
rectColor.color=0x000000;
rectColor.alpha=1;
var timer:Timer=new Timer(1 * 10);
timer.addEventListener(TimerEvent.TIMER,function(e:TimerEvent):void{
timer.stop();
timer.reset();
myns.close();
myTimer.stop();
if(!thumbBeginning){
if(status=="recording"){
takeScreenShot();
}
}else{
if(status=="recording"){
recordingTime = formatTime(realTime);
recordingLength = myTimer.currentCount;
if(!redoFlag){
ExternalInterface.call("CTRecorder.stopOk");
myTime.text = formatTime(0);
VD1.attachCamera(myCam);
setState("ready");
status = "stopped, ready"
playbackTimer.reset();
msg(recordingTime);
recording=false;
pauseTime=0;
}else{
pauseTime=0;
myTime.text = formatTime(0);
VD1.attachCamera(myCam);
playbackTimer.reset();
msg(recordingTime);
recording=false;
}
}
if(shutterGroup.visible){
toggleShutter();
}
myTimer.stop();
myTimer.reset();
if(redoFlag){
doRecord();
redoFlag=false;
trace("redoFlag turned off");
}
}
rectColor.alpha=.5;
});
timer.start();
}
This isn't really an answer, but it's too long for a comment.
"I can't debug it" - it only breaks in the release version? Is the release version the pepper plugin (i.e. Chrome's version of Flash), and the debug is the NPAPI plugin (i.e. Adobe's version)?
A likely candidate for where it's breaking is the ExternalInterface.call("CTRecorder.stopOk"); call. Are you testing this locally, or remotely? If locally, then you might be running into this bug: https://code.google.com/p/chromium/issues/detail?id=137734 where the Flash <-> JS communication is broken because of Trusted locations being ignored in PPAPI flash. In any case, try installing the release NPAPI version of Flash and see does it still crash (you can verify which one is running by visiting chrome://plugins/)
To help debugging the release version, you need a logging system - instead of making trace() calls, you call a custom log() function, that, as well as trace()ing, also stores the message somewhere, like in an Array. Then, in your SWF, when you hit a certain key, show a TextField on the screen, and populate it with your log() messages. That way, you'll be able to see trace() statements in release mode.
Also, don't forget to listen to any relative error events and thrown exceptions - ExternalInterface.call() will throw an Error and SecurityError for example. You can also set the marshallExceptions property, which will pass ActionScript exceptions to the browser and JavaScript exceptions to the player: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#marshallExceptions
Finally, add a listener for the UncaughtErrorEvent.UNCAUGHT_ERROR event on your main class, which will catch any uncaught thrown errors (funnily enough), which will at least mean that your app doesn't collapse:
mainClass.loaderInfo.uncaughtErrorEvents.addEventListener( UncaughtErrorEvent.UNCAUGHT_ERROR, this._onUncaughtErrorEvent );
private function _onUncaughtErrorEvent( e:UncaughtErrorEvent ):void
{
var message:String = null;
var stackTrace:String = null;
// get the message
if ( e.error is Error )
{
message = ( e.error as Error ).message;
try { stackTrace = ( e.error as Error ).getStackTrace(); }
catch ( error:Error ) { stackTrace = "No stack trace"; }
}
else if ( e.error is ErrorEvent )
message = ( e.error as ErrorEvent ).text;
else
message = e.error.toString();
// show an alert
trace( "An uncaught exception has occurred: " + e.errorID + ": " + e.type + ": " + message + ", stack:\n" + stackTrace );
e.preventDefault();
}

How to send Json data in payload as Toast or Tile Notification in Windows Phone

I want to send Json data in payload as Toast or Tile Notification in Windows Phone as shown below:
string msg =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1><string></ltwp:Text1>" +
"<wp:Text2><string></wp:Text2>" +
"<wp:Json><data></wp:Json>" +
"</ltwp:Toast>" +
"</wp:Notification>";
If it is possible, will I be able to receive the Json in ShellToastNotificationReceived event handler?
You can send parameters with values like following :
string msg =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1><string></ltwp:Text1>" +
"<wp:Text2><string></wp:Text2>" +
"<wp:Param>/Home.xaml?NavigatedFrom=Toast Notification</wp:Param>" +
"</ltwp:Toast>" +
"</wp:Notification>";`
If your app is running in foreground then PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) is fired and in e.Collection[key] you can find the message you sent.
If your app is not running in the foreground then on tapping the toast notification app gets launched and is navigated to the specified page(here /Home.xaml). In the OnNavigatedTo(NavigationEventArgs e) event of the page you can find the parameters you passed and can use them.
So you can give it a try by sending json string in the parameter values and can use them in your app.I have not tried it.This information might be useful for you.
All the best.
If you want to send generic content you should instead use a Raw Notification. This can contain whatever content you wish.
The limitation of the raw notification is that it can't be received if your app is not running so you may want to send a Toast (or tile) notification to the device and then when the app is subsequently launched trigger the sending of the raw notification.
Of course if you're making a web request to trigger sending a single raw message it will probably be better to just send the payload in response to the trigger request.