iOS Push Actions

DuffmanDuffman CAMember ✭✭

Hi guys,

I am following the Enhanced Notification example on the Xamarin site. I am trying to add custom actions to my push notifications for iOS10 using the new User Notification framework since my notification actions stopped showing after the iOS10 update. It is registering the actions and categories. I have included the category in the payload. I am getting remote push notifications but none of the notification actions are displayed when expanding the notification. DidReceiveRemoteNotification is called when push arrives.

Here is the code:

            //Create accept action
            var acceptID = "ACCEPT_ID";
            var acceptTitle = "Accept";
            var acceptAction = UNNotificationAction.FromIdentifier(acceptID, acceptTitle, UNNotificationActionOptions.None);

            //Create deny action
            var denyID = "DENY_ID";
            var denyTitle = "Deny";
            var denyAction = UNNotificationAction.FromIdentifier(denyID, denyTitle, UNNotificationActionOptions.None);

            //Create category
            var categoryID = "CATEGORY_ID";
            var actions = new UNNotificationAction[] { acceptAction, denyAction };
            var intentIDs = new string[] { };
            var categoryOptions = new UNNotificationCategoryOptions[] { };
            var category = UNNotificationCategory.FromIdentifier(categoryID, actions, intentIDs, UNNotificationCategoryOptions.None);

            //Register category
            var categories = new UNNotificationCategory[] { category };
            UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet<UNNotificationCategory>(categories));

            UIApplication.SharedApplication.RegisterForRemoteNotifications();                      

Any help would be appreciated!

Best Answer

Answers

  • DuffmanDuffman CAMember ✭✭
    edited September 2016

    If i target it for iOS10 it would work. What can i do to support iOS 8 and 9?

  • brianduccabrianducca ARMember ✭✭

    Hey, i'm working with remote push notifications in iOS, and i'm having trouble in request authorization when the app starts, how you manage that? In the old way, or using UNUserNotificationCenter.Current.RequestAuthorization

  • DuffmanDuffman CAMember ✭✭
    edited October 2016

    @brianducca

    I used UNUserNotificationCenter.Current.RequestAuthorization. Make sure to add a version check before using that code if you are supporting older iOS versions otherwise it'll crash on devices not running iOS 10.

  • brianduccabrianducca ARMember ✭✭

    @Duffman can you paste some code to handle the authorization?. By the way, have you used the UserNotificationCenterDelegate ? Do you know which methods you need to override to handle all the notifications scenarios ?

Sign In or Register to comment.