gpt4 book ai didi

ios - Ruby on Rails,Grocer 无法向多个收件人发送推送通知

转载 作者:可可西里 更新时间:2023-11-01 05:44:09 25 4
gpt4 key购买 nike

  def push_notification(users)

unless self.pushed_to_mobile? || users.empty?

# make sure all required users receive notifications on
# all registered devices.
@device_tokens = users.map { |u| u.device_tokens }.flatten.uniq

@device_tokens.each do |token|

notification = Grocer::Notification.new(
device_token: token.device_token,
alert: { "body" => "#{self.context_type}: #{self.name}", "action-loc-key" => "View" },
badge: 1,
sound: 'chord.aiff'
custom: { "content" => [ self.name, self.context_type, self.context_name, self.context_id, self.content_id ] },
)

feedback.each do |attempt|
# # TODO: if a device fails 3 times it should be removed from the token list.
# # Failing 3 times indicates that the user has turned notifications off or
# # removed the app from the phone. If the user logs in and their token does
# # not exist it will be readded.
puts "Device #{attempt.device_token} failed at #{attempt.timestamp}"
end

pusher.push( notification )

end
end

# update model to prevent notifying again.
self.pushed_to_mobile = true
self.save
end

def pusher
return @pusher if defined?( @pusher )
@pusher = Grocer.pusher(
certificate: Settings.apple_push_notification_options[:certificate],
passphrase: Settings.apple_push_notification_options[:pass],
gateway: Settings.apple_push_notification_options[:host],
retries: 3
)
end

def feedback
return @feedback if defined?( @feedback )
@feedback = Grocer.feedback(
certificate: Settings.apple_push_notification_options[:certificate],
passphrase: Settings.apple_push_notification_options[:pass],
gateway: Settings.apple_push_notification_options[:host],
retries: 3
)
end

如果我删除循环并强制代码发送到单个 token ,代码将运行并在设备上收到推送通知。但是,如果我尝试遍历 users.device_tokens 数组,代码会无误地执行,但设备上永远不会收到通知。

编辑:即使循环只运行一次。

最佳答案

问题与您访问 Grocer::Feedback 套接字的方式有关。尝试将您的 feedback 方法更改为以下内容。

def feedback
@feedback ||= Grocer.feedback(
certificate: Settings.apple_push_notification_options[:certificate],
passphrase: Settings.apple_push_notification_options[:pass],
gateway: Settings.apple_push_notification_options[:host],
retries: 3
)
@feedback.to_a
end

调用 to_a 将强制读取当前反馈套接字上的任何内容。

关于ios - Ruby on Rails,Grocer 无法向多个收件人发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26372805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com