2016-04-05 11 views
0

Ich habe eine Xamarin.Forms App, wo ich Push-Benachrichtigungen verwenden möchte. Ich habe einen azurblauen Push-Notification-Hub vom mobilen Dienst verwendet, um die Nachricht zu senden. Ich möchte ein interaktives Banner mit einigen Aktionen "Action1" und "Action2" auf iOS erstellen. Ich kann die Push-Nachricht mit der Schaltfläche "Aktion1" und "Aktion2" empfangen. Aber das Tippen auf diesen Knopf macht nichts. Folgende ist mein Code:Xamarin iOS handleAction nie anrufen

private static void RegisterPushAction() 
{ 
    UIMutableUserNotificationAction acceptAction = new UIMutableUserNotificationAction(); 
    acceptAction.Title = "Action1"; 
    acceptAction.Identifier = "ACCEPT_IDENTIFIER"; 
    acceptAction.ActivationMode = UIUserNotificationActivationMode.Background; 
    acceptAction.Destructive = false; 
    acceptAction.AuthenticationRequired = false; 

    UIMutableUserNotificationAction denyAction = new UIMutableUserNotificationAction(); 
    denyAction.Title = "Action2; 
    denyAction.Identifier = "DENY_IDENTIFIER"; 
    denyAction.ActivationMode = UIUserNotificationActivationMode.Background; 
    denyAction.Destructive = false; 
    denyAction.AuthenticationRequired = false; 

    UIMutableUserNotificationCategory acceptCategory = new UIMutableUserNotificationCategory(); 
    acceptCategory.Identifier = "JOIN_CATEGORY"; 
    acceptCategory.SetActions (new UIUserNotificationAction[]{acceptAction,denyAction}, UIUserNotificationActionContext.Default); 

    NSSet categories = new NSSet (acceptCategory); 
    //iOS 7 
    if (Convert.ToInt16 (UIDevice.CurrentDevice.SystemVersion.Split ('.') [0].ToString()) < 8) { 
     UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound; 
     UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes); 
    } else { 
     UIUserNotificationType types = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound; 
     UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes (types, categories); 
     UIApplication.SharedApplication.RegisterUserNotificationSettings (settings); 
     UIApplication.SharedApplication.RegisterForRemoteNotifications(); 
    } 
} 

Um dies zu handhaben ich folgende Methode haben:

public override void HandleAction (UIApplication application, string actionIdentifier, NSDictionary remoteNotificationInfo, Action completionHandler) 
{ 
    if (actionIdentifier.Equals ("ACCEPT_IDENTIFIER")) { 
     //var alert = notification.AlertBody; 
     //new UIAlertView ("Msg", alert, null, "OK", null).Show(); 
     //NotificationHelper.ReceivePushMessage (alert); 
     ProcessNotification (remoteNotificationInfo, false); 
    } 
    UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; 
    completionHandler(); 
} 

Die obige HandleAction Methode nie aufgerufen wird, und es ruft immer ReceivedRemoteNotification

public override async void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) 
{ 
    ProcessNotification (userInfo, false); 
} 

Ich habe verschiedene Arten of notificatiosn (zB eine einfache Banner-Benachrichtigung und ein Banner mit Aktion)

Irgendwelche Gedanken dazu?

Antwort

0

Ich weiß nicht, ob Sie immer noch das Problem, aber Sie sollten versuchen, die Funktion HandleAction wie folgt zu schreiben:

public override void HandleAction (UIApplication application, String actionIdentifier, NSDictionary remoteNotificationInfo, NSDictionary responseInfo, Action completionHandler) 

Lassen Sie mich wissen, ob es funktioniert!

Verwandte Themen