Dienstag, 9. Juni 2015

Showing push notifications only to certain users with xamarin and Azure mobileservices on android and ios

It took me some time to figure this out so:

First create the templates for Android and IOS:

Android:
private static string TodoCreated = "{\"data\":{\"title\":\"$(Title) + \' was created! \'\", \"text\":\"$(Description)\", \"ID\":\"$(ID)\"}}";

IOS:
private static string TodoDeleted = "{\"aps\": {\"alert\":\"{$(Title) + \' was deleted! \'}\"}, \"id\":\"$(ID)\"}";

Then add two tags to it. First the Azure UserID and then the template name that you registered the template with.
Then in the backend project just connect these two with && and thats it.

string userTag = authenticatedUser.Id;
List<string> tags = new List<string>();
tags.Add(userTag+"&&TodoCreated");

Really easy and flexible solution. It makes it super easy to subscribe to only certain pushnotifications for example.


Show alert with xamarin android

I was searching for an Alert on Android and found this:

button.Click += (o, e) =>
             {
                   Toast.MakeText(this, "Beep Boop", ToastLength.Short).Show();
             };

Its a nice little notification that can be called from within an activity.

Freitag, 5. Juni 2015

Having problems installing Newtonsoft.Json Nuget package in xamarin visual studio

Hey i had problems installing the newest Newtonsoft.Json package.

To be able to install it open the powershell as admin and perform:
1. start-job {Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
2. restart visual studio. (important :))
3. Install package
4. Change back for security reasons:
start-job {Set-ExecutionPolicy RemoteSigned } -RunAs32 | wait-job | Receive-Job

Uninstall an old nuget package in xamarin visual studio

I had problems with my automapper version, but i could not uninstall it because it was used with Microsoft azure mobile services.
So to uninstall an old nuget package open the package messenger console in visual studio and call:

unistall-package automapper -force

Debugging azure mobile service locally with IIS express and android / IOS simulator or device

I had a lot of problems getting this to work so i thought i could share the solution.

1. First find out your local ip with ipconfig.

2. Open C:\Users\<your profile name>\Documents\IISExpress\config\applicationhost.config
Add/Change this part of code to add a port binding: 

<site name="todolist_Service" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Archive\GetStartedDataWP8\C#\todolist_Service" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:58203:localhost" />
        <binding protocol="http" bindingInformation="*:58203:192.168.137.72" />
    </bindings>
</site>

3. Very important: Start Visual studio as admin. Otherwise it can't create the binding.
4. Use your ip and port as connection string for your MobileServiceClient.
5. Try to access this url from your mobile broswer to see ti it works. It should show the blue azure screen with the :).
6. (Optional) If it still does not work try
- disabling your firewall
- Add netsh http add urlacl url=http://ip:port/ user=everyone (Or "Jeder" if you are on a german mashine as i was...)




Build in xamarin mobile android not starting although it worked fine yesterday

Just a small thing.
I could not start my android build today although it worked fine yesterday evening.

It was because i was using the xamarin test version and the build is only valid for 24 hours.
So rebuild, deploy and debug fixed it. 

Debug azure mobile service with Postman using OAuth 2

I had some problems finding the right tokens to access backend functions with         [AuthorizeLevel(AuthorizationLevel.User)]
from within postman so i thought i share how i found it. 

Go to 

https://<URL-APP-ID>.azure-mobile.net/login/<YourProvider> 
in my case: 
https://plany2.azure-mobile.net/login/google

in the redirect url you will find the token. Copy paste it here: http://meyerweb.com/eric/tools/dencoder/

convert it and then take the authenticationToken and put it into postman header as X-ZUMO-AUTH. 

Thats allready it.