将 APN_Sender 与 Sidekiq 一起使用时未定义的方法 'notify'
Undefined method 'notify' when using APN_Sender with Sidekiq
我在使用 APN_SENDER gem (https://github.com/arthurnn/apn_sender) 发送这些推送通知时遇到了一些麻烦。
调用 "notify_async(ids,opts)" 时出现以下错误:
NoMethodError (undefined method `notify' for :sidekiq:Symbol):
这是代码
def self.send_apple_push_notification(projeto, ids, message)
projeto.configure_apn(projeto)
options = { alert: message, badge: "+1", sound: true, other_information: ''}
ids.each do |id|
APN.notify_async(id, options)
end
end
我选择了 sidekiq 作为我的后端,正如 README 所建议的那样
APN.backend = :sidekiq # use sidekiq backend
这是配置的其余部分。这样做的目的是使项目可以使用多个证书。
def configure_apn(projeto)
path = nil
if projeto.desenvolvimento
path = projeto.apn_development.path
else
path = projeto.apn_production.path
end
unless path.nil?
last_slash = path.rindex("/")
folder = path[0..last_slash]
file = path[last_slash+1..path.length]
APN.root = folder # root to certificates folder
APN.certificate_name = file # certificate filename
if projeto.desenvolvimento
APN.host = projeto.apn_host
APN.password = projeto.apn_password_development
else
APN.password = projeto.apn_password_production
end
APN.pool_size = 1 # number of connections on the pool
APN.pool_timeout = 5 # timeout in seconds for connection pool
APN.logger = Logger.new(File.join(Rails.root, 'log', 'apn_sender.log'))
APN.truncate_alert = true
APN.backend = :sidekiq # use sidekiq backend
end
end
此问题已在新发布版本 v2.1.1 中得到解决
我在使用 APN_SENDER gem (https://github.com/arthurnn/apn_sender) 发送这些推送通知时遇到了一些麻烦。
调用 "notify_async(ids,opts)" 时出现以下错误:
NoMethodError (undefined method `notify' for :sidekiq:Symbol):
这是代码
def self.send_apple_push_notification(projeto, ids, message)
projeto.configure_apn(projeto)
options = { alert: message, badge: "+1", sound: true, other_information: ''}
ids.each do |id|
APN.notify_async(id, options)
end
end
我选择了 sidekiq 作为我的后端,正如 README 所建议的那样
APN.backend = :sidekiq # use sidekiq backend
这是配置的其余部分。这样做的目的是使项目可以使用多个证书。
def configure_apn(projeto)
path = nil
if projeto.desenvolvimento
path = projeto.apn_development.path
else
path = projeto.apn_production.path
end
unless path.nil?
last_slash = path.rindex("/")
folder = path[0..last_slash]
file = path[last_slash+1..path.length]
APN.root = folder # root to certificates folder
APN.certificate_name = file # certificate filename
if projeto.desenvolvimento
APN.host = projeto.apn_host
APN.password = projeto.apn_password_development
else
APN.password = projeto.apn_password_production
end
APN.pool_size = 1 # number of connections on the pool
APN.pool_timeout = 5 # timeout in seconds for connection pool
APN.logger = Logger.new(File.join(Rails.root, 'log', 'apn_sender.log'))
APN.truncate_alert = true
APN.backend = :sidekiq # use sidekiq backend
end
end
此问题已在新发布版本 v2.1.1 中得到解决