ios - 滑动按钮不会用于远程通知

标签 ios objective-c apple-push-notifications apns-php

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

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

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";

这也是我从服务器获取的推送 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;
}

我做错了吗??请指教。

最佳答案

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

关于ios - 滑动按钮不会用于远程通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34127764/

相关文章:

ios - 结束跟踪时 UISlider 的控制事件

ios - WKWebView+contentInset 使内容大小错误

iOS 内存使用量不断增加

ios - 自定义 UIWebView 的滚动指示器

php - 如何在 PHP 中发送 HTTP/2 POST 请求

ios - Clevertap 推送通知声音问题

ruby-on-rails - 我在哪里/如何在后端存储 iOS 设备 token ?

iphone - 从 NSArray 获取对象的索引?

ios - 如何在swift中更新 anchor 约束

objective-c - 画一个方阵