How to use Amazon SNS with Xamarin

JoshuaNovakJoshuaNovak USMember ✭✭

I'm trying to setup Amazon SNS with my Xamarin Forms project, but I can't seem to find any docs on it. I found the SDK that Amazon made for Xamarin (link below), but it doesn't seem to have any docs with it. Anyone know how to use it or where any examples are?

https://github.com/awslabs/aws-sdk-xamarin

Posts

  • RussellCollinghamRussellCollingham GBUniversity ✭✭

    Actually to receive the notifications you don't do anything SNS specific. The actual notifications come from the native notifiers (Google GCM, Apple and Windows phone). So in your forms app you need to accept any notification. You could then use Amazon SNS, Parse, Azure to send the notifications.

    We use https://github.com/rdelrosario/xamarin-plugins/tree/master/PushNotification and these xamarin guides are really useful http://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/

  • JoshuaNovakJoshuaNovak USMember ✭✭

    @RussellCollingham Thanks! Yeah, that's the plugin I was trying to figure out, but there wasn't much documentation on it. I contacted the developer and he showed me this awesome tutorial for setting up the plugin and connecting it to a backend. Hope it helps others as much as it's helped me.

    http://lemoncode.net/2015/04/17/adding-push-notifications-to-your-xamarin-forms-application-part-1/

  • RussellCollinghamRussellCollingham GBUniversity ✭✭

    Thank you, good read. My mistake you do of course have to register the phone as an endpoint with SNS

            void IPushNotificationListener.OnRegistered(string Token, DeviceType deviceType)
            {
                Debug.WriteLine(string.Format("Push Notification - Device Registered - Token : {0}", Token));
                try
                {
    
                    string apn = Configuration.AmazonSNSAPNIOS;
                    if (deviceType == DeviceType.Android)
                        apn = Configuration.AmazonSNSAPNAndroid;
    
                    var snsClient = new AmazonSimpleNotificationServiceClient(Configuration.AmazonSNSUsername,                  Configuration.AmazonSNSPassword, Amazon.RegionEndpoint.EUWest1);
    
                    var request = new CreatePlatformEndpointRequest
                    {
                        CustomUserData = Configuration.Title,
                        PlatformApplicationArn = apn,
                        Token = Token
                    };
                    snsClient.CreatePlatformEndpointAsync(request);
                }
                catch (Exception X)
                {
    
                }
            }
    
  • JoshuaNovakJoshuaNovak USMember ✭✭

    @RussellCollingham I assume you have to add the aws-sdk-xamarin nuget package to all the PCL clients to use those commands?

  • RussellCollinghamRussellCollingham GBUniversity ✭✭
    edited April 2015

    Yes, although I am using a shared project solution. I used the nuget manager to add to each of the 3 platform projects. Note there is a missing file inside the iOS version of the AWS Xamarin Mobile DLL which I have reported as an issue several weeks ago and which has been closed but not solved (https://github.com/awslabs/aws-sdk-xamarin/issues/20)

    The Configuration stuff in my code above is just a local settings class I use.

  • JoshuaNovakJoshuaNovak USMember ✭✭

    @RussellCollingham It looks like they just released a new version a few hours ago. It still isn't updated on nuget, but i'm hoping they push it there soon since it supposedly fixes the DLL issue.

  • hopewisehopewise JOMember

    @Russell if you will register the endpoint from within the mobile, you will need to store the credentials in the mobile, which could be un-safe if the app was hacked .. right? I recommend let this registration at the server side, what do you think?

  • RussellCollinghamRussellCollingham GBUniversity ✭✭

    @hopewise yes, that's true, but you can set very limited user rights in AWS so no damage can be done.

  • hopewisehopewise JOMember

    With the minimal user rights in this case, millions of injected end points might get registered if keys where compromised..

  • batmacibatmaci DEMember ✭✭✭✭✭

    how is it possible to send custom notification after some data insert? for example using azure c# backend, i can trigger a notification if a successful insert happens. how can I do that using amazon cognite sync or dynamoDb. is there a way to do it?

  • Alwin.5974Alwin.5974 USMember ✭✭

    It seems that the plugin mentioned above has been deprecated and it is suggested to use:

    https://github.com/CrossGeeks/PushNotificationPlugin

    I have the plugin installed, I have AWS SNS setup with a platform application that is linked to FCM so I have the ARN and all server bits in place (I think?). What I don't understand is how to use the ARN when registering the mobile device, as far as I can tell:

    PushNotificationManager.Initialize(this,false);
    

    will auto-register and I'm guessing I will receive a token in

            CrossPushNotification.Current.OnTokenRefresh += (s, p) =>
            {
                string token = p.Token;
            };
    

    But I don't understand how to tell PushNotificationManager where to connect to and how to specify the ARN. The documentation for the plugin talks about compiling google-services.json which looks as though it may be for this purpose but where would I get that json from?

    Any input is welcome.

Sign In or Register to comment.