I am using Azure notification hub to send push notification(xamarin forms). I have follow below example. and its working fine.
Example
I have an issue when push notification coming when app is open. this sample shows and popup when notification coming when user using the app.
This is the JSON code
{
"text": "Message from Postman!",
"action": "action_a"
}
public override void OnMessageReceived(RemoteMessage message)
{
if (message.Data.TryGetValue("action", out var messageAction))
NotificationActionService.TriggerAction(messageAction);
}
This shows popup called " ActionA action receved". I need to show my text message for this. I tried many ways but i couldn't modify it.
Related
I am trying to add push notification service (Remote) to my OSX app. I send the following payload and was able to get notification in my desktop. But the issue is with buttons.
{
"aps": {
"alert": {
"title": "Game Request",
"body": "Bob wants to play poker",
"action-loc-key": "PLAY"
},
"badge": 5
},
"acme1": "bar",
"acme2": ["bang", "whiz"]
}
I am able to get the notification, but the button "Play" will show
up only if I hover over the notification. Any thoughts on this behavior?
Also, Can I add multiple buttons as part of remote push notification
?
I found some samples on iOS, but no concrete samples regarding OSx. Any help or guidance really appreciated.
By default "Notification style" is banner on OSx. Only for "Alert" style It will show buttons. So changing to "Alert" it starts showing buttons.
I have successfully set up push notification using firebase and linked it up Azure notification hub using this guide from the Microsoft docs:
https://learn.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-push-notifications-android-gcm
However I am now trying to push notification to specific devices using tags. There isn't currently a xamarin c# document. I have done some research around the area and found people solving what seems to be the same problem using dependency injection (which feels a little complex?). I have also found these two questions/answers:
How to push notification to specific users in Xamarin.Forms Android?
https://forums.xamarin.com/discussion/85935/how-to-push-notification-to-specific-users-in-xamarin-forms-android
Both of which point to the method "OnRegistered" which i don't seem to have? i've had another look through the documentation I followed to set up notifications in the first place and I seem to have followed it correctly?
I have the following code for android:
private void SendRegistrationToServer(string token)
{
// Register with Notification Hubs
hub = new NotificationHub(ApplicationConstants.NotificationHubName,
ApplicationConstants.ListenConnectionString, this);
var tags = new List<string>() { };
var regID = hub.Register(token, tags.ToArray()).RegistrationId;
}
I can obviously set the tags manually there, however how do i 'call' this Method again if the tags need to be changed?
So bottom line, my question is how do i set up push notification to specific devices on xamarin.forms android/ios?
Thanks.
How can I open a notification in Xamarin. Forms?, I have implemented that receives and shows the notifications even if it is inside the application but I lack the action of the notification, not that to do...
I think you want to fire an action when user clicks your "OK" button on your message which includes notification message. I suggest you to use a custom dialog project like this:
Acr.UserDialogs
When you import that library, u can call a message and give an action method to its interface: (code may not compile, i wrote it randomly)
UserDialogs.Instance.Alert(new AlertConfig
{
Message = "Your notification message",
OkText = "OK",
OnAction = ()=>{/*youraction*/}
});
So when user taps on "OK" your action code will run. Do not forget to use "Device.BeginInvokeOnMainThread" method if you make UI changes:)
The docs for UIUserNotificationSettings is here.
Previously, I added a category to the UIMutableUserNotificationCategory and was able to get custom actions/buttons in the system notifications for iOS 8. Now, I want to remove them. I removed that code but when I tested the push notification with that category, the custom action still shows up.
My guess is that the notification settings is saved the the UIUserNotificationSettings which I don't have control over. Uninstalling and reinstalling the app does not seem to reset the notification settings for my app.
How do I get the app to stop responding to custom actions triggered by a category?
Thanks!
PS: An example payload that I used for the push notification which still works after I removed the code from the app:
{ "alert": "asdf", "sound": "default", "category": "AN_ACTION" }
I am working on facebook authentication in a Xamarin forms app and want to use "native" login on each device.
The Facebook SDK (by Xamarin) is not designed for forms since it requires passing in an Android activity that implements some specific interfaces.
However; I was able to get the UI to display using a custom page renderer and then in that renderer calling StartActitivty with an activity that uses the exact implementation described in the Facebook SDK getting started. https://components.xamarin.com/view/facebookandroid
So far everything works perfect. The android app starts, xamarin forms kicks in, the custom page renderer is loaded the login android activity starts and the user logs in with facebook and we get to the console.writeline below.
So, how do I dismiss this intent or otherwise get back to xamarin forms?
Do I:
Dismiss this intent? - if so then what?
Inject something to "reset" the main page?
Other?
public void OnCompleted (Xamarin.Facebook.Model.IGraphUser user, Response response)
{
//TODO: show user details with welcome and button that takes them to main app.
//TODO: switch back to xam forms from here on out.
//TODO: figure out how to change the `main` activity to xam forms.
// 'Me' request callback
if (user != null) {
//How do I get back to Xamarin forms from here?
Console.WriteLine ("GOT USER: " + user.Name);
} else {
Console.WriteLine ("Failed to get 'me'!");
}
}
You should call Finish();
Anyway, if you want to see exactly how I did it, you can check it here:
https://github.com/IdoTene/XamarinFormsNativeFacebook