I am using push sharp to create remote notification.
But I get the notification with out a title and a View/Close buttons.
I am using a code adapted from
Here
Here is how I create my alert
AppleNotificationAlert alert = new AppleNotificationAlert();
alert.ActionLocalizedKey = "View Alert";
alert.Body = message;
alert.AddLocalizedArgs(new object[] { "title", "Test Title"});
pushBroker.QueueNotification(new AppleNotification() .ForDeviceToken(deviceToken).WithAlert(alert).WithBadge(1).WithSound("sound.caf").WithCustomItem("level", level).WithContentAvailable(1));
I also tried just specifying the Alert body as follows but it does not show View/Close buttons
pushBroker.QueueNotification(new AppleNotification() .ForDeviceToken(deviceToken).WithAlert("Alert Body").WithBadge(1).WithSound("sound.caf").WithCustomItem("level", level).WithContentAvailable(1));
Your code is right. I just spinned it out and it worked ! In your IOS device settings choose your app and then notifications and then change the notification type from banner to an alert and you will get your custom Buttons and Title!
Related
Hi am developing a Xamarin Forms app. i have implemented local notifications in the app. When the notification has fired, upon clicking the notification it has to navigate to a particular page.
In iOS project in Appdelegate.cs i wrote this method
public async override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
which will fire when the user taps on the notification. here i need to navigate to a page. Here i wrote the below line of code
App.Current.MainPage = new NavigationPage(new FavoritesPage());
It is navigating to the Favorites page but it is just displaying a blank page. OnNavigatedTo method is not calling for the FavoritesViewModel and in the Onnavigated to am calling a method which takes id(this id comes from the notification) as parameter to get a particular favorite
Here two questions
1) How to navigate to a Specific page
2) How to pass a parameter along with the page navigation.
Can someone please help me to solve this issue.
For 1:
You want to push to a new Page, but what you did is replacing the app's MainPage. please try PushAsync. You can subscribe a MessagingCenter in App:
public App ()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
MessagingCenter.Subscribe<object, string>(this, "Push", async (sender, favoriteID) =>
{
var favorite = new FavoritesPage();
favorite.FavoriteID = favoriteID;
await (MainPage as NavigationPage).PushAsync(favorite, true);
});
}
This Lambda will fire when you call MessagingCenter.Send<object, string>(this, "Push", "01");
The string 01 here is the ID what I want to push.
For 2:
Before I push to a new page, I define a property called FavoriteID in this page, then I pass the string using method above.
Use MessagingCenter, set ContentPage type or url for MessagingCenter.Send, then MessagingCenter.Subscribe & load
I'm creating a custom dynamic notification to show the user. Once i receive this notification at didReceiveNotification function at NotificationController I set the interface outlets with the right data. My problem is that i did not realize how can i add a custom button above the default dismiss button, since the notification storyboard doesnt allow buttons insertion and Apple Documentation says that
Do not include buttons, switches, or other interactive controls.
But i saw a lot of watch applications that have their custom actions, as Messages and Facebook Messenger. There is any way to add custom actions to the dynamic interface at watchOS?
You simply cannot add buttons to Dynamic notification interfaces. If you try to do this, you will receive the error
Illegal Configuration: Buttons are not supported in Notification interfaces.
However, you can add system buttons to your notifications other than the Dismiss button. When setting up the categories for the notification center, you can specify custom UNNotificationActions to be added to your notification category.
var categories = Set<UNNotificationCategory>()
let myCategory = UNNotificationCategory(identifier: "MyCategory", actions: [/*your custom actions go here*/], intentIdentifiers: [], options: []) //set up the actions here
categories.insert(myCategory)
center.setNotificationCategories(categories)
Then you can handle the user interactions with these actions (which as displayed as normal buttons on your dynamic notification interface) in your the UNUserNotificationCenterDelegate method, userNotificationCenter(_:didReceive:withCompletionHandler:) like this:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: #escaping () -> Void) {
switch response.actionIdentifier {
case "Ok":
print("Ok action tapped")
case "Dismiss":
print("Dismiss action tapped")
default:
break
}
completionHandler()
}
I am developing an iPad app using Xamarin.Forms.
I would like my settingspage to be modal so it lay over the previous page like a popup.
I have been trying all solutions I could find and most of them seems to recommend me to call this from a button:
await Navigation.PushModalAsync(ModalSettingsPage);
What happens when I use it is that my settingspage comes in from below as a modal page but not as a popup, it covers the entire screen.
This is my current code:
//Setup button (action bar)
ToolbarItems.Add(new ToolbarItem
{
// Text = "Setup",
Icon = "settings1.png",
Order = ToolbarItemOrder.Default,
Command = new Command(() => Navigation.PushModalAsync(new ModalSettingsPage())) //Action to perfome on click , open modal view
});
Also, does anyone now if there is any good way to positions the ToolbarItems? I have two items and would like each one to be positioned at each side, but by default they are both positioned to the right.
With the evolution of Forms (currently 4.5.0), it has now become simple to push a modalpage which is not fullscreen. Use the following in your code-behind of your xaml contentpage:
using Xamarin.Forms;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
namespace YourAppWithAModalPage
{
public class ModalPage : ContentPage
{
public ModalPage()
{
// iOS Solution for a ModalPage (popup) which is not fullscreen
On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.FormSheet);
}
}
}
There is nothing pre-made in Forms to give you a popup like I think you want. Instead, you would have to create this or use a third-party solution. For example, here is a "popup" implementation that might work for you.
Can we override navigation back button pressed in Xamarin.forms?
I have one navigation back button and the one save button in navigation bar.Save button hits the web service and saves in asynchronous way. While saving although i used progressing bar, navigation back button can be pressed and hence the app crashes due to index out of range exception on navigation stack.I tried using OnDisappearing() , did not work. I wanna cancel the PopUpAsync(),if the save is not done completely, but failed to achieve that. Is there any solution for this scenario? Can we override the navigation back button press event using any custom renderer ?
For controlling the back button to do what I want, I used this method in Xamarin:
public override bool OnKeyDown(Keycode HWkeyCode, KeyEvent e)
{
if (HWkeyCode == Keycode.Back)
{
StartActivity(typeof(FrontPageActivity));
return true;
}
return false;
}
I've been looking for a way to show an offline (not pushed from a server) toast notification on WP7 for a while now. Any ideas?
If you're trying to show the notification while your application is running, you can use the ToastPrompt from the coding4fun toolkit: http://coding4fun.codeplex.com/
If you want to show the notification while your app isn't running, you can use the ShellToast class from a background agent: http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.shelltoast(v=vs.92).aspx
Within a background task, simply call this method:
public static void makeToast(string toastText)
{
//Make a new toast with content "text"
ShellToast toast = new ShellToast();
toast.Title = "Toast Title: ";
toast.Content = toastText;
//toast.NavigationUri = new Uri();
toast.Show();
}