未定义的方法'通知'与Sidekiq一起使用APN_Sender时

时间:2015-09-24 19:15:49

标签: ruby-on-rails ruby apple-push-notifications 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

1 个答案:

答案 0 :(得分:0)

此问题已在新版本v2.1.1中解决

参考 https://github.com/arthurnn/apn_sender/issues/92