滑动按钮不适用于远程通知

滑动按钮不适用于远程通知

本文介绍了滑动按钮不适用于远程通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 IOS 8 应用程序中放置自定义按钮,以便在我的聊天应用程序中收到推送通知.

I am trying to put custom buttons in my IOS 8 application for the PUSH Notifications received in my chat app.

下面是我的代码,但推送通知没有显示发货按钮.

Below is my code but the Push notifications are not showing the ship buttons.

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)];
}`

我也把本地化的字符串文件放在下面的代码中.

I have also put in the localised string file following code.

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

这里也是我从服务器获取的推送 APS 详细信息作为 userInfo.

Here is the Push APS details I am getting from server as userInfo as well.

{
    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;
}

我做错了吗??请指教.

Have I done any mistake ?? Please advice.

推荐答案

category 应该在你 aps 对象的第一级,而不是在 警报:

The category should be at the first level of you aps object, not within the 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

这篇关于滑动按钮不适用于远程通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:07