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

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

Related

GMail OAUTH not asking for permission when published

I've started using the GMail API and it's working fine on my local machine; it will open the Google permissions page and I can select my account. It then stores the return json token and only asks again if this token is removed.
When I publish to the server, the OAUTH page is never displayed and the application appears to timeout with a 'Thread was being aborted' exception.
My code;
try
{
using (var stream = new FileStream(HttpContext.Current.Server.MapPath("~/credentials/client_id.json"), FileMode.Open, FileAccess.Read))
{
string credPath = HttpContext.Current.Server.MapPath("~/credentials/gmail_readonly_token.json");
_credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
db.writeLog("INFO", "Gmail Credentials Saved","Credential file saved to: " + credPath);
}
// Create Gmail API service.
service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = _credential,
});
}
catch (Exception e)
{
db.writeLog("Error", "Failure when creating Gmail class", e.Message, null, _username, null);
}
Is there something I need to change within the 'client_id.json' (formally client_secret.json) file? The only thing I have altered is the redirect_uris line.
Any other suggestions would be welcome, the only other question I could find that is similar is here but there is no answer.
Thanks,
Danny.
The first one worked because you followed the intended use case, which is client-side. But, to implement authorization on the server, follow the Implementing Server-Side AUthorization guide.

subscribeTag is not working in windowsphone8

i am implementing TAG based push notification in windowsphone8 but my app is not able to register the TAG when i execute following code.
i have tried putting subscribeTag outside onReadyToSubscribe too but i am not getting anything no success , no failure , no nothing.
if (WL.Client.Push) {
WL.Client.Push.onReadyToSubscribe = function() {
WL.Client.Push.subscribeTag("RRNEWS", {
onSuccess: function () {
alert("Tag registered");
},
onFailure: function (e) {
alert("Tag registered failed" + JSON.stringify(e));
}
});
};
}else{
alert("not supported");
}
i have register tag in application-descriptor.xml as follows
<tags>
<tag>
<name>RRNEWS</name>
<description>News</description>
</tag>
</tags>
here is the windowsphone8 entry
<windowsPhone8 version="1.0">
<uuid>6e043ba2-d382-4894-965f-47e08c24bd1e</uuid>
<pushSender/>
</windowsPhone8>
I run a tag based notification sample from Tag Notification github and deployed it on my mobile first server 6.3
when i generated the windowspone8 build and run it into a device , it shows following results
1) isPushSupported -> True
2) isSubscribed -> sample-tag1: false , sample-tag2: false
rest of the buttons are disabled
1) Subscribe to sample-tag2
2) Unsubscribe from sample-tag1
3) Unsubscribe from sample-tag2
then i tried removing disabled properties from html tag and try pressing
subscribe to sample-tag2 but nothing is happening.
Change is adapter code
function sendTagNotificationToWindows(applicationId, notificationText,notificationTags){
var notificationOptions = {};
var tags = notificationTags.split(",");
var notificationOptions = {};
var notification = WL.Server.createDefaultNotification(notificationText, 10);
notification.MPNS.raw = {};
notification.MPNS.raw.payload = {"custom":"data"} ;
notificationOptions.message = {};
notificationOptions.target = {};
notificationOptions.message.alert = JSON.stringify(notification);
notificationOptions.target.tagNames = tags;
// i have tried it with a notificationOptions too
WL.Server.sendMessage(applicationId, notification);
return {
result : "Notification sent to users subscribed to the tag(s): '" + JSON.stringify(notification) + "'."
};
}
Error
when i pass only notification param it throws following error
"Push Works Bad Request: FPWSE0005E: Invalid value was provided. Check the 'message' parameter value."
The Tag notifications sample project does not take into account the Windows Phone 8 environment. Here's what you need to add to the sample:
application-descriptor.xml
After adding the Windows Phone 8 environment, add an empty pushSender tag:
<windowsPhone8 version="1.0">
<uuid>AUTOGENERATED-GUID-NUMBER-HERE</uuid>
<pushSender/>
</windowsPhone8>
PushAdater-impl.js
Add the following to the function used for sending the notification.
For example, something like this:
function sendTagNotification(applicationId, notificationText, notificationTags) {
var tags = notificationTags.split(",");
var notificationOptions = {};
notificationOptions.message = {};
notificationOptions.message.alert = notificationText;
notificationOptions.target = {};
notificationOptions.target.tagNames = tags;
notificationOptions.settings = {};
notificationOptions.settings.mpns = {};
notificationOptions.settings.mpns.toast = {};
notificationOptions.settings.mpns.toast.text1 = "New notification";
notificationOptions.settings.mpns.toast.text2 = "You have a new notification";
notificationOptions.settings.mpns.toast.param = "/MainPage.xaml?value1=54321";
WL.Server.sendMessage(applicationId, notificationOptions);
return {
result : "Notification sent to users subscribed to the tag(s): '" + notificationTags + "'."
};
}
notificationOptions.settings.mpns.toast is needed so that when the application is closed (quit) or in the background, "toast" notification type will appear in the device.
Tapping on a toast notification launches the application. optional "param" field is used to pass on values that will be displayed once the application launches. The values set in the "param" of the toast can be retrieved natively and displayed within the application.
Additional clarifications:
When the app is open the raw notification type and the props and payload values can be seen on screen if used.
When the app is in the background and tapping the notification there are two notification types that can be receive: toast or tile. Both open the application.
When the app is in the background and tapping the app icon:
This means clicking the application tile. Application launches
When the app is closed and tapping the notification: Tapping on the toast launches the application. Tapping on the application tile launches the application.
When the app is closed and tapping the app icon: This means clicking the application tile. Application launches
I recommend to read the following MS documentation to understand what are the available notification types (Toast, Tile and Raw) and when to use them: https://msdn.microsoft.com/en-us/library/hh221549.aspx
Then search for "MPNS", "toast", "tile" or "raw" in the following user documentation topic (for onMessage) to see an example of how to set them up in your application: http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjavascript-server/html/WL.Server.html?cp=SSHS8R_7.1.0%2F10-1-0-1-6&lang=en

