【问题标题】:Remote notification category not being sent to client device?远程通知类别未发送到客户端设备?
【发布时间】:2017-01-29 02:48:55
【问题描述】:

我正在使用 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 设备上,我在应用委托中收到通知:

- (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 设备上获取类别。

【问题讨论】:

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


    【解决方案1】:

    有点晚了,但可能会帮助其他人。

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

    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了解更多信息。

    希望对您有所帮助;)

    【讨论】:

      猜你喜欢
      • 2016-05-20
      • 1970-01-01
      • 2017-11-28
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 2020-10-11
      相关资源
      最近更新 更多