我们正在使用AWS SNS和APNS从Ruby on Rails服务器向iOS(Swift)发送通知。通知将进入iOS,但大约需要30-40秒,这对于我们的应用来说是不可接受的。我们可以使用AWS控制台发送立即通过的测试通知,因此它看起来不像iOS错误。在日志中,我们可以看到通知命中AWS并返回200响应。因此,延迟似乎在AWS和iOS之间。我们如何使这些通知更快地通过?
notification = {
:aps => {
"mutable-content" => 1,
:category => category,
:sound => "default",
:extra => data
}
}
notification[:aps][:alert] = { :title => title, :body => body } if title
sns_message = {
:APNS_SANDBOX => notification.to_json,
:APNS => notification.to_json
}
config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env]
sns = AWS::SNS::Client.new(
:access_key_id => config['access_key_id' ],
:secret_access_key => config['secret_access_key'],
:region => config['region' ]
)
sns.publish(
:target_arn => self.arn,
:message => sns_message.to_json,
:message_structure => 'json'
)