Chromecast Launch, what's with the DIAL parameters? Aren't I runing MY application, not some registered standard?

The following code displays a proper list of available chromecast devices on my network. But when I click on the links, the application never launches. There are a couple of things that I'm quite confused about that may or may not be related to this question:
If I'm making my own custom application, what's with the DIAL parameters and why do I have to pass them? I don't want to write an app for the DIAL standard... this is MY app.
Again related to the DIAL parameters, if I search for devices with any other query other than "YouTube" (a DIAL parameter), the list always comes up blank. I suppose I shouldn't care, as long as the device is listed... but again... the app won't launch.
It should be noted that my sender app is a chrome webpage.
I'm a bit confused as to where my "appid" goes int he launch parameters,'
<html data-cast-api-enabled="true">
<body>
hi!<BR/>
<script>
var cast_api, cv_activity;
if (window.cast && window.cast.isAvailable) {
// Cast is known to be available
initializeApi();
} else {
// Wait for API to post a message to us
window.addEventListener("message", function(event) {
if (event.source == window && event.data &&
event.data.source == "CastApi" &&
event.data.event == "Hello")
{
//document.write("Initialize via message.<br/>");
initializeApi();
//document.write("Api initialized via message.");
};
});
};
initializeApi = function() {
cast_api = new cast.Api();
cast_api.addReceiverListener("YouTube", onReceiverList);
};
var g_list;
onReceiverList = function(list) {
g_list = list;
// If the list is non-empty, show a widget with
// the friendly names of receivers.
// When a receiver is picked, invoke doLaunch with the receiver.
document.write("Receivers: "+list.length+"<br/>");
var t;
for(t=0;t<list.length;t++)
document.write('found:'+list[t].name+' ' +list[t].id+'<br/>');
};
onLaunch = function(activity) {
if (activity.status == "running") {
cv_activity = activity;
// update UI to reflect that the receiver has received the
// launch command and should start video playback.
} else if (activity.status == "error") {
cv_activity = null;
}
};
function launchy(idx)
{
doLaunch(g_list[idx]);
}
doLaunch = function(receiver) {
var request = new window.cast.LaunchRequest(">>>>>what REALLY goes here?<<<<<<< ", receiver);
request.parameters = "v=abcdefg";
request.description = new window.cast.LaunchDescription();
request.description.text = "My Cat Video";
request.description.url = "http://my.website.get.your.own/chomecast/test.php";
cast_api.launch(request, onLaunch);
};
stopPlayback = function() {
if (cv_activity) {
cast_api.stopActivity(cv_activity.activityId);
}
};
</script>
</body>
</html>
The part marked "what really goes here?" is the part that I THINK is wrong... I couldn't be completely wrong. My device is white listed, I have an appid (which I thought might go in that slot)... The documentation merely says ActivityType DIAL Parmeters are valid, mandatory.
The first argument to the LaunchRequest is your App ID, the one that you have received in an email as part of whitelisting process. Also, the "YouTube" in the initialize method should also be replaced with the same App ID.
I strongly suggest you look at the sample that is on GitHub for chrome sender to see how you can send a request to load a media on a cast device.

Buy & try in windows Phone 8?

