Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example project for Push Notifications #7

Open
JoshuaNovak919 opened this issue Apr 27, 2015 · 18 comments
Open

Example project for Push Notifications #7

JoshuaNovak919 opened this issue Apr 27, 2015 · 18 comments
Assignees

Comments

@JoshuaNovak919
Copy link

Is there a way we can get a simple example project that uses the Push Notification plugin? The docs are a bit confusing and i'm not sure how i'm supposed to implement all the parts even after reading the txt files etc.

@rdelrosario
Copy link
Owner

Hi

There is instructions and step by step here:

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

Let me know if helps.

@rdelrosario rdelrosario self-assigned this Apr 29, 2015
@pjdupreez
Copy link

Hi there,

The link is broken. Cannot get to the instructions.

I did manage to get it working with the code on the main page, but how do I handle opening the notification? Notifications are received by my app and tapping the notification open my app, but on the first page. How can I tell it to open a specific page (I am using it for both iOS and Android in a Xamarin forms project)?

@codebase2015
Copy link

Hi Rendy,

First of all I am really thankful that you have developed the plugin for Xamarin and AWS and helping developers across the globe.

I am new to mobile development and trying to develop a mobile app for andriod platform using xamrin. I do have requirement of sending notfications to indivisual devices through Amazon SNS services.
I need your help on getting the tutorial link for Xamarin Push Notification with Amazon SNS.
http://lemoncode.net/2015/04/17/adding-push-notifications-to-your-xamarin-forms-application-part-1/ (this is broken link)
Could you please provide me the full example or link which I can follow.
It would be a great help.
Thank you
Ashish

@homerokzam
Copy link

I would also like to set an example for Android.

@rdelrosario
Copy link
Owner

Try the link of Step by step instructions on the README documentation just
updated the readme. Shouldn't be broken know let me know if works.
On Jul 23, 2015 10:41 AM, "homerokzam" notifications@github.com wrote:

I would also like to set an example for Android.


Reply to this email directly or view it on GitHub
#7 (comment)
.

@espilacopa
Copy link

My bad the link in the readme work just fine !! you're a boss !

thanks again !!

Hello, thanks for all your work but the link is still broken !
if you can do something !

@jwood803
Copy link

jwood803 commented Feb 3, 2016

I think this is the updated link from above.

Though, I'm still confused on how to implement in Android to receive the device token and when a message is received. Looking at part two from the link, it still doesn't seem to show that.

@Aybukes
Copy link

Aybukes commented Jul 15, 2016

@nmdias
Copy link

nmdias commented Feb 16, 2017

Does anyone have a working example? I'm not succeeding in implementing this.
None of the above links are working.

Thank you.

@CR4567
Copy link

CR4567 commented Feb 16, 2017

If you could be more specific we could help you.
In the readme you can find the normal way to get it working, except you have special requirements.

@nmdias
Copy link

nmdias commented Feb 16, 2017

No special requirements, but I have to be missing something.

I have implemented the IPushNotificationListener, in my CrossPushNotificationListener class. As suggested in the README file.

public class CrossPushNotificationListener : IPushNotificationListener
{
    void IPushNotificationListener.OnError(string message, DeviceType deviceType)
    {
        Application.Current.MainPage.DisplayAlert("error", message, "ok");
    }

    void IPushNotificationListener.OnMessage(JObject values, DeviceType deviceType)
    {
        Application.Current.MainPage.DisplayAlert("message", values.ToString(), "ok");
    }

    void IPushNotificationListener.OnRegistered(string token, DeviceType deviceType)
    {
        Application.Current.MainPage.DisplayAlert("token", token, "ok");
    }

    void IPushNotificationListener.OnUnregistered(DeviceType deviceType)
    {
        Application.Current.MainPage.DisplayAlert("unregistered", "", "ok");
    }

    bool IPushNotificationListener.ShouldShowNotification()
    {
        Application.Current.MainPage.DisplayAlert("should show notification", "", "ok");
        return true;
    }
}

In iOS’s AppDelegate, I then initialize the CrossPushNotification plugin.

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init ();

    CrossPushNotification.Initialize<CrossPushNotificationListener>();

    LoadApplication(new Origination.App ());
    return base.FinishedLaunching(app, options);
}

I have also extended the AppDelegate with the appropriate overrides as shown in the PushNotificationApplicationDelegate.txt.pp file:

public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
    if (CrossPushNotification.Current is IPushNotificationHandler)
    {
        ((IPushNotificationHandler)CrossPushNotification.Current).OnErrorReceived(error);
    }
}

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
    if (CrossPushNotification.Current is IPushNotificationHandler)
    {
        ((IPushNotificationHandler)CrossPushNotification.Current).OnRegisteredSuccess(deviceToken);
    }
}


public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
    if (CrossPushNotification.Current is IPushNotificationHandler)
    {
        ((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(userInfo);
    }
}


public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
    if (CrossPushNotification.Current is IPushNotificationHandler)
    {
        ((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(userInfo);
    }
}

Afterwards, in my shared code, after the user registered/logged in the App and enter it's home screen, I call:

CrossPushNotification.Current.Register();

I know this method is being executed, as I get an alert requesting permissions. But none of the methods from the IPushNotificationListener interface implemented in the CrossPushNotificationListener are called.

There must be something I'm not seeing here..

@CR4567
Copy link

CR4567 commented Feb 16, 2017

Did you install it on your real device or simulator?
Are you sure that a push notification is sent to your device?
Are using Azure or a different Push Server?

@nmdias
Copy link

nmdias commented Feb 16, 2017

I'm testing this on a real device.

My issue is that, the CrossPushNotification.Current.Register() method, while it's triggering an alert to request permissions for push notifications (as expected), the implementation of the IPushNotificationListener interface is never called. So I never get the device's token.

In fact, none of the method's from the AppDelegate are called (that's weird, considering the permissions alert).

@CR4567
Copy link

CR4567 commented Feb 16, 2017

Ok, I see. You're right, at least the Register callbacks of AppDelegate should be triggered.
But what I've seen looks good to me...
Could you give us access to your code? Or maybe someone else has an idea

@gtmorais
Copy link

gtmorais commented Mar 14, 2017

Same problem as nmdias, it does request permission for push notifications and calls DidRegisterUserNotificationSettings but never calls RegisteredForRemoteNotifications in order to get the device's token. For Android I've updated the payload fields that comes from Firebase on the plugin's source and now it shows the notification body on Android. But not for IOS. My CrossPushNotificationListener is on the PCL, only working for Android so far.

@gtmorais
Copy link

gtmorais commented Mar 14, 2017

Now it calls RegisteredForRemoteNotifications but when sending push it says the token is invalid using Pusher. So the token is invalid for now. It may be IOS 10 issue with this plugin.

@nmdias
Copy link

nmdias commented Mar 14, 2017

@gtmorais can you try adding a group to your app's entitlements? Give that a go.

I honestly don't remember if that was it, as I ended up with a custom dependency service.

Here's what I did, based on the plugin's source code:

http://stackoverflow.com/a/42422790/1544047

@pjavax
Copy link

pjavax commented Sep 22, 2017

My project do not work when i register CrossPushNotification in the OnStart method. I no have a error message, but don't run. When i debug it, then get in the Service to consume, don't work. Any help is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

13 participants