远程通知类别未发送到客户端设备?

时间:2017-01-29 02:48:56

标签: ios objective-c apple-push-notifications amazon-sns aws-sdk-ruby

我正在使用Amazon SNS为我的iOS应用程序提供远程通知,而我在客户端设备上收到通知类别时遇到问题。

以下是我如何使用SNS从服务器发布通知:

@client = Aws::SNS::Client.new(...)

resp = @client.publish({
    target_arn: endpoint_arn,
    message: {
        default: body,
        APNS: {
            aps: {
                alert: {
                    title: title,
                    body: body
                },
                category: category
            }
        }
    }.to_json,
    subject: title,
    message_structure: "json"
})

在iOS设备上,我在app delegate中收到通知:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    NSDictionary<NSString *, id> * aps = [userInfo objectForKey:@"aps"];
    if (aps) {
        NSString * category = [aps objectForKey:@"category"];
        NSLog(@"Category is: %@", category); // Category is: nil
    } else {
        NSLog(@"APS dictionary nil");
    }
}

问题是该类别总是为零。我已经尝试了aps对象的一些不同结构,但我似乎无法在iOS设备上获得该类别。

1 个答案:

答案 0 :(得分:0)

有点晚,但可以帮助其他人。

尝试以category的相同级别发送aps属性,如下所示:

resp = @client.publish({
    target_arn: endpoint_arn,
    message: {
        default: body,
        APNS: {
            aps: {
                alert: {
                    title: title,
                    body: body
                }
            },
            category: category
        }
    }.to_json,
    subject: title,
    message_structure: "json"
})

获得回复
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    NSString * category = [userInfo objectForKey:@"category"];
    NSLog(@"Category is: %@", category);        
}

查看this answer了解详情。

希望这个帮助;)