Is that possible to make the buy & try options in windows phone 8
like in the windows store apps.
One of my game in the windows store is full access for one week from the day of download. After that windows store itself locks the game(If we give 1 week in the dashboard).
Like that, windows phone 8 having any of the features. .
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh286402(v=vs.105).aspx#BKMK_Runningtheapplication
Even i tried for Buy & try using the above link.
I changed the checklicense() like below.
private void CheckLicense()
{
if DEBUG
string message = "This sample demonstrates the implementation of a trial mode in an application." +
"Press 'OK' to simulate trial mode. Press 'Cancel' to run the application in normal mode.";
if (MessageBox.Show(message, "Debug Trial",
MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
_isTrial = true;
}
else
{
_isTrial = false;
}
else
_isTrial = _licenseInfo.IsTrial();
//Included lines
if(_isTrail)
freeversion = true; //Here Free version trigger when user presses Try
else
freeversion = false; //Here fullversion trigger when user presses Buy
//Included lines
endif
}
If i did like this. I run it in the Master Mode. It always goes for freeversion is false.(i.e: _isTrail is always returns false).
Its because of i have not yet uploaded to windows phone store or some other problem??
Help out to solve this??
There is no automated way to do that on Windows Phone, you'll have to implement the trial limitation yourself in the app.
Note that uninstalling an app on Windows Phone leaves no traces. Therefore, users will be able restart the trial period if they uninstall/reinstall the app.
Here is the code that i used:
private void CheckLicense()
{
LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
try
{
var listing = await CurrentApp.LoadListingInformationAsync();
var _price = listing.FormattedPrice;
// start product purchase
await CurrentApp.RequestProductPurchaseAsync("FeatureName", false);
ProductLicense productLicense = null;
if (CurrentApp.LicenseInformation.ProductLicenses.TryGetValue("FeatureName", out productLicense))
{
if (productLicense.IsActive)
{
MessageBox.Show("Product purchased");
CurrentApp.ReportProductFulfillment("FeatureName");
ProductPurchased(); // It display product purchased & trigger full version
return;
}
else
{
str = "Purchase failed";
ShowErrorPopup(str); // It shows error msg. purchase failed.
return;
}
}
}
catch (Exception)
{
str = "Purchase failed. Check internet connection and try again";
ShowErrorPopup(str);
return;
}
}

Chrome Devpanel Extension Communicating with Background Page

I have an extension to the chrome devtools panel. I can send messages to the page using chrome.devtools.inspectedWindow.eval ... but how do I receive messages in the dev panel? Specifically, I need my devpanel to hook into events that happen on the page. I can't get it to listen to events on my content script, nor the background page.
I've tried chrome.extension.sendMessage in the content script, along with chrome.extension.onMessage.addListener in the dev panel script. But sendMessage complains with Port error: Could not establish connection. Receiving end does not exist.
The issue persists with long-lived connections:
In content script or background page:
var port = chrome.extension.connect({name: "test"});
port.postMessage({msg: "testing"});
In dev tools panel javascript:
chrome.extension.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
// never gets here
});
});
How can I listen for events that are triggered in my content script-- in my dev tool panel? A diagram like this from Firefox's Add-On SDK would be great: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/static-files/media/content-scripting-overview.png
The goal is to create a channel ("port") for communication. It does not matter how the port is created, as long as the connection is correctly maintained.
The devtools script has to initiate the port, because the background script does not know when a devtools panel is created.
Here's a basic example, which shows a bidirectional communication method:
devtools.js
chrome.devtools.panels.create('Test', '/icon.png', '/panel.html', function(extensionPanel) {
var _window; // Going to hold the reference to panel.html's `window`
var data = [];
var port = chrome.runtime.connect({name: 'devtools'});
port.onMessage.addListener(function(msg) {
// Write information to the panel, if exists.
// If we don't have a panel reference (yet), queue the data.
if (_window) {
_window.do_something(msg);
} else {
data.push(msg);
}
});
extensionPanel.onShown.addListener(function tmp(panelWindow) {
extensionPanel.onShown.removeListener(tmp); // Run once only
_window = panelWindow;
// Release queued data
var msg;
while (msg = data.shift())
_window.do_something(msg);
// Just to show that it's easy to talk to pass a message back:
_window.respond = function(msg) {
port.postMessage(msg);
};
});
});
Now, the panel is capable of sending/receiving messages over a port. The panel's script (external script file, because of the CSP) may look like:
panel.js
function do_something(msg) {
document.body.textContent += '\n' + msg; // Stupid example, PoC
}
document.documentElement.onclick = function() {
// No need to check for the existence of `respond`, because
// the panel can only be clicked when it's visible...
respond('Another stupid example!');
};
Now, the background page's script:
background.js
var ports = [];
chrome.runtime.onConnect.addListener(function(port) {
if (port.name !== "devtools") return;
ports.push(port);
// Remove port when destroyed (eg when devtools instance is closed)
port.onDisconnect.addListener(function() {
var i = ports.indexOf(port);
if (i !== -1) ports.splice(i, 1);
});
port.onMessage.addListener(function(msg) {
// Received message from devtools. Do something:
console.log('Received message from devtools page', msg);
});
});
// Function to send a message to all devtools.html views:
function notifyDevtools(msg) {
ports.forEach(function(port) {
port.postMessage(msg);
});
}
To test, simply run notifyDevtools('Foo'); on the background page (e.g. via the console). In this demo, the message will be sent to all devtools. Upon receipt, the devtools panel will contain the received message.
Put the extension together using:
manifest.json
{
"name": "Test",
"manifest_version": 2,
"version": "1",
"devtools_page": "devtools.html",
"background":{"scripts":["background.js"]}
}
panel.html
<script src="panel.js"></script> <!-- Doctype etc not added for conciseness-->
devtools.html
<script src="devtools.js"></script>
See also
How to modify content under a devtools panel in a Chrome extension?
chrome.devtools API
Message passing: Long-lived connections
Content Security Policy in Chrome extensions ("Inline JavaScript (...) will not be executed. This restriction bans both inline <script> blocks and inline event handlers.")