Кнопки смахивания не приходят для удаленных уведомлений

Я пытаюсь поместить пользовательские кнопки в свое приложение IOS 8 для PUSH-уведомлений, полученных в моем приложении чата.

Ниже мой код, но в push-уведомлениях не отображаются кнопки корабля.

if([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{

    //Defining Ap Actions Categories


    UIMutableUserNotificationAction *replyAction =
    [[UIMutableUserNotificationAction alloc] init];

    // Define an ID string to be passed back to your app when you handle the action
    replyAction.identifier = @"REPLY_ACTION";

    // Localized string displayed in the action button
    replyAction.title = NSLocalizedString(@"REPLY", nil);

    // If you need to show UI, choose foreground
    replyAction.activationMode = UIUserNotificationActivationModeForeground;

    // Destructive actions display in red
    replyAction.destructive = NO;

    // Set whether the action requires the user to authenticate
    replyAction.authenticationRequired = YES;


    UIMutableUserNotificationAction *remindLaterAction =
    [[UIMutableUserNotificationAction alloc] init];

    // Define an ID string to be passed back to your app when you handle the action
    remindLaterAction.identifier = @"REMIND_LATER_ACTION";

    // Localized string displayed in the action button
    remindLaterAction.title = NSLocalizedString(@"REMIND", nil);

    // If you need to show UI, choose foreground
    remindLaterAction.activationMode = UIUserNotificationActivationModeForeground;

    // Destructive actions display in red
    remindLaterAction.destructive = NO;

    // Set whether the action requires the user to authenticate
    remindLaterAction.authenticationRequired = YES;

    // First create the category
    UIMutableUserNotificationCategory *singleChatCategory = [[UIMutableUserNotificationCategory alloc] init];

    // Identifier to include in your push payload and local notification
    [singleChatCategory setIdentifier:@"SINGLE_CHAT"];

    // Add the actions to the category and set the action context
    [singleChatCategory setActions:@[replyAction, remindLaterAction]
                        forContext:UIUserNotificationActionContextDefault];

    // Set the actions to present in a minimal context
    [singleChatCategory setActions:@[replyAction]
                        forContext:UIUserNotificationActionContextMinimal];

    NSSet *categories = [NSSet setWithObjects:singleChatCategory,nil];

    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:categories]];

    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)];
}`

Я также поместил в локализованный строковый файл следующий код.

"SINGLECHAT_WITH_PREVIEW"       =   "%@:%@";
"SINGLECHAT_WITHOUT_PREVIEW"    =   "%@ %@ %@";
"REPLY"                         =   "Reply";
"REMIND"                        =   "Remind Me";

Вот данные Push APS, которые я также получаю с сервера как userInfo.

{
    aps =     {
        alert =         {
            category = "SINGLE_CHAT";
            "loc-args" =             (
                "USER DEV12347",
                "TEST NOTIFICATION MESSAGE"
            );
            "loc-key" = "SINGLECHAT_WITHOUT_PREVIEW";
            title = Closrr;
        };
        badge = 1;
        sound = "push_play.aiff";
    };
    from = "+67123456";
    to = "+67890765";
    type = 2;
}

Я сделал какую-либо ошибку ?? Пожалуйста посоветуй.


person Vicky Dhas    schedule 07.12.2015    source источник
comment
intertech.com/Blog/push-notifications-tutorial-for -ios-9 Попробуйте это   -  person Devang Goswami    schedule 07.12.2015


Ответы (1)


category должен быть на первом уровне вашего объекта aps, а не внутри alert:

{
    aps =     {
        category = "SINGLE_CHAT";
        alert =         {
(...)

Ссылка: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1

person jcaron    schedule 07.12.2015
comment
Я попробую сделать это, внося изменения в сервер :) - person Vicky Dhas; 08.12.2015
comment
Спасибо. Вы решили эту проблему, такая маленькая ошибка, упустили из виду :) Спасибо, JCaron. Ценю ваш совет. - person Vicky Dhas; 08.12.2015
comment
Я сделал это, а также закрыл эту проблему, но одна проблема заключается в том, что когда приложение находится в фоновом режиме, я могу делать все, что захочу, чтобы отправить сообщение XMPP, но когда у приложения не хватает памяти, ничего не происходит. Можете ли вы помочь, как добиться отправки сообщения WhatsApp, когда оно даже не активно в памяти или не активировано, чтобы отправить ответ из уведомления. - Вики Дхас только что отредактировала - person Vicky Dhas; 08.12.2015
comment
@VickyDhas, не уверен, что понимаю вашу проблему, но это похоже на другой вопрос, поэтому, пожалуйста, создайте для этого новый вопрос. - person jcaron; 08.12.2015
comment
Пожалуйста, помогите мне - описано в другом сообщении: stackoverflow.com/questions/34152184/ - person Vicky Dhas; 08.12.2015