var 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();
push.QueueNotification(new WindowsPhoneToastNotification()
.ForEndpointUri(new Uri(uri))
.ForOSVersion(WindowsPhoneDeviceOSVersion.Eight)
.WithBatchingInterval(BatchingInterval.Immediate)
.WithNavigatePath("/LandingView.xaml")
.WithText1("PushSharp")
.WithText2("This is a Toast"));
push.StopAllServices();
I am using pushsharp nuget package for push notifications and while passing uri to this c# backend code for windows, I am getting notification failure exception.
I am using the latest version of PushSharp (version 3.0) in a project of mine to send toast notifications to Windows Phone Devices and it is working fine for me. I notice by the code you have above that you are using an older version of the PushSharp package, there is a new 3.0 version available from nuget.
You could use that latest package to send toast notification to windows phone devices. The latest version of PushSharp uses the WNS as opposed to the old MPNS.
If you go to that nuget get link i supplied above and download the solution you can see some examples on how to implement the push notifcations for windows phone using WNS. Look under the PushSharp.Test project (look for the WNSRealTest.cs file).
Below is an example of how you can send a toast notification to windows phone device:
var config = new WnsConfiguration(
"Your-WnsPackageNameProperty",
"Your-WnsPackageSid",
"Your-WnsClientSecret"
);
var broker = new WnsServiceBroker(config);
broker.OnNotificationFailed += (notification, exception) =>
{
//you could do something here
};
broker.OnNotificationSucceeded += (notification) =>
{
//you could do something here
};
broker.Start();
broker.QueueNotification(new WnsToastNotification
{
ChannelUri = "Your device Channel URI",
Payload = XElement.Parse(string.Format(#"
<toast>
<visual>
<binding template=""ToastText02"">
<text id=""1"">{0}</text>
<text id=""2"">{1}</text>
</binding>
</visual>
</toast>
","Your Header","Your Toast Message"))
});
broker.Stop();
As you may notice above the WnsConfiguration constructor requires a Package Name, Package SID, and a Client Secrete. To get these values your app must be registered with the Store Dashboard. This will provide you with credentials for your app that your cloud service will use in authenticating with WNS. You can check steps 1-3 on the following MSDN page for details on how to get this done. (note in the link above it states that you have to edit your appManifest.xml file with the identity of your app, I did not do this step, just make sure you have your windows phone app setup correctly to receive toast notification, this blog post will help with that.
Hope this helps.
Related
I am currently moving an ASP.NET application made by a third party from Windows to Linux. I read the documentation and nothing indicates this should be a problem, but sadly
var profile = new CredentialProfile(profileName, credentials) {
Region = RegionEndpoint.EUWest1
};
var netSDKFile = new NetSDKCredentialsFile();
netSDKFile.RegisterProfile(profile);
throws the following exception
Unhandled Exception: Amazon.Runtime.AmazonClientException: The encrypted store is not available. This may be due to use of a non-Windows operating system or Windows Nano Server, or the current user account may not have its profile loaded.
at Amazon.Util.Internal.SettingsManager.EnsureAvailable()
at Amazon.Runtime.CredentialManagement.NetSDKCredentialsFile..ctor()
Is the Amazon .NET SDK(or a part of it) not supported on Linux? If that is the case, is there a possible workaround?
For the most part there is very little that isn't supported on Linux that is supported on Windows. Off of the top of my head I can't think of anything besides NetSDKCredentialsFile which is due to the fact it uses Win32 API to encrypt credentials.
You can use SharedCredentialsFile to register a profile in the credentials file stored under ~/.aws/credentials. This is the same credential stored supported by all of the other AWS SDK and Tools.
Following on from Norm's answer, I found this resource that explained how to use Shared Credentials: https://medium.com/#somchat/programming-using-aws-net-sdk-9ce3f5119633
This is how I was previously using NetSDKCredentials, which won't work for Linux/Mac OS:
//Try this code on a non-Windows platform and you will see the above error
var options = new CredentialProfileOptions
{
AccessKey = "access_key",
SecretKey = "secret_key"
};
var profile = new CredentialProfile("default", options);
profile.Region = RegionEndpoint.USWest1;
NetSDKCredentialsFile file = new NetSDKCredentialsFile();
file.RegisterProfile(profile);
But I was then able to use this example to use SharedCredentials:
var credProfileStoreChain = new CredentialProfileStoreChain();
if (credProfileStoreChain.TryGetAWSCredentials("default", out AWSCredentials awsCredentials))
{
Console.WriteLine("Access Key: " + awsCredentials.GetCredentials().AccessKey);
Console.WriteLine("Secret Key: " + awsCredentials.GetCredentials().SecretKey);
}
Console.WriteLine("Hello World!");
You'll then be able to see your code is able to access the keys:
Access Key: A..................Q
Secret Key: 8.......................................p
Hello World!
I then used System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform() (as I am using this code on both Windows and Linux), to determine which credentials to use:
using System.Runtime.InteropServices;
//NETSDK Credentials only work on Windows - must use SharedCredentials on Linux
bool isLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
if (isLinux) {
//Use SharedCredentials
} else {
//Use NetSDKCredentials
}
You may find this section of the AWS documentation helpful, too: https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html#creds-locate
I have created in windows phone in Cordova. All things are working fine.
But now I have integrated Push Notification using Parse. I have configured correctly. But now I am only getting push when my app is in background or closed. But I am not getting Push notification when my app is open.
I have used this plugin.
Finally found the answer.
I have remove old plugin and install https://github.com/cookys/parse-push-plugin
and add below code in App.xaml.cs file
// Parse initialization
ParseClient.Initialize("APP_ID", ".NET_KEY");
this.Startup += async (sender, args) =>
{
ParseAnalytics.TrackAppOpens(RootFrame);
await ParseInstallation.CurrentInstallation.SaveAsync();
};
It worked for me. :)
Basically I am PHP developer! and now I want to implement the push notifications for windows phone! So for this I have refereed many blogs and also started implement on this! but for demo purpose how I can get my device token and device specific type of my phone that having Windows 8.1 OS.
Is any GUI tool for getting this.
If you need the Device Token as follows-
Byte[] DeviceArrayID = (Byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
string UniqueDeviceID = Convert.ToBase64String(DeviceArrayID);
Debug.WriteLine("Device ID - " + UniqueDeviceID
Also, if you need help regarding push notifications in Windows Phone apps, follow this link-
http://msdn.microsoft.com/en-us/library/windows/apps/hh202967%28v=vs.105%29.aspx
It also has a project for a simple webpage which can send notification to your device for testing purposes.
The following should work
object DeviceUniqueID;
byte[] DeviceIDbyte = null;
if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out DeviceUniqueID))
DeviceIDbyte = (byte[])DeviceUniqueID;
string di = Convert.ToBase64String(DeviceIDbyte);
The above code will give you the device ID. You can use the string di to pass the Device ID to your web service to provide the user with push notifications.
I've made a game using marmalade sdk and AppEasy engine and it works when I test it on the device but after submitting to store and downloading it only shows splash screen and then terminates.
Is there a way to debug it? Android and ios both have tools to trace the console output, is there such a tool for wp8? I only found how to do that for apps deployed to the device locally but no way to debug downloaded apps :(
For my other game made in same framework (with same issue) there is a crash report on the dev center dashboard with error saying 'STACK_OVERFLOW_DATA' but that doesn't help much
also tried this (solution found in some other question):
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
string result = "nothing :(";
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists("iwtrace.txt"))
{
using (var stream = new IsolatedStorageFileStream("iwtrace.txt", FileMode.Open, store))
{
using (var fileReader = new StreamReader(stream))
{
result = fileReader.ReadToEnd();
}
}
}
EmailComposeTask task = new EmailComposeTask();
task.To = "";
task.Subject = "crash log " + e.ExceptionObject.Message;
task.Body = result;
task.Show();
}
but it never get's to showing the email form
There's no way yet to debug retail version of WP8 apps especially which are made in Marmalade.
You can read more about that in the article explaining how to test the retail version.
According to the article you need to test the retail version via Visual Studio in case of Native C# app. I suppose even native XAML apps can't be debugged after downloading from store.
I've asked almost similar question on Marmalade forums last year. The only way at that time was to use Windows Power tool or Visual Studio.
To test the function, run your code from Visual Studio in release mode and see if it crashes or not. That's the only thing you can do in this case as far as I know.
When I use the Amazon SNS console to send toast messages to a Windows Phone 8 device (i.e. with the MPNS system), I can only send messages in text format. Selecting "Use platform specific JSON message dictionaries" and sending a JSON toast never seems to get to the device. The default message that you see when you select the platform specific format is a tile notification message, and that does work.
For exmple, the following message neither gives an error nor is displayed in the device:
{
"MPNS": "<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>Amazon</wp:Text1><wp:Text2>hooray</wp:Text2><wp:Param>this_is/my?extra=parameter</wp:Param></wp:Toast></wp:Notification>"
}
This has been tested with a couple of devices: Lumia 620 with Windows Phone 8.0 and Lumia 1020 with 8.1 beta. I have also tried sending messages from a Java backend, but it just shows up as a raw JSON text toast ({ "MPNS": ...) again. What could possibly be wrong? The JSON is valid, the XML is well-formed... I'm at loss.
I have run into the same issue recently, and found a solution. The SNS documentation for MPNS does not emphasise an important step, but it can be found in the sample code and eventually in the message attributes section of the docs.
You must set two MPNS-specific MessageAttributes on the PublishRequest. Omitting them will cause the delivery to fail with no clues left to investigate: i.e. even if you enable delivery status logs with CloudWatch, providerResponse will be missing.
For reference, the attributes are the following:
Attribute name: AWS.SNS.MOBILE.MPNS.Type
Possible values: token (for tile notifications), toast or raw
Attribute name: AWS.SNS.MOBILE.MPNS.NotificationClass
Possible values: realtime*, priority, regular
(realtime worked for me)
That said, it seems that it is not possible to send custom content to MPNS using the SNS console. But using the API works, so here is an excerpt from the Java sample for using the Java SDK:
AmazonSNS snsClient = ... /* initialise the client */;
Map<String, MessageAttributeValue> notificationAttributes = new HashMap<String, MessageAttributeValue>();
notificationAttributes.put("AWS.SNS.MOBILE.MPNS.Type",
new MessageAttributeValue()
.withDataType("String")
.withStringValue("token")); // or "toast" or "raw", depending on the payload
notificationAttributes.put("AWS.SNS.MOBILE.MPNS.NotificationClass",
new MessageAttributeValue()
.withDataType("String")
.withStringValue("realtime"));
PublishRequest request = new PublishRequest();
request.setMessageAttributes(notificationAttributes);
request.setMessageStructure("json");
request.setTargetArn(... /* topic or endpoint ARN */);
request.setMessage(... /* JSON payload */)
snsClient.publish(request);